added ability to disable notifications for specific conversations - fixed #322

This commit is contained in:
iNPUTmice 2014-09-03 12:36:54 +02:00
parent 1f378bffc8
commit 1a09a4706b
7 changed files with 76 additions and 0 deletions

View file

@ -44,6 +44,11 @@
android:orderInCategory="60" android:orderInCategory="60"
android:showAsAction="never" android:showAsAction="never"
android:title="@string/action_end_conversation"/> android:title="@string/action_end_conversation"/>
<item
android:id="@+id/action_mute"
android:orderInCategory="70"
android:showAsAction="never"
android:title="@string/disable_notifications"/>
<item <item
android:id="@+id/action_accounts" android:id="@+id/action_accounts"
android:orderInCategory="90" android:orderInCategory="90"

View file

@ -19,4 +19,18 @@
<item>524288</item> <item>524288</item>
<item>1048576</item> <item>1048576</item>
</string-array> </string-array>
<string-array name="mute_options_descriptions">
<item>30 minutes</item>
<item>one hour</item>
<item>2 hours</item>
<item>8 hours</item>
<item>until further notice</item>
</string-array>
<integer-array name="mute_options_durations">
<item>1800</item>
<item>3600</item>
<item>7200</item>
<item>28800</item>
<item>-1</item>
</integer-array>
</resources> </resources>

View file

@ -235,5 +235,9 @@
<string name="server_info_session_established">Current session established</string> <string name="server_info_session_established">Current session established</string>
<string name="additional_information">Additional Information</string> <string name="additional_information">Additional Information</string>
<string name="skip">Skip</string> <string name="skip">Skip</string>
<string name="disable_notifications">Disable notifications</string>
<string name="disable_notifications_for_this_conversation">Disable notifications for this conversation</string>
<string name="notifications_disabled">Notifications are disabled</string>
<string name="enable">Enable</string>
</resources> </resources>

View file

@ -16,6 +16,7 @@ import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.SystemClock;
public class Conversation extends AbstractEntity { public class Conversation extends AbstractEntity {
public static final String TABLENAME = "conversations"; public static final String TABLENAME = "conversations";
@ -43,6 +44,8 @@ public class Conversation extends AbstractEntity {
private long created; private long created;
private int mode; private int mode;
private long mutedTill = 0;
private String nextPresence; private String nextPresence;
private transient CopyOnWriteArrayList<Message> messages = null; private transient CopyOnWriteArrayList<Message> messages = null;
@ -418,4 +421,12 @@ public class Conversation extends AbstractEntity {
} }
return false; return false;
} }
public void setMutedTill(long mutedTill) {
this.mutedTill = mutedTill;
}
public boolean isMuted() {
return SystemClock.elapsedRealtime() < this.mutedTill;
}
} }

View file

@ -435,6 +435,7 @@ public class MessageParser extends AbstractParser implements
if (packet.getType() != MessagePacket.TYPE_ERROR) { if (packet.getType() != MessagePacket.TYPE_ERROR) {
mXmppConnectionService.databaseBackend.createMessage(message); mXmppConnectionService.databaseBackend.createMessage(message);
} }
notify = notify && !conversation.isMuted();
mXmppConnectionService.notifyUi(conversation, notify); mXmppConnectionService.notifyUi(conversation, notify);
} }

View file

@ -13,6 +13,7 @@ import eu.siacs.conversations.utils.ExceptionHelper;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.SystemClock;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.app.ActionBar; import android.app.ActionBar;
import android.app.AlertDialog; import android.app.AlertDialog;
@ -214,6 +215,7 @@ public class ConversationActivity extends XmppActivity {
MenuItem menuAdd = (MenuItem) menu.findItem(R.id.action_add); MenuItem menuAdd = (MenuItem) menu.findItem(R.id.action_add);
MenuItem menuInviteContact = (MenuItem) menu MenuItem menuInviteContact = (MenuItem) menu
.findItem(R.id.action_invite); .findItem(R.id.action_invite);
MenuItem menuMute = (MenuItem) menu.findItem(R.id.action_mute);
if ((spl.isOpen() && (spl.isSlideable()))) { if ((spl.isOpen() && (spl.isSlideable()))) {
menuArchive.setVisible(false); menuArchive.setVisible(false);
@ -223,6 +225,7 @@ public class ConversationActivity extends XmppActivity {
menuInviteContact.setVisible(false); menuInviteContact.setVisible(false);
menuAttach.setVisible(false); menuAttach.setVisible(false);
menuClearHistory.setVisible(false); menuClearHistory.setVisible(false);
menuMute.setVisible(false);
} else { } else {
menuAdd.setVisible(!spl.isSlideable()); menuAdd.setVisible(!spl.isSlideable());
if (this.getSelectedConversation() != null) { if (this.getSelectedConversation() != null) {
@ -463,6 +466,9 @@ public class ConversationActivity extends XmppActivity {
case R.id.action_clear_history: case R.id.action_clear_history:
clearHistoryDialog(getSelectedConversation()); clearHistoryDialog(getSelectedConversation());
break; break;
case R.id.action_mute:
muteConversationDialog(getSelectedConversation());
break;
default: default:
break; break;
} }
@ -505,6 +511,31 @@ public class ConversationActivity extends XmppActivity {
builder.create().show(); 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() { protected ConversationFragment swapConversationFragment() {
ConversationFragment selectedFragment = new ConversationFragment(); ConversationFragment selectedFragment = new ConversationFragment();
if (!isFinishing()) { if (!isFinishing()) {

View file

@ -406,6 +406,16 @@ public class ConversationFragment extends Fragment {
break; 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) { if (this.conversation.getMessages().size() == 0) {
this.messageList.clear(); this.messageList.clear();
messagesLoaded = false; messagesLoaded = false;