コード例 #1
0
 private void applyStyle() {
   conversationsAdapter.notifyDataSetChanged();
 }
コード例 #2
0
  public void updateValues() {
    if (conversationsAdapter == null) { // never initialized
      return;
    }

    conversations.clear(); // always clean, rebuild if authenticated
    conversationsAdapter.notifyDataSetChanged();

    if (layerClient.isAuthenticated()) {

      List<Conversation> convs = layerClient.getConversations();
      if (debug) Log.d(TAG, "updateValues() conv: " + convs.size());
      for (Conversation conv : convs) {
        // no participants means we are removed from conversation (disconnected conversation)
        if (conv.getParticipants().size() == 0) continue;

        // only ourselves in participant list is possible to happen, but there is nothing to do with
        // it
        // behave like conversation is disconnected
        if (conv.getParticipants().size() == 1 && conv.getParticipants().contains(globalUserId))
          continue;

        conversations.add(conv);
      }

      // the bigger .time the highest in the list
      Collections.sort(
          conversations,
          new Comparator<Conversation>() {
            public int compare(Conversation lhs, Conversation rhs) {
              long leftSentAt = 0;
              Message leftLastMessage = lhs.getLastMessage();
              if (leftLastMessage != null && leftLastMessage.getSentAt() != null) {
                leftSentAt = leftLastMessage.getSentAt().getTime();
              }
              long rightSentAt = 0;
              Message rightLastMessage = rhs.getLastMessage();
              if (rightLastMessage != null && rightLastMessage.getSentAt() != null) {
                rightSentAt = rightLastMessage.getSentAt().getTime();
              }
              long result = rightSentAt - leftSentAt;
              if (result == 0L) return 0;
              return result < 0L ? -1 : 1;
            }
          });
      if (conversations.size() > 0
          && findViewById(R.id.no_conversation_description).getVisibility() == View.VISIBLE) {
        findViewById(R.id.no_conversation_description).setVisibility(View.GONE);
        findViewById(R.id.atlas_conversations_view).setVisibility(View.VISIBLE);
      } else if (conversations.size() == 0) {
        TextView noConversationDescription =
            (TextView) findViewById(R.id.no_conversation_description);
        noConversationDescription.setVisibility(VISIBLE);
        if (accountType == 1) {
          noConversationDescription.setText(R.string.no_conversation_description_counselor);
        } else if (accountType == 0) {
          noConversationDescription.setText(R.string.no_conversation_description);
        } else if (accountType == 2) {
          noConversationDescription.setText(R.string.no_reports_description);
        }
      }
    }
  }