From 240d2d68c8f0efb24de6b713181a25880d02828c Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Tue, 18 Nov 2014 00:07:27 +0100 Subject: [PATCH] context menu for conversations. fixed #630 --- .../ui/ConversationActivity.java | 54 +++++++++++++++---- src/main/res/menu/conversations_context.xml | 11 ++++ src/main/res/values/strings.xml | 1 + 3 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 src/main/res/menu/conversations_context.xml diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index 56a6bead8..ad0711571 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -15,6 +15,7 @@ import android.os.SystemClock; import android.provider.MediaStore; import android.support.v4.widget.SlidingPaneLayout; import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener; +import android.view.ContextMenu; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; @@ -73,7 +74,8 @@ public class ConversationActivity extends XmppActivity implements private View mContentView; private List conversationList = new ArrayList<>(); - private Conversation selectedConversation = null; + private Conversation mSelectedConversation = null; + private Conversation mSelectedConversationForContext = null; private ListView listView; private ConversationFragment mConversationFragment; @@ -87,11 +89,11 @@ public class ConversationActivity extends XmppActivity implements } public Conversation getSelectedConversation() { - return this.selectedConversation; + return this.mSelectedConversation; } public void setSelectedConversation(Conversation conversation) { - this.selectedConversation = conversation; + this.mSelectedConversation = conversation; } public ListView getConversationListView() { @@ -180,6 +182,7 @@ public class ConversationActivity extends XmppActivity implements hideConversationsOverview(); } }); + registerForContextMenu(listView); mContentView = findViewById(R.id.content_view_spl); if (mContentView == null) { mContentView = findViewById(R.id.content_view_ll); @@ -223,6 +226,42 @@ public class ConversationActivity extends XmppActivity implements } } + @Override + public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { + getMenuInflater().inflate(R.menu.conversations_context, menu); + AdapterView.AdapterContextMenuInfo acmi = (AdapterView.AdapterContextMenuInfo) menuInfo; + this.mSelectedConversationForContext = this.conversationList.get(acmi.position); + menu.setHeaderTitle(this.mSelectedConversationForContext.getName()); + MenuItem enableNotifications = menu.findItem(R.id.action_unmute); + MenuItem disableNotifications = menu.findItem(R.id.action_mute); + if (this.mSelectedConversationForContext.isMuted()) { + disableNotifications.setVisible(false); + } else { + enableNotifications.setVisible(false); + } + super.onCreateContextMenu(menu,v,menuInfo); + } + + @Override + public boolean onContextItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_archive: + endConversation(mSelectedConversationForContext); + return true; + case R.id.action_mute: + muteConversationDialog(mSelectedConversationForContext); + return true; + case R.id.action_unmute: + mSelectedConversationForContext.setMutedTill(0); + xmppConnectionService.updateConversation(mSelectedConversationForContext); + updateConversationList(); + ConversationActivity.this.mConversationFragment.updateMessages(); + return true; + default: + return super.onContextItemSelected(item); + } + } + public void openConversation() { ActionBar ab = getActionBar(); if (ab != null) { @@ -580,7 +619,7 @@ public class ConversationActivity extends XmppActivity implements protected void muteConversationDialog(final Conversation conversation) { AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.disable_notifications_for_this_conversation); + builder.setTitle(R.string.disable_notifications); final int[] durations = getResources().getIntArray( R.array.mute_options_durations); builder.setItems(R.array.mute_options_descriptions, @@ -598,11 +637,8 @@ public class ConversationActivity extends XmppActivity implements conversation.setMutedTill(till); ConversationActivity.this.xmppConnectionService.databaseBackend .updateConversation(conversation); - ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager() - .findFragmentByTag("conversation"); - if (selectedFragment != null) { - selectedFragment.updateMessages(); - } + updateConversationList(); + ConversationActivity.this.mConversationFragment.updateMessages(); } }); builder.create().show(); diff --git a/src/main/res/menu/conversations_context.xml b/src/main/res/menu/conversations_context.xml new file mode 100644 index 000000000..28dc2a6d9 --- /dev/null +++ b/src/main/res/menu/conversations_context.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index d7fc8891c..6881c7f9c 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -351,4 +351,5 @@ Are you sure that you want to verify your contacts OTR fingerprint? Show dynamic tags Display read-only tags underneath contacts + Enable notifications