Ejemplo n.º 1
0
 /**
  * 鍦ㄤ細璇濆垪琛ㄤ腑鎺ユ敹娑堟伅
  *
  * @param event
  */
 public void onEventMainThread(MessageEvent event) {
   Log.i(TAG, "onEventMainThread MessageEvent execute");
   Message msg = event.getMessage();
   String targetID = msg.getTargetID();
   ConversationType convType = msg.getTargetType();
   Conversation conv;
   if (convType == ConversationType.group) {
     conv = JMessageClient.getGroupConversation(Integer.parseInt(targetID));
   } else {
     conv = JMessageClient.getSingleConversation(targetID);
   }
   if (conv != null && convType == ConversationType.single) {
     // 濡傛灉缂撳瓨浜嗗ご鍍忥紝鐩存帴鍒锋柊浼氳瘽鍒楄〃
     if (NativeImageLoader.getInstance().getBitmapFromMemCache(targetID) != null) {
       Log.i("Test", "conversation ");
       mConvListController.refreshConvList();
       // 娌℃湁澶村儚锛屼粠Conversation鎷�
     } else {
       File file = conv.getAvatarFile();
       // 鎷垮埌鍚庣紦瀛樺苟鍒锋柊
       if (file != null) {
         mConvListController.loadAvatarAndRefresh(targetID, file.getAbsolutePath());
         // conversation涓病鏈夊ご鍍忥紝鐩存帴鍒锋柊锛孲DK浼氬湪鍚庡彴鑾峰緱澶村儚锛屾嬁鍒板悗浼氭墽琛宱nEvent(ConversationRefreshEvent
         // conversationRefreshEvent)
       } else mConvListController.refreshConvList();
     }
   } else {
     mConvListController.refreshConvList();
   }
 }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ItemViewTag viewTag;
    Bitmap bitmap;
    if (convertView == null) {
      convertView = mInflater.inflate(R.layout.group_grid_view_item, null);
      viewTag =
          new ItemViewTag(
              (CircleImageView) convertView.findViewById(R.id.grid_avatar),
              (TextView) convertView.findViewById(R.id.grid_name),
              (ImageView) convertView.findViewById(R.id.grid_delete_icon));
      convertView.setTag(viewTag);
    } else {
      viewTag = (ItemViewTag) convertView.getTag();
    }

    if (position < mCurrentNum) {
      UserInfo userInfo = mMemberList.get(position);
      viewTag = (ItemViewTag) convertView.getTag();
      viewTag.icon.setVisibility(View.VISIBLE);
      viewTag.name.setVisibility(View.VISIBLE);
      bitmap = NativeImageLoader.getInstance().getBitmapFromMemCache(userInfo.getUserName());
      if (bitmap != null) viewTag.icon.setImageBitmap(bitmap);
      else {
        // 如果mediaID为空,表明用户没有设置过头像,用默认头像
        if (TextUtils.isEmpty(userInfo.getAvatar())) {
          viewTag.icon.setImageResource(R.drawable.head_icon);
        } else {
          File file = userInfo.getAvatarFile();
          // 如果本地存在头像
          if (file != null && file.isFile()) {
            bitmap =
                BitmapLoader.getBitmapFromFile(file.getAbsolutePath(), mDefaultSize, mDefaultSize);
            NativeImageLoader.getInstance().updateBitmapFromCache(userInfo.getUserName(), bitmap);
            viewTag.icon.setImageBitmap(bitmap);
            // 从网上拿头像
          } else {
            viewTag.icon.setImageResource(R.drawable.head_icon);
            final String userName = userInfo.getUserName();
            userInfo.getAvatarFileAsync(
                new DownloadAvatarCallback() {
                  @Override
                  public void gotResult(int status, String desc, File file) {
                    if (status == 0) {
                      Bitmap bitmap =
                          BitmapLoader.getBitmapFromFile(
                              file.getAbsolutePath(), mDefaultSize, mDefaultSize);
                      NativeImageLoader.getInstance().updateBitmapFromCache(userName, bitmap);
                      notifyDataSetChanged();
                    }
                  }
                });
          }
        }
      }

      if (TextUtils.isEmpty(userInfo.getNickname())) {
        viewTag.name.setText(userInfo.getUserName());
      } else {
        viewTag.name.setText(userInfo.getNickname());
      }
    }
    // 是Delete状态
    if (mIsShowDelete) {
      if (position < mCurrentNum) {
        UserInfo userInfo = mMemberList.get(position);
        // 群主不能删除自己
        if (userInfo.getUserName().equals(JMessageClient.getMyInfo().getUserName()))
          viewTag.deleteIcon.setVisibility(View.GONE);
        else viewTag.deleteIcon.setVisibility(View.VISIBLE);

      } else {
        viewTag.deleteIcon.setVisibility(View.INVISIBLE);
        viewTag.icon.setVisibility(View.INVISIBLE);
        viewTag.name.setVisibility(View.INVISIBLE);
      }
      // 非Delete状态
    } else {
      viewTag.deleteIcon.setVisibility(View.INVISIBLE);
      if (position < mCurrentNum) {
        viewTag.icon.setVisibility(View.VISIBLE);
        viewTag.name.setVisibility(View.VISIBLE);
      } else if (position == mCurrentNum) {
        viewTag = (ItemViewTag) convertView.getTag();
        viewTag.icon.setImageResource(R.drawable.chat_detail_add);
        viewTag.icon.setVisibility(View.VISIBLE);
        viewTag.name.setVisibility(View.INVISIBLE);

        // 设置删除群成员按钮
      } else if (position == mCurrentNum + 1) {
        if (mIsCreator && mCurrentNum > 1) {
          viewTag = (ItemViewTag) convertView.getTag();
          viewTag.icon.setImageResource(R.drawable.chat_detail_del);
          viewTag.icon.setVisibility(View.VISIBLE);
          viewTag.name.setVisibility(View.INVISIBLE);
        } else {
          viewTag = (ItemViewTag) convertView.getTag();
          viewTag.icon.setVisibility(View.GONE);
          viewTag.name.setVisibility(View.GONE);
        }
        // 空白项
      } else {
        viewTag = (ItemViewTag) convertView.getTag();
        viewTag.icon.setVisibility(View.INVISIBLE);
        viewTag.name.setVisibility(View.INVISIBLE);
      }
    }

    return convertView;
  }