diff --git a/res/layout/chatlist_cell.xml b/res/layout/chatlist_cell.xml index adcc02ee4..6dc7ed1ff 100644 --- a/res/layout/chatlist_cell.xml +++ b/res/layout/chatlist_cell.xml @@ -19,16 +19,18 @@ android:visibility="invisible" android:src="@drawable/list_delete" /> - + android:gravity="center" + android:textSize="18dp" + android:visibility="gone" /> diff --git a/src/org/linphone/ChatFragment.java b/src/org/linphone/ChatFragment.java index 35b79df2f..d76e998d3 100644 --- a/src/org/linphone/ChatFragment.java +++ b/src/org/linphone/ChatFragment.java @@ -328,7 +328,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC saveImage(item.getGroupId()); break; case MENU_COPY_TEXT: - copyText(item.getGroupId()); + copyTextMessageToClipboard(item.getGroupId()); break; case MENU_PICTURE_SMALL: uploadAndSendImage(fileToUploadPath, imageToUpload, ImageSize.SMALL); @@ -431,7 +431,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC }, 100); } - private void copyText(int id) { + private void copyTextMessageToClipboard(int id) { String msg = LinphoneActivity.instance().getChatStorage().getTextMessageForId(id); if (msg != null) { Compatibility.copyTextToClipboard(getActivity(), msg); diff --git a/src/org/linphone/ChatListFragment.java b/src/org/linphone/ChatListFragment.java index 38f0ff456..ce269afc3 100644 --- a/src/org/linphone/ChatListFragment.java +++ b/src/org/linphone/ChatListFragment.java @@ -23,6 +23,7 @@ import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneCoreFactory; import android.os.Bundle; +import android.os.Handler; import android.support.v4.app.Fragment; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -44,6 +45,8 @@ import android.widget.TextView; * @author Sylvain Berfini */ public class ChatListFragment extends Fragment implements OnClickListener, OnItemClickListener { + private Handler mHandler = new Handler(); + private LayoutInflater mInflater; private List mConversations, mDrafts; private ListView chatList; @@ -91,6 +94,18 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte chatList.setAdapter(new ChatListAdapter()); } } + + public void refresh() { + mHandler.post(new Runnable() { + @Override + public void run() { + mConversations = LinphoneActivity.instance().getChatList(); + mDrafts = LinphoneActivity.instance().getDraftChatList(); + mConversations.removeAll(mDrafts); + hideAndDisplayMessageIfNoChat(); + } + }); + } @Override public void onResume() { @@ -98,12 +113,10 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte if (LinphoneActivity.isInstanciated()) { LinphoneActivity.instance().selectMenu(FragmentsAvailable.CHATLIST); + LinphoneActivity.instance().updateChatListFragment(this); } - mConversations = LinphoneActivity.instance().getChatList(); - mDrafts = LinphoneActivity.instance().getDraftChatList(); - mConversations.removeAll(mDrafts); - hideAndDisplayMessageIfNoChat(); + refresh(); } @Override @@ -216,7 +229,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte isDraft = true; } view.setTag(contact); - final String fContact = contact; + int unreadMessagesCount = LinphoneActivity.instance().getChatStorage().getUnreadMessageCount(contact); LinphoneAddress address = LinphoneCoreFactory.instance().createLinphoneAddress(contact); LinphoneUtils.findUriPictureOfContactAndSetDisplayName(address, view.getContext().getContentResolver()); @@ -234,24 +247,20 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte view.findViewById(R.id.draft).setVisibility(View.VISIBLE); } - ImageView delete, detail; - delete = (ImageView) view.findViewById(R.id.delete); - detail = (ImageView) view.findViewById(R.id.detail); + ImageView delete = (ImageView) view.findViewById(R.id.delete); + TextView unreadMessages = (TextView) view.findViewById(R.id.unreadMessages); + + if (unreadMessagesCount > 0) { + unreadMessages.setVisibility(View.VISIBLE); + unreadMessages.setText(String.valueOf(unreadMessagesCount)); + } else { + unreadMessages.setVisibility(View.GONE); + } if (isEditMode) { delete.setVisibility(View.VISIBLE); - detail.setVisibility(View.INVISIBLE); } else { delete.setVisibility(View.INVISIBLE); - detail.setVisibility(View.VISIBLE); - detail.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - if (LinphoneActivity.isInstanciated()) { - LinphoneActivity.instance().displayChat(fContact); - } - } - }); } return view; diff --git a/src/org/linphone/ChatStorage.java b/src/org/linphone/ChatStorage.java index b62d9a2db..5625b120f 100644 --- a/src/org/linphone/ChatStorage.java +++ b/src/org/linphone/ChatStorage.java @@ -235,6 +235,10 @@ public class ChatStorage { return db.query(TABLE_NAME, null, "read LIKE " + NOT_READ, null, null, null, null).getCount(); } + public int getUnreadMessageCount(String contact) { + return db.query(TABLE_NAME, null, "remoteContact LIKE \"" + contact + "\" AND read LIKE " + NOT_READ, null, null, null, null).getCount(); + } + public byte[] getRawImageFromMessage(int id) { String[] columns = { "image" }; Cursor c = db.query(TABLE_NAME, columns, "id LIKE " + id + "", null, null, null, null); diff --git a/src/org/linphone/LinphoneActivity.java b/src/org/linphone/LinphoneActivity.java index 614fdb467..32d648779 100644 --- a/src/org/linphone/LinphoneActivity.java +++ b/src/org/linphone/LinphoneActivity.java @@ -96,7 +96,7 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene private LinearLayout menu, mark; private RelativeLayout contacts, history, settings, chat, aboutChat, aboutSettings; private FragmentsAvailable currentFragment, nextFragment; - private Fragment dialerFragment, messageListenerFragment; + private Fragment dialerFragment, messageListenerFragment, messageListFragment; private SavedState dialerSavedState; private ChatStorage chatStorage; private boolean preferLinphoneContacts = false, isAnimationDisabled = false; @@ -268,6 +268,7 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene break; case CHATLIST: newFragment = new ChatListFragment(); + messageListFragment = new Fragment(); break; } @@ -587,6 +588,10 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); } + public void updateChatListFragment(ChatListFragment fragment) { + messageListFragment = fragment; + } + public void hideMenu(boolean hide) { menu.setVisibility(hide ? View.GONE : View.VISIBLE); mark.setVisibility(hide ? View.GONE : View.VISIBLE); @@ -685,6 +690,9 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene getChatStorage().markMessageAsRead(id); } else if (LinphoneService.isReady()) { displayMissedChats(getChatStorage().getUnreadMessageCount()); + if (messageListFragment != null && messageListFragment.isVisible()) { + ((ChatListFragment) messageListFragment).refresh(); + } } LinphoneUtils.findUriPictureOfContactAndSetDisplayName(from, getContentResolver()); LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getDisplayName(), notificationText);