Display unread messages on chat list view
This commit is contained in:
parent
e03a2ee2e8
commit
f02038997f
5 changed files with 53 additions and 30 deletions
|
@ -19,16 +19,18 @@
|
||||||
android:visibility="invisible"
|
android:visibility="invisible"
|
||||||
android:src="@drawable/list_delete" />
|
android:src="@drawable/list_delete" />
|
||||||
|
|
||||||
<ImageView
|
<TextView
|
||||||
android:contentDescription="@string/content_description_detail"
|
android:id="@+id/unreadMessages"
|
||||||
android:id="@+id/detail"
|
android:layout_width="25dp"
|
||||||
android:paddingRight="5dp"
|
android:layout_height="25dp"
|
||||||
android:layout_width="wrap_content"
|
android:layout_marginRight="5dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_toLeftOf="@id/delete"
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
|
android:background="@drawable/chat_icon_over"
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
android:src="@drawable/list_detail" />
|
android:gravity="center"
|
||||||
|
android:textSize="18dp"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/draft"
|
android:id="@+id/draft"
|
||||||
|
@ -38,7 +40,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
android:textColor="@color/text_selected"
|
android:textColor="@color/text_selected"
|
||||||
android:layout_toLeftOf="@id/detail"
|
android:layout_toLeftOf="@id/unreadMessages"
|
||||||
android:text="@string/draft"
|
android:text="@string/draft"
|
||||||
android:layout_marginLeft="5dp"
|
android:layout_marginLeft="5dp"
|
||||||
android:layout_marginRight="5dp" />
|
android:layout_marginRight="5dp" />
|
||||||
|
|
|
@ -328,7 +328,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
saveImage(item.getGroupId());
|
saveImage(item.getGroupId());
|
||||||
break;
|
break;
|
||||||
case MENU_COPY_TEXT:
|
case MENU_COPY_TEXT:
|
||||||
copyText(item.getGroupId());
|
copyTextMessageToClipboard(item.getGroupId());
|
||||||
break;
|
break;
|
||||||
case MENU_PICTURE_SMALL:
|
case MENU_PICTURE_SMALL:
|
||||||
uploadAndSendImage(fileToUploadPath, imageToUpload, ImageSize.SMALL);
|
uploadAndSendImage(fileToUploadPath, imageToUpload, ImageSize.SMALL);
|
||||||
|
@ -431,7 +431,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyText(int id) {
|
private void copyTextMessageToClipboard(int id) {
|
||||||
String msg = LinphoneActivity.instance().getChatStorage().getTextMessageForId(id);
|
String msg = LinphoneActivity.instance().getChatStorage().getTextMessageForId(id);
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
Compatibility.copyTextToClipboard(getActivity(), msg);
|
Compatibility.copyTextToClipboard(getActivity(), msg);
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.linphone.core.LinphoneAddress;
|
||||||
import org.linphone.core.LinphoneCoreFactory;
|
import org.linphone.core.LinphoneCoreFactory;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
import android.view.ContextMenu.ContextMenuInfo;
|
||||||
|
@ -44,6 +45,8 @@ import android.widget.TextView;
|
||||||
* @author Sylvain Berfini
|
* @author Sylvain Berfini
|
||||||
*/
|
*/
|
||||||
public class ChatListFragment extends Fragment implements OnClickListener, OnItemClickListener {
|
public class ChatListFragment extends Fragment implements OnClickListener, OnItemClickListener {
|
||||||
|
private Handler mHandler = new Handler();
|
||||||
|
|
||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
private List<String> mConversations, mDrafts;
|
private List<String> mConversations, mDrafts;
|
||||||
private ListView chatList;
|
private ListView chatList;
|
||||||
|
@ -91,6 +94,18 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
chatList.setAdapter(new ChatListAdapter());
|
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
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
|
@ -98,12 +113,10 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
|
|
||||||
if (LinphoneActivity.isInstanciated()) {
|
if (LinphoneActivity.isInstanciated()) {
|
||||||
LinphoneActivity.instance().selectMenu(FragmentsAvailable.CHATLIST);
|
LinphoneActivity.instance().selectMenu(FragmentsAvailable.CHATLIST);
|
||||||
|
LinphoneActivity.instance().updateChatListFragment(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
mConversations = LinphoneActivity.instance().getChatList();
|
refresh();
|
||||||
mDrafts = LinphoneActivity.instance().getDraftChatList();
|
|
||||||
mConversations.removeAll(mDrafts);
|
|
||||||
hideAndDisplayMessageIfNoChat();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -216,7 +229,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
isDraft = true;
|
isDraft = true;
|
||||||
}
|
}
|
||||||
view.setTag(contact);
|
view.setTag(contact);
|
||||||
final String fContact = contact;
|
int unreadMessagesCount = LinphoneActivity.instance().getChatStorage().getUnreadMessageCount(contact);
|
||||||
|
|
||||||
LinphoneAddress address = LinphoneCoreFactory.instance().createLinphoneAddress(contact);
|
LinphoneAddress address = LinphoneCoreFactory.instance().createLinphoneAddress(contact);
|
||||||
LinphoneUtils.findUriPictureOfContactAndSetDisplayName(address, view.getContext().getContentResolver());
|
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);
|
view.findViewById(R.id.draft).setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageView delete, detail;
|
ImageView delete = (ImageView) view.findViewById(R.id.delete);
|
||||||
delete = (ImageView) view.findViewById(R.id.delete);
|
TextView unreadMessages = (TextView) view.findViewById(R.id.unreadMessages);
|
||||||
detail = (ImageView) view.findViewById(R.id.detail);
|
|
||||||
|
if (unreadMessagesCount > 0) {
|
||||||
|
unreadMessages.setVisibility(View.VISIBLE);
|
||||||
|
unreadMessages.setText(String.valueOf(unreadMessagesCount));
|
||||||
|
} else {
|
||||||
|
unreadMessages.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
if (isEditMode) {
|
if (isEditMode) {
|
||||||
delete.setVisibility(View.VISIBLE);
|
delete.setVisibility(View.VISIBLE);
|
||||||
detail.setVisibility(View.INVISIBLE);
|
|
||||||
} else {
|
} else {
|
||||||
delete.setVisibility(View.INVISIBLE);
|
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;
|
return view;
|
||||||
|
|
|
@ -235,6 +235,10 @@ public class ChatStorage {
|
||||||
return db.query(TABLE_NAME, null, "read LIKE " + NOT_READ, null, null, null, null).getCount();
|
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) {
|
public byte[] getRawImageFromMessage(int id) {
|
||||||
String[] columns = { "image" };
|
String[] columns = { "image" };
|
||||||
Cursor c = db.query(TABLE_NAME, columns, "id LIKE " + id + "", null, null, null, null);
|
Cursor c = db.query(TABLE_NAME, columns, "id LIKE " + id + "", null, null, null, null);
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
private LinearLayout menu, mark;
|
private LinearLayout menu, mark;
|
||||||
private RelativeLayout contacts, history, settings, chat, aboutChat, aboutSettings;
|
private RelativeLayout contacts, history, settings, chat, aboutChat, aboutSettings;
|
||||||
private FragmentsAvailable currentFragment, nextFragment;
|
private FragmentsAvailable currentFragment, nextFragment;
|
||||||
private Fragment dialerFragment, messageListenerFragment;
|
private Fragment dialerFragment, messageListenerFragment, messageListFragment;
|
||||||
private SavedState dialerSavedState;
|
private SavedState dialerSavedState;
|
||||||
private ChatStorage chatStorage;
|
private ChatStorage chatStorage;
|
||||||
private boolean preferLinphoneContacts = false, isAnimationDisabled = false;
|
private boolean preferLinphoneContacts = false, isAnimationDisabled = false;
|
||||||
|
@ -268,6 +268,7 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
break;
|
break;
|
||||||
case CHATLIST:
|
case CHATLIST:
|
||||||
newFragment = new ChatListFragment();
|
newFragment = new ChatListFragment();
|
||||||
|
messageListFragment = new Fragment();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -587,6 +588,10 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateChatListFragment(ChatListFragment fragment) {
|
||||||
|
messageListFragment = fragment;
|
||||||
|
}
|
||||||
|
|
||||||
public void hideMenu(boolean hide) {
|
public void hideMenu(boolean hide) {
|
||||||
menu.setVisibility(hide ? View.GONE : View.VISIBLE);
|
menu.setVisibility(hide ? View.GONE : View.VISIBLE);
|
||||||
mark.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);
|
getChatStorage().markMessageAsRead(id);
|
||||||
} else if (LinphoneService.isReady()) {
|
} else if (LinphoneService.isReady()) {
|
||||||
displayMissedChats(getChatStorage().getUnreadMessageCount());
|
displayMissedChats(getChatStorage().getUnreadMessageCount());
|
||||||
|
if (messageListFragment != null && messageListFragment.isVisible()) {
|
||||||
|
((ChatListFragment) messageListFragment).refresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
LinphoneUtils.findUriPictureOfContactAndSetDisplayName(from, getContentResolver());
|
LinphoneUtils.findUriPictureOfContactAndSetDisplayName(from, getContentResolver());
|
||||||
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getDisplayName(), notificationText);
|
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getDisplayName(), notificationText);
|
||||||
|
|
Loading…
Reference in a new issue