From ad7e8e76f0fad8b3887c332fbaddcc77daee8df0 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Thu, 9 Feb 2017 23:55:40 +0100 Subject: move (un)mute settings to contact-/conference details --- .../messenger/ui/ConferenceDetailsActivity.java | 21 ++++- .../messenger/ui/ContactDetailsActivity.java | 81 ++++++++++++++++++ .../pixart/messenger/ui/ConversationActivity.java | 48 ----------- src/main/res/layout/activity_contact_details.xml | 97 +++++++++++++++------- src/main/res/menu/conversations.xml | 25 ------ 5 files changed, 167 insertions(+), 105 deletions(-) (limited to 'src') diff --git a/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java index a7f6d421f..a6e2a40de 100644 --- a/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java @@ -111,7 +111,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers getString(R.string.notify_never) }; final AtomicInteger choice; - if (mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL, 0) == Long.MAX_VALUE) { + if (mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL, 0) <= Long.MAX_VALUE) { choice = new AtomicInteger(2); } else { choice = new AtomicInteger(mConversation.alwaysNotify() ? 0 : 1); @@ -127,7 +127,24 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers @Override public void onClick(DialogInterface dialog, int which) { if (choice.get() == 2) { - mConversation.setMutedTill(Long.MAX_VALUE); + AlertDialog.Builder builder = new AlertDialog.Builder(ConferenceDetailsActivity.this); + builder.setTitle(R.string.disable_notifications); + final int[] durations = getResources().getIntArray(R.array.mute_options_durations); + builder.setItems(R.array.mute_options_descriptions, + new DialogInterface.OnClickListener() { + + @Override + public void onClick(final DialogInterface dialog, final int which) { + final long till; + if (durations[which] == -1) { + till = Long.MAX_VALUE; + } else { + till = System.currentTimeMillis() + (durations[which] * 1000); + } + mConversation.setMutedTill(till); + } + }); + builder.create().show(); } else { mConversation.setMutedTill(0); mConversation.setAttribute(Conversation.ATTRIBUTE_ALWAYS_NOTIFY, String.valueOf(choice.get() == 0)); diff --git a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java index 4a77784af..adebdc3ad 100644 --- a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java @@ -34,6 +34,7 @@ import com.wefika.flowlayout.FlowLayout; import org.openintents.openpgp.util.OpenPgpUtils; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; import de.pixart.messenger.Config; import de.pixart.messenger.R; @@ -43,6 +44,7 @@ import de.pixart.messenger.crypto.axolotl.FingerprintStatus; import de.pixart.messenger.crypto.axolotl.XmppAxolotlSession; import de.pixart.messenger.entities.Account; import de.pixart.messenger.entities.Contact; +import de.pixart.messenger.entities.Conversation; import de.pixart.messenger.entities.ListItem; import de.pixart.messenger.services.XmppConnectionService.OnAccountUpdate; import de.pixart.messenger.services.XmppConnectionService.OnRosterUpdate; @@ -59,6 +61,8 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp public static final String ACTION_VIEW_CONTACT = "view_contact"; private Contact contact; + private Conversation mConversation; + private DialogInterface.OnClickListener removeFromRoster = new DialogInterface.OnClickListener() { @Override @@ -123,6 +127,8 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp private boolean showLastSeen = false; private boolean showInactiveOmemo = false; private String messageFingerprint; + private TextView mNotifyStatusText; + private ImageButton mNotifyStatusButton; private DialogInterface.OnClickListener addToPhonebook = new DialogInterface.OnClickListener() { @@ -160,6 +166,62 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp } }; + private OnClickListener mNotifyStatusClickListener = new OnClickListener() { + @Override + public void onClick(View v) { + AlertDialog.Builder builder = new AlertDialog.Builder(ContactDetailsActivity.this); + builder.setTitle(R.string.pref_notification_settings); + String[] choices = { + getString(R.string.notify_on_all_messages), + getString(R.string.notify_never) + }; + final AtomicInteger choice; + if (mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL, 0) <= Long.MAX_VALUE) { + choice = new AtomicInteger(1); + } else { + choice = new AtomicInteger(0); + } + builder.setSingleChoiceItems(choices, choice.get(), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + choice.set(which); + } + }); + builder.setNegativeButton(R.string.cancel, null); + builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (choice.get() == 1) { + AlertDialog.Builder builder = new AlertDialog.Builder(ContactDetailsActivity.this); + builder.setTitle(R.string.disable_notifications); + final int[] durations = getResources().getIntArray(R.array.mute_options_durations); + builder.setItems(R.array.mute_options_descriptions, + new DialogInterface.OnClickListener() { + + @Override + public void onClick(final DialogInterface dialog, final int which) { + final long till; + if (durations[which] == -1) { + till = Long.MAX_VALUE; + } else { + till = System.currentTimeMillis() + (durations[which] * 1000); + } + mConversation.setMutedTill(till); + } + }); + builder.create().show(); + } else { + mConversation.setMutedTill(0); + mConversation.setAttribute(Conversation.ATTRIBUTE_ALWAYS_NOTIFY, String.valueOf(choice.get() == 0)); + } + xmppConnectionService.updateConversation(mConversation); + populateView(); + } + }); + builder.create().show(); + } + }; + @Override public void onRosterUpdate() { refreshUi(); @@ -236,6 +298,9 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp populateView(); } }); + this.mNotifyStatusButton = (ImageButton) findViewById(R.id.notification_status_button); + this.mNotifyStatusButton.setOnClickListener(this.mNotifyStatusClickListener); + this.mNotifyStatusText = (TextView) findViewById(R.id.notification_status_text); } @Override @@ -338,6 +403,18 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp if (contact == null) { return; } + + long mutedTill = mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL, 0); + if (mutedTill == Long.MAX_VALUE) { + mNotifyStatusText.setText(R.string.notify_never); + mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_off_grey600_24dp); + } else if (System.currentTimeMillis() < mutedTill) { + mNotifyStatusText.setText(R.string.notify_paused); + mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_paused_grey600_24dp); + } else { + mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_grey600_24dp); + mNotifyStatusText.setText(R.string.notify_on_all_messages); + } if (getActionBar() != null) { final ActionBar ab = getActionBar(); ab.setCustomView(R.layout.ab_title); @@ -580,6 +657,10 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp if (account == null) { return; } + this.mConversation = xmppConnectionService.findOrCreateConversation(account, contactJid, false); + if (this.mConversation != null) { + populateView(); + } this.contact = account.getRoster().getContact(contactJid); if (mPendingFingerprintVerificationUri != null) { processFingerprintVerification(mPendingFingerprintVerificationUri); diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java index dadab9a72..6bcf9c631 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java @@ -512,8 +512,6 @@ public class ConversationActivity extends XmppActivity final MenuItem menuClearHistory = menu.findItem(R.id.action_clear_history); final MenuItem menuAdd = menu.findItem(R.id.action_add); final MenuItem menuInviteContact = menu.findItem(R.id.action_invite); - final MenuItem menuMute = menu.findItem(R.id.action_mute); - final MenuItem menuUnmute = menu.findItem(R.id.action_unmute); final MenuItem menuUpdater = menu.findItem(R.id.action_check_updates); final MenuItem menuInviteUser = menu.findItem(R.id.action_invite_user); @@ -524,8 +522,6 @@ public class ConversationActivity extends XmppActivity menuInviteContact.setVisible(false); menuAttach.setVisible(false); menuClearHistory.setVisible(false); - menuMute.setVisible(false); - menuUnmute.setVisible(false); } else { menuAdd.setVisible(!isConversationsOverviewHideable()); //hide settings, accounts and updater in all menus except in main window @@ -552,11 +548,6 @@ public class ConversationActivity extends XmppActivity } else { menuSecure.setVisible(Config.multipleEncryptionChoices()); } - if (this.getSelectedConversation().isMuted()) { - menuMute.setVisible(false); - } else { - menuUnmute.setVisible(false); - } } } if (Config.supportOmemo()) { @@ -842,12 +833,6 @@ public class ConversationActivity extends XmppActivity case R.id.action_clear_history: clearHistoryDialog(getSelectedConversation()); break; - case R.id.action_mute: - muteConversationDialog(getSelectedConversation()); - break; - case R.id.action_unmute: - unmuteConversation(getSelectedConversation()); - break; case R.id.action_block: BlockContactDialog.show(this, xmppConnectionService, getSelectedConversation()); break; @@ -1088,39 +1073,6 @@ public class ConversationActivity extends XmppActivity } } - protected void muteConversationDialog(final Conversation conversation) { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.disable_notifications); - final int[] durations = getResources().getIntArray(R.array.mute_options_durations); - builder.setItems(R.array.mute_options_descriptions, - new OnClickListener() { - - @Override - public void onClick(final DialogInterface dialog, final int which) { - final long till; - if (durations[which] == -1) { - till = Long.MAX_VALUE; - } else { - till = System.currentTimeMillis() + (durations[which] * 1000); - } - conversation.setMutedTill(till); - ConversationActivity.this.xmppConnectionService.updateConversation(conversation); - updateConversationList(); - ConversationActivity.this.mConversationFragment.updateMessages(); - invalidateOptionsMenu(); - } - }); - builder.create().show(); - } - - public void unmuteConversation(final Conversation conversation) { - conversation.setMutedTill(0); - this.xmppConnectionService.updateConversation(conversation); - updateConversationList(); - ConversationActivity.this.mConversationFragment.updateMessages(); - invalidateOptionsMenu(); - } - @Override public void onBackPressed() { if (!isConversationsOverviewVisable()) { diff --git a/src/main/res/layout/activity_contact_details.xml b/src/main/res/layout/activity_contact_details.xml index 46b0f1768..4c0e54955 100644 --- a/src/main/res/layout/activity_contact_details.xml +++ b/src/main/res/layout/activity_contact_details.xml @@ -72,18 +72,55 @@ android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:textColor="@color/black54" - android:textSize="?attr/TextSizeBody" /> + android:textSize="?attr/TextSizeBody" + android:layout_marginBottom="4dp" + android:layout_marginTop="4dp" /> + android:textStyle="italic" + android:layout_marginBottom="4dp" /> + +