void populateFromGroup(RosterItemView rosterItemView, Group g) { Group group = g; g = RosterHelper.getInstance().getGroupWithContacts(g); if (g == null) g = group; rosterItemView.itemNameColor = Scheme.getColor(R.attr.group); rosterItemView.itemNameFont = Typeface.DEFAULT; rosterItemView.itemName = g.getText(); rosterItemView.itemFirstImage = new Icon(g.isExpanded() ? SawimResources.groupDownIcon : SawimResources.groupRightIcons) .getImage() .getBitmap(); Drawable messIcon = ChatHistory.instance.getUnreadMessageIcon(g.getContacts()); if (messIcon != null) { if (messIcon == SawimResources.PERSONAL_MESSAGE_ICON) { messIcon = messIcon.getConstantState().newDrawable(); messIcon.setColorFilter( Scheme.getColor(R.attr.personal_unread_message), PorterDuff.Mode.MULTIPLY); } else { messIcon = messIcon.getConstantState().newDrawable(); messIcon.setColorFilter(Scheme.getColor(R.attr.unread_message), PorterDuff.Mode.MULTIPLY); } } if (!g.isExpanded() && messIcon != null) rosterItemView.itemFifthImage = messIcon; }
@Override public ViewHolder onCreateViewHolder(ViewGroup parent, int itemViewType) { View convertView = null; Context context = parent.getContext(); if (type == RosterHelper.ACTIVE_CONTACTS) { convertView = new RosterItemView(SawimApplication.getInstance().getBaseContext()); } if (itemViewType == ITEM_PROTOCOL) { convertView = new LinearLayout(context); RosterItemView rosterItemView = new RosterItemView(context); MyImageButton imageButton = new MyImageButton(context); ProgressBar progressBar = new ProgressBar(context, null, android.R.attr.progressBarStyleInverse); LinearLayout.LayoutParams progressLinearLayout = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); progressLinearLayout.gravity = Gravity.RIGHT; progressBar.setLayoutParams(progressLinearLayout); progressBar.setMax(100); LinearLayout.LayoutParams buttonLinearLayout = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); buttonLinearLayout.gravity = Gravity.RIGHT; imageButton.setLayoutParams(buttonLinearLayout); LinearLayout.LayoutParams rosterLinearLayout = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); rosterLinearLayout.gravity = Gravity.LEFT; rosterLinearLayout.weight = 1; convertView.setBackgroundColor(Scheme.getColor(R.attr.item_selected)); rosterItemView.setLayoutParams(rosterLinearLayout); imageButton.setImageDrawable(SawimResources.MENU_ICON); ((ViewGroup) convertView).setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); ((ViewGroup) convertView).addView(rosterItemView); ((ViewGroup) convertView).addView(progressBar); ((ViewGroup) convertView).addView(imageButton); } if (itemViewType == ITEM_GROUP) { convertView = new RosterItemView(SawimApplication.getInstance().getBaseContext()); } if (itemViewType == ITEM_CONTACT) { convertView = new RosterItemView(SawimApplication.getInstance().getBaseContext()); } return new ViewHolder(convertView); }
void populateFromProtocol(RosterItemView rosterItemView, ProtocolBranch o) { rosterItemView.itemNameColor = Scheme.getColor(R.attr.group); rosterItemView.itemNameFont = Typeface.DEFAULT; rosterItemView.itemName = o.getText(); rosterItemView.itemSecondImage = new Icon(o.isExpanded() ? SawimResources.groupDownIcon : SawimResources.groupRightIcons) .getImage(); Icon icGroup = o.getProtocol().getCurrentStatusIcon(); if (icGroup != null) rosterItemView.itemThirdImage = icGroup.getImage().getBitmap(); Profile profile = o.getProtocol().getProfile(); if (profile != null) { if (profile.xstatusIndex != XStatusInfo.XSTATUS_NONE) { XStatusInfo xStatusInfo = o.getProtocol().getXStatusInfo(); if (xStatusInfo != null) { Icon xStatusIcon = xStatusInfo.getIcon(profile.xstatusIndex); if (xStatusIcon != null) rosterItemView.itemFourthImage = xStatusIcon.getImage().getBitmap(); } } } Drawable messIcon = ChatHistory.instance.getUnreadMessageIcon(); if (messIcon != null) { if (messIcon == SawimResources.PERSONAL_MESSAGE_ICON) { messIcon = messIcon.getConstantState().newDrawable(); messIcon.setColorFilter( Scheme.getColor(R.attr.personal_unread_message), PorterDuff.Mode.MULTIPLY); } else { messIcon = messIcon.getConstantState().newDrawable(); messIcon.setColorFilter(Scheme.getColor(R.attr.unread_message), PorterDuff.Mode.MULTIPLY); } } if (!o.isExpanded() && messIcon != null) rosterItemView.itemFifthImage = messIcon; }
void setShowDivider(RosterItemView rosterItemView, boolean value) { rosterItemView.isShowDivider = value; }
void populateFromContact( final RosterItemView rosterItemView, RosterHelper roster, Protocol p, Contact item) { if (p == null || item == null) return; rosterItemView.itemNameColor = Scheme.getColor(item.getTextTheme()); rosterItemView.itemNameFont = item.hasChat() ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT; rosterItemView.itemName = (item.subcontactsS() == 0) ? item.getText() : item.getText() + " (" + item.subcontactsS() + ")"; String statusMessage = roster.getStatusMessage(p, item); rosterItemView.itemDescColor = Scheme.getColor(R.attr.contact_status); rosterItemView.itemDesc = statusMessage; if (Options.getBoolean(JLocale.getString(R.string.pref_users_avatars))) { AvatarCache.getInstance() .load( item.getUserId(), item.avatarHash, item.getText(), new AvatarCache.OnImageLoadListener() { @Override public void onLoad(Bitmap avatar) { rosterItemView.itemFirstImage = avatar; rosterItemView.repaint(); } }); rosterItemView.avatarBorderColor = Contact.getStatusColor(item.getStatusIndex()); } // Icon icStatus = item.getLeftIcon(p); // if (icStatus != null) // rosterItemView.itemSecondImage = icStatus.getImage().getBitmap(); if (item.isTyping()) { rosterItemView.itemSecondImage = Message.getIcon(Message.ICON_TYPE); } else { Drawable icMess = ChatHistory.instance.getUnreadMessageIcon(item); if (icMess != null) { if (icMess == SawimResources.PERSONAL_MESSAGE_ICON) { icMess = icMess.getConstantState().newDrawable(); icMess.setColorFilter( Scheme.getColor(R.attr.personal_unread_message), PorterDuff.Mode.MULTIPLY); } else { icMess = icMess.getConstantState().newDrawable(); icMess.setColorFilter(Scheme.getColor(R.attr.unread_message), PorterDuff.Mode.MULTIPLY); } rosterItemView.itemSecondImage = icMess; } } if (item.getXStatusIndex() != XStatusInfo.XSTATUS_NONE) { XStatusInfo xStatusInfo = p.getXStatusInfo(); if (xStatusInfo != null) rosterItemView.itemThirdImage = xStatusInfo.getIcon(item.getXStatusIndex()).getImage().getBitmap(); } if (!item.isTemp()) { if (item.isAuth()) { int privacyList = -1; if (item.inIgnoreList()) { privacyList = 0; } else if (item.inInvisibleList()) { privacyList = 1; } else if (item.inVisibleList()) { privacyList = 2; } if (privacyList != -1) rosterItemView.itemThirdImage = Contact.serverListsIcons.iconAt(privacyList).getImage().getBitmap(); } else { rosterItemView.itemFourthImage = SawimResources.AUTH_ICON.getBitmap(); } } Icon icClient = (null != p.clientInfo) ? p.clientInfo.getIcon(item.clientIndex) : null; if (icClient != null && !SawimApplication.hideIconsClient) rosterItemView.itemSixthImage = icClient.getImage().getBitmap(); }
@Override public void onBindViewHolder(ViewHolder holder, int position) { final TreeNode item = getItem(position); int itemViewType = getItemViewType(position); View convertView = holder.itemView; convertView.setTag(position); if (type == RosterHelper.ACTIVE_CONTACTS) { RosterItemView rosterItemView = (RosterItemView) holder.itemView; rosterItemView.setNull(); if (item != null) { if (itemViewType == ITEM_LAYER) { rosterItemView.addLayer(item.getText()); } if (itemViewType == ITEM_CONTACT) { Contact contact = (Contact) item; populateFromContact( rosterItemView, RosterHelper.getInstance(), contact.getProtocol(), contact); } setShowDivider(rosterItemView, getItemViewType(position + 1) == ITEM_CONTACT); } rosterItemView.repaint(); } else { if (itemViewType == ITEM_PROTOCOL) { RosterItemView rosterItemView = (RosterItemView) ((ViewGroup) convertView).getChildAt(0); ProgressBar progressBar = (ProgressBar) ((ViewGroup) convertView).getChildAt(1); MyImageButton imageButton = (MyImageButton) ((ViewGroup) convertView).getChildAt(2); rosterItemView.setNull(); if (item != null) { progressBar.setVisibility( ((ProtocolBranch) item).getProtocol().getConnectingProgress() != 100 ? View.VISIBLE : View.GONE); imageButton.setTag(item); imageButton.setOnClickListener(this); populateFromProtocol(rosterItemView, (ProtocolBranch) item); setShowDivider(rosterItemView, true); } rosterItemView.repaint(); } else if (itemViewType == ITEM_GROUP) { RosterItemView rosterItemView = (RosterItemView) convertView; rosterItemView.setNull(); if (item != null) { populateFromGroup(rosterItemView, (Group) item); setShowDivider(rosterItemView, true); } rosterItemView.repaint(); } else if (itemViewType == ITEM_CONTACT) { RosterItemView rosterItemView = (RosterItemView) convertView; rosterItemView.setNull(); if (item != null) { Contact contact = (Contact) item; populateFromContact( rosterItemView, RosterHelper.getInstance(), contact.getProtocol(), contact); setShowDivider(rosterItemView, true); } rosterItemView.repaint(); } } }