From a3e136b5504641f9782b9d94e35311dad19fbc1d Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 8 Jan 2016 21:30:46 +0100 Subject: [PATCH] show per conference notification settings in details activity --- .../conversations/entities/Conversation.java | 16 ++++- .../services/NotificationService.java | 8 +-- .../ui/ConferenceDetailsActivity.java | 63 ++++++++++++++++++ .../ui/adapter/ConversationAdapter.java | 5 +- .../ic_notifications_none_grey600_24dp.png | Bin 0 -> 427 bytes .../ic_notifications_none_grey600_24dp.png | Bin 0 -> 318 bytes .../ic_notifications_none_grey600_24dp.png | Bin 0 -> 471 bytes .../ic_notifications_none_grey600_24dp.png | Bin 0 -> 657 bytes .../ic_notifications_none_grey600_24dp.png | Bin 0 -> 962 bytes src/main/res/layout/activity_muc_details.xml | 27 ++++++++ src/main/res/values/strings.xml | 6 +- src/main/res/xml/preferences.xml | 6 -- 12 files changed, 114 insertions(+), 17 deletions(-) create mode 100644 src/main/res/drawable-hdpi/ic_notifications_none_grey600_24dp.png create mode 100644 src/main/res/drawable-mdpi/ic_notifications_none_grey600_24dp.png create mode 100644 src/main/res/drawable-xhdpi/ic_notifications_none_grey600_24dp.png create mode 100644 src/main/res/drawable-xxhdpi/ic_notifications_none_grey600_24dp.png create mode 100644 src/main/res/drawable-xxxhdpi/ic_notifications_none_grey600_24dp.png diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index f34641ab..43012976 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -47,6 +47,7 @@ public class Conversation extends AbstractEntity implements Blockable { public static final String ATTRIBUTE_NEXT_ENCRYPTION = "next_encryption"; public static final String ATTRIBUTE_MUC_PASSWORD = "muc_password"; public static final String ATTRIBUTE_MUTED_TILL = "muted_till"; + public static final String ATTRIBUTE_ALWAYS_NOTIFY = "always_notify"; private String name; private String contactUuid; @@ -546,7 +547,7 @@ public class Conversation extends AbstractEntity implements Blockable { /** * short for is Private and Non-anonymous */ - public boolean isPnNA() { + private boolean isPnNA() { return mode == MODE_SINGLE || (getMucOptions().membersOnly() && getMucOptions().nonanonymous()); } @@ -729,6 +730,10 @@ public class Conversation extends AbstractEntity implements Blockable { return System.currentTimeMillis() < this.getLongAttribute(ATTRIBUTE_MUTED_TILL, 0); } + public boolean alwaysNotify() { + return mode == MODE_SINGLE || getBooleanAttribute(ATTRIBUTE_ALWAYS_NOTIFY,isPnNA()); + } + public boolean setAttribute(String key, String value) { try { this.attributes.put(key, value); @@ -772,6 +777,15 @@ public class Conversation extends AbstractEntity implements Blockable { } } + public boolean getBooleanAttribute(String key, boolean defaultValue) { + String value = this.getAttribute(key); + if (value == null) { + return defaultValue; + } else { + return Boolean.parseBoolean(value); + } + } + public void add(Message message) { message.setConversation(this); synchronized (this.messages) { diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index 3199b492..752d7bca 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -62,9 +62,7 @@ public class NotificationService { return (message.getStatus() == Message.STATUS_RECEIVED) && notificationsEnabled() && !message.getConversation().isMuted() - && (message.getConversation().isPnNA() - || conferenceNotificationsEnabled() - || wasHighlightedOrPrivate(message) + && (message.getConversation().alwaysNotify() || wasHighlightedOrPrivate(message) ); } @@ -109,10 +107,6 @@ public class NotificationService { } } - public boolean conferenceNotificationsEnabled() { - return mXmppConnectionService.getPreferences().getBoolean("always_notify_in_conference", false); - } - public void pushFromBacklog(final Message message) { if (notify(message)) { synchronized (notifications) { diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index b3de28b3..6653dd24 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -28,6 +28,7 @@ import org.openintents.openpgp.util.OpenPgpUtils; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.concurrent.atomic.AtomicInteger; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; @@ -64,7 +65,9 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers private TextView mConferenceType; private TableLayout mConferenceInfoTable; private TextView mConferenceInfoMam; + private TextView mNotifyStatusText; private ImageButton mChangeConferenceSettingsButton; + private ImageButton mNotifyStatusButton; private Button mInviteButton; private String uuid = null; private User mSelectedUser = null; @@ -99,6 +102,47 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers } }; + + private OnClickListener mNotifyStatusClickListener = new OnClickListener() { + @Override + public void onClick(View v) { + AlertDialog.Builder builder = new AlertDialog.Builder(ConferenceDetailsActivity.this); + builder.setTitle(R.string.pref_notification_settings); + String[] choices = { + getString(R.string.notify_on_all_messages), + getString(R.string.notify_only_when_highlighted), + getString(R.string.notify_never) + }; + final AtomicInteger choice; + if (mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL,0) == Long.MAX_VALUE) { + choice = new AtomicInteger(2); + } else { + choice = new AtomicInteger(mConversation.alwaysNotify() ? 0 : 1); + } + 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() == 2) { + mConversation.setMutedTill(Long.MAX_VALUE); + } else { + mConversation.setMutedTill(0); + mConversation.setAttribute(Conversation.ATTRIBUTE_ALWAYS_NOTIFY,String.valueOf(choice.get() == 0)); + } + xmppConnectionService.updateConversation(mConversation); + updateView(); + } + }); + builder.create().show(); + } + }; + private OnClickListener mChangeConferenceSettings = new OnClickListener() { @Override public void onClick(View v) { @@ -222,6 +266,9 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers this.mConferenceInfoTable = (TableLayout) findViewById(R.id.muc_info_more); mConferenceInfoTable.setVisibility(this.mAdvancedMode ? View.VISIBLE : View.GONE); this.mConferenceInfoMam = (TextView) findViewById(R.id.muc_info_mam); + this.mNotifyStatusButton = (ImageButton) findViewById(R.id.notification_status_button); + this.mNotifyStatusButton.setOnClickListener(this.mNotifyStatusClickListener); + this.mNotifyStatusText = (TextView) findViewById(R.id.notification_status_text); } @Override @@ -493,6 +540,22 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers mChangeConferenceSettingsButton.setVisibility(View.GONE); } } + + 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 if (mConversation.alwaysNotify()) { + mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_grey600_24dp); + mNotifyStatusText.setText(R.string.notify_on_all_messages); + } else { + mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_none_grey600_24dp); + mNotifyStatusText.setText(R.string.notify_only_when_highlighted); + } + LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); membersView.removeAllViews(); final ArrayList users = mucOptions.getUsers(); diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java index 302faaf1..f5f48a26 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java @@ -102,8 +102,11 @@ public class ConversationAdapter extends ArrayAdapter { } else if (muted_till >= System.currentTimeMillis()) { notificationStatus.setVisibility(View.VISIBLE); notificationStatus.setImageResource(R.drawable.ic_notifications_paused_grey600_24dp); - } else { + } else if (conversation.alwaysNotify()) { notificationStatus.setVisibility(View.GONE); + } else { + notificationStatus.setVisibility(View.VISIBLE); + notificationStatus.setImageResource(R.drawable.ic_notifications_none_grey600_24dp); } mTimestamp.setText(UIHelper.readableTimeDifference(activity,conversation.getLatestMessage().getTimeSent())); diff --git a/src/main/res/drawable-hdpi/ic_notifications_none_grey600_24dp.png b/src/main/res/drawable-hdpi/ic_notifications_none_grey600_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..6cd4dfc90b1582732829bfcdcc03fc3f0d0ae90b GIT binary patch literal 427 zcmV;c0aX5pP)004R> z004l5008;`004mK004C`008P>0026e000+ooVrmw00002VoOIv0RM-N%)bBt010qN zS#tmY3ljhU3ljkVnw%H_00AROL_t(Y$73jEpbli9r$LO=Fvzm>PU)}GnWapW8g#St zKNv<(YS4cutf#~vtI|nugRYk5l?sw$kZS23xFIn3sk9h(SYa3T1Zw(^6>cfzB;FvK z((hnRze{J8I+O~PvXsh~rj%ZW8^uJNL42hT!5Z$C>Y#`-m$pESDk9FH2C(86rE*x5 zLyY=}E!fcom`h)Q6-Q$Y3Fgu(VA)*42AP2sKEs(UQo-^&2^*9GR=5afdQpUWoS;Ef zV1;cs4PpVy{~>G;B&Zt*W|~ohMh(JkkV5GLA`NQ5XAsPo|D^|j3UR^z*p0$w46(2Q zyFm>k8iN*62&Mxb@8E*;ulqM5c|)HPg972koF&whAmrpUV4d(#! VJ{2GKeaip<002ovPDHLkV1gXmqf-C? literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-mdpi/ic_notifications_none_grey600_24dp.png b/src/main/res/drawable-mdpi/ic_notifications_none_grey600_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..3e8b0805c273ad36b22e67bf29400bc438c714eb GIT binary patch literal 318 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_*1g=CK)Uj~LMH3o);76yi2K%s^g z3=E|P3=FRl7#OT(FffQ0%-I!a1C(G&@^*J&_}|`tWO=~G=WkLc z&C|s(#NzbbD~4Q$3?$kfhVA+yB>H~A=0(#5zn8D%uxxBjUZ_4nt3sVA3B>jz5p2IQ|~!oVA$0Lh;qc1m8x1MG2-XN}tL;sY?dRpAb~l004R> z004l5008;`004mK004C`008P>0026e000+ooVrmw00002VoOIv0RM-N%)bBt010qN zS#tmY3ljhU3ljkVnw%H_00B=)L_t(o!|m8XO2a@D2HG zxA^x{@CZVvc!#1;bRk7litfc52(F}^xs{sN{cR(BWTKKGPv0ogh;50LQRtd^Q zfHgek#!E004R> z004l5008;`004mK004C`008P>0026e000+ooVrmw00002VoOIv0RM-N%)bBt010qN zS#tmY3ljhU3ljkVnw%H_00Id~L_t(&-tF1XO9DX@2XG}wt2OK1k6Q>4T`TBRK}1I} z>JO0UAbI#kM-M@Dj3go|sO|~<1<|31eo*}bA*gk!E)k^SbckYhU3Es^Iu^sbzBl{X z-M2G4yDqpID_k0+K@9gR9pEf$6;VtQ4LC3K#!_H z1q-O48pMi1A*cgE8&D8_6`%Z=%In zP%rLE1_GGDE?$eW(&(ZGwcw%XFkyIX zGCi0tqTj(w4cfLGVh_GD+3h&6g?9zH#GJpc7Lo`y@bqJaM%N8c-*4+@N8}X>Nh5&5A9%l@ex6^NvRn3<4ZF3}rHszB2vKvSwf9z5G{GH6!ULvuEuklLnRM4rRsgun7T r_>>Le2pQy&!663pW3NFP^cO&12{8B+D>I>q00000NkvXXu0mjfcV__% literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-xxxhdpi/ic_notifications_none_grey600_24dp.png b/src/main/res/drawable-xxxhdpi/ic_notifications_none_grey600_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..ffdb15a83c04be61b0efe6c1089bfcf6ea9c526f GIT binary patch literal 962 zcmV;z13mnSP)004R> z004l5008;`004mK004C`008P>0026e000+ooVrmw00002VoOIv0RM-N%)bBt010qN zS#tmY3ljhU3ljkVnw%H_00TNnL_t(|+U?vqOcg;G!14ckpnyVQGEFX|%*(VGIhqc%hskA!q@HhXfvog`ygT3Fb z&UEuFyZiliW@mOb`v_GN>=H%-BtQZrKmvRRSipH+GtD$ZRFmc=AmqYCwt{xn{!t&M zgz@0CKpJg-r4Ko@k{TR9CE1GDI!*-#aKuE^mw+7AXl`%-DXP%`-2(xi2Ucrt$?`iO zmwIB1YHp7aqmFg{oXEEq`>rk5eBGZ zexd)d(tQ`|>Rz%07FCNVc@sZtiQ$xG+XL zoeVS11dz^ha)?mODvgyx3;XHzb{JhlkLuN*p@{~1HTK#?C5K5;+46;a#=Pr7soYgf zzm;r`X{HZ793_{iYDa3;Y)=;e^=wqczHyQ=Vsq~MmSQUSu842uvR7SbC*2D4CrTMK zHT6AYsSulG2LoQTK!Zy95mV{I07ZOO{4>0lbk%ih*{MyMW`0asQ01N%S-`Lga+IfO4VUWMJUb zDt+X zosIxr7=Ei^8z8Qph8+Qn2=$fj0Tu~$XI_|poZ~DG0u~DO2}b~5g?hSs0CDa1!x6xg zP@m`RYZV_936KB@kN^pg011!)36KB@kN^pg01419wVq{E>jt2f8qWYV<_KY*rEi)L z_FeiW3CWhzkGo7TcsC>!`t9ofE_(^_%pM?-=^G|!0}`FSL4x+T5^?-dLUJaS09Q-0 z)xIZNKmz{xd%#MW()}KK%8lP~INJgrbhp0qe;0b9yY;dE0XK9WK;ks|A26ho + + + + + Also vibrate when a new message arrives Sound Play ringtone with notification - Notifications in Public Conferences - Always notify when a message arrives in a public conference instead of only when highlighted Notification grace period Disable notifications for a short time after a carbon copy was received Advanced Options @@ -570,4 +568,8 @@ SHA1 (Not available) No certificate found + Notify on all messages + Notify only when highlighted + Notifications disabled + Notifications paused diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index 16dc5eb9..34fb7c0a 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -82,12 +82,6 @@ android:summary="@string/pref_sound_summary" android:title="@string/pref_sound"/> -