From 240d2d68c8f0efb24de6b713181a25880d02828c Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Tue, 18 Nov 2014 00:07:27 +0100 Subject: context menu for conversations. fixed #630 --- .../conversations/ui/ConversationActivity.java | 54 ++++++++++++++++++---- 1 file changed, 45 insertions(+), 9 deletions(-) (limited to 'src/main/java/eu') diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index 56a6bead..ad071157 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(); -- cgit v1.2.3