Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 @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();
     }
   }
 }
Exemplo n.º 3
0
 private void sendHelloMessage(Protocol protocol, Contact contact) {
   validUins.addElement(contact.getUserId());
   uncheckedUins.removeElement(contact.getUserId());
   if (protocol.isMeVisible(contact)) {
     protocol.sendMessage(
         contact, Options.getString(JLocale.getString(R.string.pref_antispam_hello)), false);
   }
 }
Exemplo n.º 4
0
 private void sendQuestion(Protocol protocol, Contact contact) {
   if (uncheckedUins.contains(contact.getUserId())) {
     uncheckedUins.removeElement(contact.getUserId());
     return;
   }
   String message = Options.getString(JLocale.getString(R.string.pref_antispam_msg));
   if (protocol.isMeVisible(contact) && !StringConvertor.isEmpty(message)) {
     protocol.sendMessage(contact, "I don't like spam!\n" + message, false);
     uncheckedUins.addElement(contact.getUserId());
   }
 }
Exemplo n.º 5
0
 public synchronized boolean hasLastMessage(Chat chat, Message message) {
   Contact contact = chat.getContact();
   boolean hasMessage = false;
   Cursor cursor = null;
   try {
     cursor =
         SawimApplication.getDatabaseHelper()
             .getReadableDatabase()
             .query(
                 DatabaseHelper.TABLE_CHAT_HISTORY,
                 null,
                 DatabaseHelper.CONTACT_ID + " = ?",
                 new String[] {uniqueUserId},
                 null,
                 null,
                 DatabaseHelper.DATE + " DESC",
                 String.valueOf(60));
     if (cursor.moveToLast()) {
       do {
         short rowData = cursor.getShort(cursor.getColumnIndex(DatabaseHelper.ROW_DATA));
         MessData mess =
             Chat.buildMessage(
                 contact,
                 message,
                 contact.isConference() ? message.getName() : chat.getFrom(message),
                 false,
                 Chat.isHighlight(message.getProcessedText(), contact.getMyName()));
         MessData messFromDataBase = buildMessage(chat, cursor);
         boolean isMessage =
             (rowData & MessData.PRESENCE) == 0
                 && (rowData & MessData.SERVICE) == 0
                 && (rowData & MessData.PROGRESS) == 0;
         if (isMessage) {
           hasMessage = hasMessage(mess, messFromDataBase);
           if (hasMessage) {
             return true;
           }
         }
       } while (cursor.moveToPrevious());
     }
   } catch (Exception e) {
     DebugLog.panic(e);
   } finally {
     if (cursor != null) {
       cursor.close();
     }
   }
   return hasMessage;
 }
Exemplo n.º 6
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());
  }
Exemplo n.º 7
0
 public void addMessageToHistory(
     Contact contact, Message message, String from, boolean isSystemNotice) {
   addText(
       Chat.buildMessage(
           contact,
           message,
           from,
           isSystemNotice,
           Chat.isHighlight(message.getProcessedText(), contact.getMyName())));
 }
Exemplo n.º 8
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);
   }
 }
Exemplo n.º 9
0
 private static MessData buildMessage(Chat chat, Cursor cursor) {
   Contact contact = chat.getContact();
   int sendingState = cursor.getInt(cursor.getColumnIndex(DatabaseHelper.SENDING_STATE));
   boolean isIncoming = cursor.getInt(cursor.getColumnIndex(DatabaseHelper.INCOMING)) == 0;
   String from = cursor.getString(cursor.getColumnIndex(DatabaseHelper.AUTHOR));
   String text = cursor.getString(cursor.getColumnIndex(DatabaseHelper.MESSAGE));
   long date = cursor.getLong(cursor.getColumnIndex(DatabaseHelper.DATE));
   short rowData = cursor.getShort(cursor.getColumnIndex(DatabaseHelper.ROW_DATA));
   // String serverMsgId = cursor.getString(cursor.getColumnIndex(DatabaseHelper.SERVER_MSG_ID));
   PlainMessage message;
   if (isIncoming) {
     message = new PlainMessage(from, chat.getProtocol(), date, text, true);
   } else {
     message = new PlainMessage(chat.getProtocol(), contact.getUserId(), date, text);
   }
   // message.setServerMsgId(serverMsgId);
   MessData messData;
   if (rowData == 0) {
     messData =
         Chat.buildMessage(
             contact,
             message,
             contact.isConference() ? from : chat.getFrom(message),
             false,
             isIncoming
                 ? Chat.isHighlight(message.getProcessedText(), contact.getMyName())
                 : false);
   } else if ((rowData & MessData.ME) != 0 || (rowData & MessData.PRESENCE) != 0) {
     messData = new MessData(contact, message.getNewDate(), text, from, rowData);
   } else {
     messData =
         Chat.buildMessage(
             contact,
             message,
             contact.isConference() ? from : chat.getFrom(message),
             rowData,
             Chat.isHighlight(message.getProcessedText(), contact.getMyName()));
   }
   if (!message.isIncoming() && !messData.isMe()) {
     messData.setIconIndex((byte) sendingState);
   }
   return messData;
 }
Exemplo n.º 10
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();
  }
Exemplo n.º 11
0
 public final void setOfflineStatus() {
   subContacts.removeAllElements();
   super.setOfflineStatus();
 }