From 1a09a4706b7cc53225abd5c6124f3da2f784ad61 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Wed, 3 Sep 2014 12:36:54 +0200 Subject: [PATCH] added ability to disable notifications for specific conversations - fixed #322 --- res/menu/conversations.xml | 5 +++ res/values/arrays.xml | 14 +++++++++ res/values/strings.xml | 4 +++ .../conversations/entities/Conversation.java | 11 +++++++ .../conversations/parser/MessageParser.java | 1 + .../ui/ConversationActivity.java | 31 +++++++++++++++++++ .../ui/ConversationFragment.java | 10 ++++++ 7 files changed, 76 insertions(+) diff --git a/res/menu/conversations.xml b/res/menu/conversations.xml index 215bbb66c..3edee120a 100644 --- a/res/menu/conversations.xml +++ b/res/menu/conversations.xml @@ -44,6 +44,11 @@ android:orderInCategory="60" android:showAsAction="never" android:title="@string/action_end_conversation"/> + 524288 1048576 + + 30 minutes + one hour + 2 hours + 8 hours + until further notice + + + 1800 + 3600 + 7200 + 28800 + -1 + diff --git a/res/values/strings.xml b/res/values/strings.xml index e799b0ae4..7b9c8d959 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -235,5 +235,9 @@ Current session established Additional Information Skip + Disable notifications + Disable notifications for this conversation + Notifications are disabled + Enable \ No newline at end of file diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java index 8dc9b3cad..2097b2a45 100644 --- a/src/eu/siacs/conversations/entities/Conversation.java +++ b/src/eu/siacs/conversations/entities/Conversation.java @@ -16,6 +16,7 @@ import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.graphics.Bitmap; +import android.os.SystemClock; public class Conversation extends AbstractEntity { public static final String TABLENAME = "conversations"; @@ -42,6 +43,8 @@ public class Conversation extends AbstractEntity { private int status; private long created; private int mode; + + private long mutedTill = 0; private String nextPresence; @@ -418,4 +421,12 @@ public class Conversation extends AbstractEntity { } return false; } + + public void setMutedTill(long mutedTill) { + this.mutedTill = mutedTill; + } + + public boolean isMuted() { + return SystemClock.elapsedRealtime() < this.mutedTill; + } } diff --git a/src/eu/siacs/conversations/parser/MessageParser.java b/src/eu/siacs/conversations/parser/MessageParser.java index 3dca636ea..108593450 100644 --- a/src/eu/siacs/conversations/parser/MessageParser.java +++ b/src/eu/siacs/conversations/parser/MessageParser.java @@ -435,6 +435,7 @@ public class MessageParser extends AbstractParser implements if (packet.getType() != MessagePacket.TYPE_ERROR) { mXmppConnectionService.databaseBackend.createMessage(message); } + notify = notify && !conversation.isMuted(); mXmppConnectionService.notifyUi(conversation, notify); } diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index 32c77fbed..17e410f22 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -13,6 +13,7 @@ import eu.siacs.conversations.utils.ExceptionHelper; import eu.siacs.conversations.utils.UIHelper; import android.net.Uri; import android.os.Bundle; +import android.os.SystemClock; import android.provider.MediaStore; import android.app.ActionBar; import android.app.AlertDialog; @@ -214,6 +215,7 @@ public class ConversationActivity extends XmppActivity { MenuItem menuAdd = (MenuItem) menu.findItem(R.id.action_add); MenuItem menuInviteContact = (MenuItem) menu .findItem(R.id.action_invite); + MenuItem menuMute = (MenuItem) menu.findItem(R.id.action_mute); if ((spl.isOpen() && (spl.isSlideable()))) { menuArchive.setVisible(false); @@ -223,6 +225,7 @@ public class ConversationActivity extends XmppActivity { menuInviteContact.setVisible(false); menuAttach.setVisible(false); menuClearHistory.setVisible(false); + menuMute.setVisible(false); } else { menuAdd.setVisible(!spl.isSlideable()); if (this.getSelectedConversation() != null) { @@ -463,6 +466,9 @@ public class ConversationActivity extends XmppActivity { case R.id.action_clear_history: clearHistoryDialog(getSelectedConversation()); break; + case R.id.action_mute: + muteConversationDialog(getSelectedConversation()); + break; default: break; } @@ -504,6 +510,31 @@ public class ConversationActivity extends XmppActivity { }); builder.create().show(); } + + protected void muteConversationDialog(final Conversation conversation) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.disable_notifications_for_this_conversation); + final int[] durations = getResources().getIntArray(R.array.mute_options_durations); + builder.setItems(R.array.mute_options_descriptions, new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + long till; + if (durations[which]==-1) { + till = Long.MAX_VALUE; + } else { + till = SystemClock.elapsedRealtime() + (durations[which] * 1000); + } + conversation.setMutedTill(till); + ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager() + .findFragmentByTag("conversation"); + if (selectedFragment!=null) { + selectedFragment.updateMessages(); + } + } + }); + builder.create().show(); + } protected ConversationFragment swapConversationFragment() { ConversationFragment selectedFragment = new ConversationFragment(); diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index b0fd4a033..d0e5bdb4c 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -406,6 +406,16 @@ public class ConversationFragment extends Fragment { break; } } + if (this.conversation.isMuted()) { + showSnackbar(R.string.notifications_disabled, R.string.enable, new OnClickListener() { + + @Override + public void onClick(View v) { + conversation.setMutedTill(0); + updateMessages(); + } + }); + } if (this.conversation.getMessages().size() == 0) { this.messageList.clear(); messagesLoaded = false;