From 6a2a04e2561c5655cd9a60a31b6b2679c9d54317 Mon Sep 17 00:00:00 2001 From: jubb Date: Tue, 13 Jul 2021 16:31:16 +1000 Subject: [PATCH] feat: don't show notifications on HomeActivity.kt --- .../java/org/thoughtcrime/securesms/home/HomeActivity.kt | 6 ++++++ .../securesms/notifications/DefaultMessageNotifier.java | 8 +++++++- .../securesms/notifications/OptimizedMessageNotifier.java | 5 +++++ .../sending_receiving/notifications/MessageNotifier.kt | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt index 608091b05f..6c6fd8e1ed 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt @@ -159,6 +159,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), ConversationClickLis override fun onResume() { super.onResume() + ApplicationContext.getInstance(this).messageNotifier.setHomeScreenVisible(true) if (TextSecurePreferences.getLocalNumber(this) == null) { return; } // This can be the case after a secondary device is auto-cleared IdentityKeyUtil.checkUpdate(this) profileButton.recycle() // clear cached image before update tje profilePictureView @@ -174,6 +175,11 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), ConversationClickLis } } + override fun onPause() { + super.onPause() + ApplicationContext.getInstance(this).messageNotifier.setHomeScreenVisible(false) + } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (resultCode == CreateClosedGroupActivity.closedGroupCreatedResultCode) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java index c5bf55d800..33f25c96b4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/DefaultMessageNotifier.java @@ -96,6 +96,7 @@ public class DefaultMessageNotifier implements MessageNotifier { private static final long DESKTOP_ACTIVITY_PERIOD = TimeUnit.MINUTES.toMillis(1); private volatile static long visibleThread = -1; + private volatile static boolean homeScreenVisible = false; private volatile static long lastDesktopActivityTimestamp = -1; private volatile static long lastAudibleNotification = -1; private static final CancelableExecutor executor = new CancelableExecutor(); @@ -105,6 +106,11 @@ public class DefaultMessageNotifier implements MessageNotifier { visibleThread = threadId; } + @Override + public void setHomeScreenVisible(boolean isVisible) { + homeScreenVisible = isVisible; + } + @Override public void setLastDesktopActivityTimestamp(long timestamp) { lastDesktopActivityTimestamp = timestamp; @@ -234,7 +240,7 @@ public class DefaultMessageNotifier implements MessageNotifier { if (isVisible) { sendInThreadNotification(context, threads.getRecipientForThreadId(threadId)); - } else { + } else if (!homeScreenVisible) { updateNotification(context, signal, 0); } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/OptimizedMessageNotifier.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/OptimizedMessageNotifier.java index 4a72d7757c..5ca700cf66 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/OptimizedMessageNotifier.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/OptimizedMessageNotifier.java @@ -29,6 +29,11 @@ public class OptimizedMessageNotifier implements MessageNotifier { @Override public void setVisibleThread(long threadId) { wrapped.setVisibleThread(threadId); } + @Override + public void setHomeScreenVisible(boolean isVisible) { + wrapped.setHomeScreenVisible(isVisible); + } + @Override public void setLastDesktopActivityTimestamp(long timestamp) { wrapped.setLastDesktopActivityTimestamp(timestamp);} diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/MessageNotifier.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/MessageNotifier.kt index 4f820c4a9b..37480543b7 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/MessageNotifier.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/notifications/MessageNotifier.kt @@ -4,6 +4,7 @@ import android.content.Context import org.session.libsession.utilities.recipients.Recipient interface MessageNotifier { + fun setHomeScreenVisible(isVisible: Boolean) fun setVisibleThread(threadId: Long) fun setLastDesktopActivityTimestamp(timestamp: Long) fun notifyMessageDeliveryFailed(context: Context?, recipient: Recipient?, threadId: Long)