Search in sources :

Example 1 with ThreadHolder

use of com.abewy.android.apps.klyph.adapter.holder.ThreadHolder in project Klyph by jonathangerbaud.

the class ThreadAdapter method attachViewHolder.

@Override
protected void attachViewHolder(View view) {
    ImageView authorPicture = (ImageView) view.findViewById(R.id.avatar);
    TextView authorName = (TextView) view.findViewById(R.id.conversation_name);
    TextView date = (TextView) view.findViewById(R.id.conversation_date);
    TextView message = (TextView) view.findViewById(R.id.message_snippet);
    TextView unreadCount = (TextView) view.findViewById(R.id.unread_count);
    setHolder(view, new ThreadHolder(authorPicture, authorName, date, message, unreadCount));
}
Also used : ThreadHolder(com.abewy.android.apps.klyph.adapter.holder.ThreadHolder) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 2 with ThreadHolder

use of com.abewy.android.apps.klyph.adapter.holder.ThreadHolder in project Klyph by jonathangerbaud.

the class ThreadAdapter method bindData.

@Override
public void bindData(View view, GraphObject data) {
    ThreadHolder holder = (ThreadHolder) getHolder(view);
    MessageThread thread = (MessageThread) data;
    List<Friend> friends = new ArrayList<Friend>();
    friends.addAll(thread.getRecipients_friends());
    String pic = null;
    if (friends.size() > 0) {
        for (int i = 0; i < friends.size(); i++) {
            Friend friend = friends.get(i);
            if (friend.getUid().equals(KlyphSession.getSessionUserId())) {
                friends.remove(friend);
                i--;
            } else {
                if (pic == null) {
                    pic = friend.getPic();
                }
            }
        }
    }
    if (pic == null) {
        pic = "";
    }
    Resources res = getContext(view).getResources();
    holder.getAuthorName().setText("");
    int n = friends.size();
    Friend friend = null;
    if (n > 0) {
        friend = friends.get(0);
    } else {
        n = 1;
        friend = thread.getRecipients_friends().get(0);
        pic = friend.getPic();
    }
    String friendName = friend.getFirst_name().length() > 0 ? friend.getFirst_name() : friend.getName();
    if (n == 1) {
        holder.getAuthorName().setText(String.format(res.getString(R.string.thread_one_user), friend.getName()));
    } else if (n > 1) {
        Friend friend2 = friends.get(1);
        String friendName2 = friend2.getFirst_name().length() > 0 ? friend2.getFirst_name() : friend2.getName();
        if (n == 2) {
            holder.getAuthorName().setText(String.format(res.getString(R.string.thread_two_users), friendName, friendName2));
        } else if (n > 2) {
            holder.getAuthorName().setText(String.format(res.getString(R.string.thread_many_users), friendName, friendName2, n - 2));
        }
    }
    String message = "";
    if (thread.getSnippet_author().equals(KlyphSession.getSessionUserId())) {
        message = view.getContext().getString(R.string.my_last_message, thread.getSnippet());
    } else if (thread.isMultiUserConversation()) {
        for (Friend friend2 : thread.getRecipients_friends()) {
            if (friend2.getUid().equals(thread.getSnippet_author())) {
                message = view.getContext().getString(R.string.friend_last_message, friend2.getFirst_name(), thread.getSnippet());
                break;
            }
        }
    } else {
        message = thread.getSnippet();
    }
    holder.getMessageTextView().setText(message);
    EmojiUtil.convertTextToEmoji(holder.getMessageTextView(), false);
    holder.getDateTextView().setText(DateUtil.getShortDate(thread.getUpdated_time()));
    int unreadCount = thread.getUnread();
    if (unreadCount > 0) {
        if (unreadCount <= 99)
            holder.getUnreadCountTextView().setText(thread.getUnread() + "");
        else
            holder.getUnreadCountTextView().setText("99+");
        holder.getUnreadCountTextView().setVisibility(View.VISIBLE);
        holder.getAuthorName().setTypeface(null, Typeface.BOLD);
        holder.getMessageTextView().setTypeface(null, Typeface.BOLD);
        holder.getDateTextView().setTypeface(null, Typeface.BOLD);
    } else {
        holder.getUnreadCountTextView().setVisibility(View.GONE);
        holder.getAuthorName().setTypeface(null, Typeface.NORMAL);
        holder.getMessageTextView().setTypeface(null, Typeface.NORMAL);
        holder.getDateTextView().setTypeface(null, Typeface.NORMAL);
    }
    ImageLoader.display(holder.getAuthorPicture(), pic, KlyphUtil.getPlaceHolder(holder.getAuthorName().getContext()));
}
Also used : Friend(com.abewy.android.apps.klyph.core.fql.Friend) ThreadHolder(com.abewy.android.apps.klyph.adapter.holder.ThreadHolder) ArrayList(java.util.ArrayList) MessageThread(com.abewy.android.apps.klyph.core.fql.MessageThread) Resources(android.content.res.Resources)

Aggregations

ThreadHolder (com.abewy.android.apps.klyph.adapter.holder.ThreadHolder)2 Resources (android.content.res.Resources)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Friend (com.abewy.android.apps.klyph.core.fql.Friend)1 MessageThread (com.abewy.android.apps.klyph.core.fql.MessageThread)1 ArrayList (java.util.ArrayList)1