Esempio n. 1
0
 private void updateVisibleRows(int mask) {
   if (listView != null) {
     int count = listView.getChildCount();
     for (int a = 0; a < count; a++) {
       View child = listView.getChildAt(a);
       if (child instanceof UserCell) {
         ((UserCell) child).update(mask);
       }
     }
   }
 }
  @Override
  public View getItemView(int section, int position, View convertView, ViewGroup parent) {
    int type = getItemViewType(section, position);
    if (type == 4) {
      if (convertView == null) {
        convertView = new DividerCell(mContext);
        convertView.setPadding(
            AndroidUtilities.dp(LocaleController.isRTL ? 28 : 72),
            0,
            AndroidUtilities.dp(LocaleController.isRTL ? 72 : 28),
            0);
      }
    } else if (type == 3) {
      if (convertView == null) {
        convertView = new GreySectionCell(mContext);
        ((GreySectionCell) convertView)
            .setText(LocaleController.getString("Contacts", R.string.Contacts).toUpperCase());
      }
    } else if (type == 2) {
      if (convertView == null) {
        convertView = new TextCell(mContext);
      }
      TextCell actionCell = (TextCell) convertView;
      if (needPhonebook) {
        actionCell.setTextAndIcon(
            LocaleController.getString("InviteFriends", R.string.InviteFriends),
            R.drawable.menu_invite);
      } else if (isAdmin) {
        actionCell.setTextAndIcon(
            LocaleController.getString("InviteToGroupByLink", R.string.InviteToGroupByLink),
            R.drawable.menu_invite);
      } else {
        if (position == 0) {
          actionCell.setTextAndIcon(
              LocaleController.getString("NewGroup", R.string.NewGroup), R.drawable.menu_newgroup);
        } else if (position == 1) {
          actionCell.setTextAndIcon(
              LocaleController.getString("NewSecretChat", R.string.NewSecretChat),
              R.drawable.menu_secret);
        } else if (position == 2) {
          actionCell.setTextAndIcon(
              LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList),
              R.drawable.menu_broadcast);
        }
      }
    } else if (type == 1) {
      if (convertView == null) {
        convertView = new TextCell(mContext);
      }
      ContactsController.Contact contact =
          ContactsController.getInstance().phoneBookContacts.get(position);
      if (contact.first_name != null && contact.last_name != null) {
        if (isContainUTF8(contact.display_name)) {
          ((TextCell) convertView).setText(contact.display_name);
        } else {
          ((TextCell) convertView).setText(contact.first_name + " " + contact.last_name);
        }
      } else if (contact.first_name != null && contact.last_name == null) {
        ((TextCell) convertView).setText(contact.first_name);
      } else {
        ((TextCell) convertView).setText(contact.last_name);
      }
    } else if (type == 0) {
      if (convertView == null) {
        convertView = new UserCell(mContext, 58);
        ((UserCell) convertView).setStatusColors(0xffa8a8a8, 0xff3b84c0);
      }

      ArrayList<TLRPC.TL_contact> arr =
          ContactsController.getInstance()
              .usersSectionsDict
              .get(
                  ContactsController.getInstance()
                      .sortedUsersSectionsArray
                      .get(section - (onlyUsers && !isAdmin ? 0 : 1)));
      TLRPC.User user = MessagesController.getInstance().getUser(arr.get(position).user_id);
      if (isContainUTF8(user.first_name) || isContainUTF8(user.last_name)) {
        ((UserCell) convertView).setData(user, user.last_name + user.first_name, null, 0);
      } else {
        ((UserCell) convertView).setData(user, null, null, 0);
      }

      if (checkedMap != null) {
        ((UserCell) convertView)
            .setChecked(checkedMap.containsKey(user.id), !scrolling && Build.VERSION.SDK_INT > 10);
      }
      if (ignoreUsers != null) {
        if (ignoreUsers.containsKey(user.id)) {
          ViewProxy.setAlpha(convertView, 0.5f);
        } else {
          ViewProxy.setAlpha(convertView, 1.0f);
        }
      }
    }
    return convertView;
  }