@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(); } } }
public static List<Contact> getActiveContacts() { List<Contact> list = new ArrayList<>(); Cursor cursor = null; try { cursor = SawimApplication.getDatabaseHelper() .getReadableDatabase() .query( DatabaseHelper.TABLE_CHAT_HISTORY, null, null, null, DatabaseHelper.CONTACT_ID, null, null, null); if (cursor.moveToLast()) { do { String protocolId = cursor.getString(cursor.getColumnIndex(DatabaseHelper.ACCOUNT_ID)); String uniqueUserId = cursor.getString(cursor.getColumnIndex(DatabaseHelper.CONTACT_ID)); Protocol protocol = RosterHelper.getInstance().getProtocol(protocolId); if (protocol != null) { list.add(protocol.getItemByUID(uniqueUserId)); } } while (cursor.moveToPrevious()); } } finally { if (cursor != null) { cursor.close(); } } return list; }
void populateFrom(final int position) { final Profile account = getItem(position); Protocol p = RosterHelper.getInstance().getProtocol(account); if (null != p) { ImageView icProtocol = getImageProtocol(); Icon ic = p.getStatusInfo().getIcon((byte) 0); if (ic != null) { icProtocol.setVisibility(ImageView.VISIBLE); icProtocol.setImageDrawable(ic.getImage()); } else { icProtocol.setVisibility(ImageView.GONE); } } getTextLogin().setText(account.userId); ToggleButton tb = getToggleButton(); tb.setChecked(account.isActive); tb.setFocusableInTouchMode(false); tb.setFocusable(false); tb.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { ToggleButton t = (ToggleButton) v.findViewById(R.id.toggle_button); account.isActive = t.isChecked(); RosterHelper.getInstance().setCurrentProtocol(); Options.saveAccount(account); notifyDataSetChanged(); } }); }
public boolean filterData(String query) { items.clear(); boolean isFound = false; if (query == null || query.isEmpty()) { originalContactList.clear(); refreshList(); } else { query = query.toLowerCase(); if (originalContactList.isEmpty()) { Protocol p = RosterHelper.getInstance().getProtocol(); for (Contact contact : p.getContactItems().values()) { originalContactList.add(contact); } } for (Contact contact : originalContactList) { boolean isSearch = contact.getText().toLowerCase().contains(query); if (isSearch) { items.add(contact); } } isFound = !items.isEmpty(); notifyDataSetChanged(); } return isFound; }
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; }
private void buildRoster(Protocol p) { if (p == null) return; if (RosterHelper.getInstance().useGroups) { rebuildFlatItemsWG(p, items); } else { rebuildFlatItemsWOG(p, items); } }
public void removeHistory() { try { Contact contact = RosterHelper.getInstance().getProtocol(protocolId).getItemByUID(uniqueUserId); contact.firstServerMsgId = ""; // RosterStorage.updateFirstServerMsgId(contact); RosterHelper.getInstance() .getProtocol(protocolId) .getStorage() .updateUnreadMessagesCount(protocolId, uniqueUserId, 0); SawimApplication.getDatabaseHelper() .getWritableDatabase() .delete( DatabaseHelper.TABLE_CHAT_HISTORY, WHERE_ACC_CONTACT_ID, new String[] {protocolId, uniqueUserId}); } catch (Exception e) { DebugLog.panic(e); } }
public void refreshList() { RosterHelper roster = RosterHelper.getInstance(); items.clear(); if (type == RosterHelper.ACTIVE_CONTACTS) { Protocol p = roster.getProtocol(); ChatHistory.instance.addLayerToListOfChats(p, items); ChatHistory.instance.sort(); } else { buildRoster(roster.getProtocol()); } notifyDataSetChanged(); }
public static Drawable getImageChat(Chat chat, boolean showMess) { if (chat.getContact().isTyping()) { return Message.getIcon(Message.ICON_TYPE); } else { Icon icStatus = RosterHelper.getInstance() .getProtocol() .getStatusInfo() .getIcon(chat.getContact().getStatusIndex()); Drawable icMess = Message.getIcon(chat.getNewMessageIcon()); 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); } } return icMess == null || !showMess ? icStatus.getImage() : icMess; } }
public SmsForm(Protocol protocol, String phones) { this.phones = phones; Protocol[] protos; if (null == protocol) { protos = RosterHelper.getInstance().getProtocols(); } else { protos = new Protocol[] {protocol}; } protocols = new Vector(); agents = ""; for (int i = 0; i < protos.length; ++i) { if ((protos[i] instanceof Mrim) && protos[i].isConnected()) { agents += "|" + protos[i].getUserId(); protocols.addElement(protos[i]); } } if (agents.startsWith("|")) { agents = agents.substring(1); } }
@Override public void onClick(View v) { RosterHelper.getInstance() .showProtocolMenu( (BaseActivity) v.getContext(), ((ProtocolBranch) v.getTag()).getProtocol()); }