diff options
author | Christian Schneppe <christian@pix-art.de> | 2016-05-13 19:10:42 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-05-13 21:59:43 +0200 |
commit | d93fb68c178783501477b69c2fb2ebada34dac56 (patch) | |
tree | 4a6ccf6cf1b0945d15d5d8ecf4ad992cef2d42d2 /src/main/java/eu/siacs/conversations/ui/adapter | |
parent | ddce327009e8838bfa093338fdf2ff0adba7f917 (diff) |
add "is typing..." to Overview
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui/adapter')
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java | 259 |
1 files changed, 134 insertions, 125 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java index 34c9d7b32..7251ef56b 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java @@ -3,10 +3,12 @@ package eu.siacs.conversations.ui.adapter; import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; +import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.AsyncTask; +import android.support.v4.content.ContextCompat; import android.util.Pair; import android.view.LayoutInflater; import android.view.View; @@ -26,6 +28,7 @@ import eu.siacs.conversations.entities.Transferable; import eu.siacs.conversations.ui.ConversationActivity; import eu.siacs.conversations.ui.XmppActivity; import eu.siacs.conversations.utils.UIHelper; +import eu.siacs.conversations.xmpp.chatstate.ChatState; public class ConversationAdapter extends ArrayAdapter<Conversation> { @@ -37,108 +40,114 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> { this.activity = activity; } + public static boolean cancelPotentialWork(Conversation conversation, ImageView imageView) { + final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView); + + if (bitmapWorkerTask != null) { + final Conversation oldConversation = bitmapWorkerTask.conversation; + if (oldConversation == null || conversation != oldConversation) { + bitmapWorkerTask.cancel(true); + } else { + return false; + } + } + return true; + } + + private static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) { + if (imageView != null) { + final Drawable drawable = imageView.getDrawable(); + if (drawable instanceof AsyncDrawable) { + final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable; + return asyncDrawable.getBitmapWorkerTask(); + } + } + return null; + } + @Override public View getView(int position, View view, ViewGroup parent) { - if (view == null) { - LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - view = inflater.inflate(R.layout.conversation_list_row,parent, false); - } - Conversation conversation = getItem(position); - if (this.activity instanceof ConversationActivity) { - View swipeableItem = view.findViewById(R.id.swipeable_item); - ConversationActivity a = (ConversationActivity) this.activity; - int c = a.highlightSelectedConversations() && conversation == a.getSelectedConversation() ? a.getSecondaryBackgroundColor() : a.getPrimaryBackgroundColor(); - swipeableItem.setBackgroundColor(c); - } - TextView convName = (TextView) view.findViewById(R.id.conversation_name); - if (conversation.getMode() == Conversation.MODE_SINGLE || activity.useSubjectToIdentifyConference()) { - convName.setText(conversation.getName()); - } else { - convName.setText(conversation.getJid().toBareJid().toString()); - } - TextView mLastMessage = (TextView) view.findViewById(R.id.conversation_lastmsg); - TextView mTimestamp = (TextView) view.findViewById(R.id.conversation_lastupdate); - ImageView imagePreview = (ImageView) view.findViewById(R.id.conversation_lastimage); - ImageView notificationStatus = (ImageView) view.findViewById(R.id.notification_status); - - Message message = conversation.getLatestMessage(); - - if (!conversation.isRead()) { - convName.setTypeface(null, Typeface.BOLD); - } else { - convName.setTypeface(null, Typeface.NORMAL); - } - - if (message.getFileParams().width > 0 - && (message.getTransferable() == null - || message.getTransferable().getStatus() != Transferable.STATUS_DELETED)) { - mLastMessage.setVisibility(View.GONE); - imagePreview.setVisibility(View.VISIBLE); - activity.loadBitmap(message, imagePreview); - } else { - Pair<String,Boolean> preview = UIHelper.getMessagePreview(activity,message); - mLastMessage.setVisibility(View.VISIBLE); - imagePreview.setVisibility(View.GONE); - mLastMessage.setText(preview.first); - if (preview.second) { - if (conversation.isRead()) { - mLastMessage.setTypeface(null, Typeface.ITALIC); - } else { - mLastMessage.setTypeface(null,Typeface.BOLD_ITALIC); - } - } else { - if (conversation.isRead()) { - mLastMessage.setTypeface(null,Typeface.NORMAL); - } else { - mLastMessage.setTypeface(null,Typeface.BOLD); - } - } - } - - long muted_till = conversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL,0); - if (muted_till == Long.MAX_VALUE) { - notificationStatus.setVisibility(View.VISIBLE); - notificationStatus.setImageResource(R.drawable.ic_notifications_off_grey600_24dp); - } else if (muted_till >= System.currentTimeMillis()) { - notificationStatus.setVisibility(View.VISIBLE); - notificationStatus.setImageResource(R.drawable.ic_notifications_paused_grey600_24dp); - } else if (conversation.alwaysNotify()) { - notificationStatus.setVisibility(View.GONE); - } else { - notificationStatus.setVisibility(View.VISIBLE); - notificationStatus.setImageResource(R.drawable.ic_notifications_none_grey600_24dp); - } - - mTimestamp.setText(UIHelper.readableTimeDifference(activity,conversation.getLatestMessage().getTimeSent())); - ImageView profilePicture = (ImageView) view.findViewById(R.id.conversation_image); - loadAvatar(conversation,profilePicture); - - return view; - } - - class BitmapWorkerTask extends AsyncTask<Conversation, Void, Bitmap> { - private final WeakReference<ImageView> imageViewReference; - private Conversation conversation = null; - - public BitmapWorkerTask(ImageView imageView) { - imageViewReference = new WeakReference<>(imageView); - } - - @Override - protected Bitmap doInBackground(Conversation... params) { - return activity.avatarService().get(params[0], activity.getPixel(56), isCancelled()); - } - - @Override - protected void onPostExecute(Bitmap bitmap) { - if (bitmap != null && !isCancelled()) { - final ImageView imageView = imageViewReference.get(); - if (imageView != null) { - imageView.setImageBitmap(bitmap); - imageView.setBackgroundColor(0x00000000); - } - } - } + if (view == null) { + LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + view = inflater.inflate(R.layout.conversation_list_row, parent, false); + } + Conversation conversation = getItem(position); + if (this.activity instanceof ConversationActivity) { + View swipeableItem = view.findViewById(R.id.swipeable_item); + ConversationActivity a = (ConversationActivity) this.activity; + int c = a.highlightSelectedConversations() && conversation == a.getSelectedConversation() ? a.getSecondaryBackgroundColor() : a.getPrimaryBackgroundColor(); + swipeableItem.setBackgroundColor(c); + } + TextView convName = (TextView) view.findViewById(R.id.conversation_name); + if (conversation.getMode() == Conversation.MODE_SINGLE || activity.useSubjectToIdentifyConference()) { + convName.setText(conversation.getName()); + } else { + convName.setText(conversation.getJid().toBareJid().toString()); + } + TextView mLastMessage = (TextView) view.findViewById(R.id.conversation_lastmsg); + TextView mTimestamp = (TextView) view.findViewById(R.id.conversation_lastupdate); + ImageView imagePreview = (ImageView) view.findViewById(R.id.conversation_lastimage); + ImageView notificationStatus = (ImageView) view.findViewById(R.id.notification_status); + + Message message = conversation.getLatestMessage(); + + if (!conversation.isRead()) { + convName.setTypeface(null, Typeface.BOLD); + } else { + convName.setTypeface(null, Typeface.NORMAL); + } + + if (message.getFileParams().width > 0 + && (message.getTransferable() == null + || message.getTransferable().getStatus() != Transferable.STATUS_DELETED)) { + mLastMessage.setVisibility(View.GONE); + imagePreview.setVisibility(View.VISIBLE); + activity.loadBitmap(message, imagePreview); + } else { + Pair<String, Boolean> preview = UIHelper.getMessagePreview(activity, message); + mLastMessage.setVisibility(View.VISIBLE); + imagePreview.setVisibility(View.GONE); + mLastMessage.setText(preview.first); + if (preview.second) { + if (conversation.isRead()) { + mLastMessage.setTypeface(null, Typeface.ITALIC); + } else { + mLastMessage.setTypeface(null, Typeface.BOLD_ITALIC); + } + } else { + if (conversation.isRead()) { + mLastMessage.setTypeface(null, Typeface.NORMAL); + } else { + mLastMessage.setTypeface(null, Typeface.BOLD); + } + } + } + + long muted_till = conversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL, 0); + if (muted_till == Long.MAX_VALUE) { + notificationStatus.setVisibility(View.VISIBLE); + notificationStatus.setImageResource(R.drawable.ic_notifications_off_grey600_24dp); + } else if (muted_till >= System.currentTimeMillis()) { + notificationStatus.setVisibility(View.VISIBLE); + notificationStatus.setImageResource(R.drawable.ic_notifications_paused_grey600_24dp); + } else if (conversation.alwaysNotify()) { + notificationStatus.setVisibility(View.GONE); + } else { + notificationStatus.setVisibility(View.VISIBLE); + notificationStatus.setImageResource(R.drawable.ic_notifications_none_grey600_24dp); + } + + mTimestamp.setText(UIHelper.readableTimeDifference(activity, conversation.getLatestMessage().getTimeSent())); + ImageView profilePicture = (ImageView) view.findViewById(R.id.conversation_image); + loadAvatar(conversation, profilePicture); + + mLastMessage.setTextColor(Color.BLACK); + + if (conversation.getIncomingChatState().equals(ChatState.COMPOSING)) { + mLastMessage.setTextColor(ContextCompat.getColor(getContext(), R.color.green500)); + mLastMessage.setText(R.string.is_typing); + } + return view; } public void loadAvatar(Conversation conversation, ImageView imageView) { @@ -162,31 +171,6 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> { } } - public static boolean cancelPotentialWork(Conversation conversation, ImageView imageView) { - final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView); - - if (bitmapWorkerTask != null) { - final Conversation oldConversation = bitmapWorkerTask.conversation; - if (oldConversation == null || conversation != oldConversation) { - bitmapWorkerTask.cancel(true); - } else { - return false; - } - } - return true; - } - - private static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) { - if (imageView != null) { - final Drawable drawable = imageView.getDrawable(); - if (drawable instanceof AsyncDrawable) { - final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable; - return asyncDrawable.getBitmapWorkerTask(); - } - } - return null; - } - static class AsyncDrawable extends BitmapDrawable { private final WeakReference<BitmapWorkerTask> bitmapWorkerTaskReference; @@ -199,4 +183,29 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> { return bitmapWorkerTaskReference.get(); } } + + class BitmapWorkerTask extends AsyncTask<Conversation, Void, Bitmap> { + private final WeakReference<ImageView> imageViewReference; + private Conversation conversation = null; + + public BitmapWorkerTask(ImageView imageView) { + imageViewReference = new WeakReference<>(imageView); + } + + @Override + protected Bitmap doInBackground(Conversation... params) { + return activity.avatarService().get(params[0], activity.getPixel(56)); + } + + @Override + protected void onPostExecute(Bitmap bitmap) { + if (bitmap != null) { + final ImageView imageView = imageViewReference.get(); + if (imageView != null) { + imageView.setImageBitmap(bitmap); + imageView.setBackgroundColor(0x00000000); + } + } + } + } }
\ No newline at end of file |