@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 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();
 }
Exemple #3
0
 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;
 }
Exemple #4
0
    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 rebuildFlatItemsWOG(Protocol p, List<TreeNode> list) {
   ConcurrentHashMap<String, Contact> contacts = p.getContactItems();
   for (Contact contact : contacts.values()) {
     // if (contact.isVisibleInContactList()) {
     list.add(contact);
     // }
   }
   RosterHelper.sort(list, null);
 }
Exemple #9
0
 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);
   }
 }
Exemple #10
0
  public void rebuildFlatItemsWG(Protocol p, List<TreeNode> list) {
    int contactCounter;
    int onlineContactCounter;
    Enumeration<Group> e = p.getGroupItems().elements();
    while (e.hasMoreElements()) {
      Group group = e.nextElement();
      contactCounter = 0;
      onlineContactCounter = 0;
      Group newGroup = copyGroupWithoutContacts(group);
      list.add(newGroup);
      List<Contact> contacts = group.getContacts();
      int contactsSize = contacts.size();
      for (Contact contact : contacts) {
        // if (contact.isVisibleInContactList()) {
        if (newGroup.isExpanded()) {
          list.add(contact);
        }
        contactCounter++;
        // }
        if (contact.isOnline()) ++onlineContactCounter;
      }
      if (0 == contactCounter) {
        list.remove(list.size() - 1);
      }
      group.updateGroupData(contactsSize, onlineContactCounter);
    }

    Group group = p.getNotInListGroup();
    list.add(group);
    List<Contact> contacts = group.getContacts();
    contactCounter = 0;
    onlineContactCounter = 0;
    int contactsSize = contacts.size();
    for (Contact contact : contacts) {
      // if (contact.isVisibleInContactList()) {
      if (group.isExpanded()) {
        list.add(contact);
      }
      contactCounter++;
      // }
      if (contact.isOnline()) ++onlineContactCounter;
    }
    if (0 == contactCounter) {
      list.remove(list.size() - 1);
    }
    group.updateGroupData(contactsSize, onlineContactCounter);
    RosterHelper.sort(list, p.getGroupItems());
  }
Exemple #11
0
 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;
   }
 }
Exemple #12
0
  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);
    }
  }
Exemple #13
0
 @Override
 public void onClick(View v) {
   RosterHelper.getInstance()
       .showProtocolMenu(
           (BaseActivity) v.getContext(), ((ProtocolBranch) v.getTag()).getProtocol());
 }
Exemple #14
0
  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();
  }