feat: don't show notifications on HomeActivity.kt

This commit is contained in:
jubb 2021-07-13 16:31:16 +10:00
parent 6b7c7d1d2a
commit 6a2a04e256
4 changed files with 19 additions and 1 deletions

View File

@ -159,6 +159,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), ConversationClickLis
override fun onResume() { override fun onResume() {
super.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 if (TextSecurePreferences.getLocalNumber(this) == null) { return; } // This can be the case after a secondary device is auto-cleared
IdentityKeyUtil.checkUpdate(this) IdentityKeyUtil.checkUpdate(this)
profileButton.recycle() // clear cached image before update tje profilePictureView 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?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
if (resultCode == CreateClosedGroupActivity.closedGroupCreatedResultCode) { if (resultCode == CreateClosedGroupActivity.closedGroupCreatedResultCode) {

View File

@ -96,6 +96,7 @@ public class DefaultMessageNotifier implements MessageNotifier {
private static final long DESKTOP_ACTIVITY_PERIOD = TimeUnit.MINUTES.toMillis(1); private static final long DESKTOP_ACTIVITY_PERIOD = TimeUnit.MINUTES.toMillis(1);
private volatile static long visibleThread = -1; private volatile static long visibleThread = -1;
private volatile static boolean homeScreenVisible = false;
private volatile static long lastDesktopActivityTimestamp = -1; private volatile static long lastDesktopActivityTimestamp = -1;
private volatile static long lastAudibleNotification = -1; private volatile static long lastAudibleNotification = -1;
private static final CancelableExecutor executor = new CancelableExecutor(); private static final CancelableExecutor executor = new CancelableExecutor();
@ -105,6 +106,11 @@ public class DefaultMessageNotifier implements MessageNotifier {
visibleThread = threadId; visibleThread = threadId;
} }
@Override
public void setHomeScreenVisible(boolean isVisible) {
homeScreenVisible = isVisible;
}
@Override @Override
public void setLastDesktopActivityTimestamp(long timestamp) { public void setLastDesktopActivityTimestamp(long timestamp) {
lastDesktopActivityTimestamp = timestamp; lastDesktopActivityTimestamp = timestamp;
@ -234,7 +240,7 @@ public class DefaultMessageNotifier implements MessageNotifier {
if (isVisible) { if (isVisible) {
sendInThreadNotification(context, threads.getRecipientForThreadId(threadId)); sendInThreadNotification(context, threads.getRecipientForThreadId(threadId));
} else { } else if (!homeScreenVisible) {
updateNotification(context, signal, 0); updateNotification(context, signal, 0);
} }
} }

View File

@ -29,6 +29,11 @@ public class OptimizedMessageNotifier implements MessageNotifier {
@Override @Override
public void setVisibleThread(long threadId) { wrapped.setVisibleThread(threadId); } public void setVisibleThread(long threadId) { wrapped.setVisibleThread(threadId); }
@Override
public void setHomeScreenVisible(boolean isVisible) {
wrapped.setHomeScreenVisible(isVisible);
}
@Override @Override
public void setLastDesktopActivityTimestamp(long timestamp) { wrapped.setLastDesktopActivityTimestamp(timestamp);} public void setLastDesktopActivityTimestamp(long timestamp) { wrapped.setLastDesktopActivityTimestamp(timestamp);}

View File

@ -4,6 +4,7 @@ import android.content.Context
import org.session.libsession.utilities.recipients.Recipient import org.session.libsession.utilities.recipients.Recipient
interface MessageNotifier { interface MessageNotifier {
fun setHomeScreenVisible(isVisible: Boolean)
fun setVisibleThread(threadId: Long) fun setVisibleThread(threadId: Long)
fun setLastDesktopActivityTimestamp(timestamp: Long) fun setLastDesktopActivityTimestamp(timestamp: Long)
fun notifyMessageDeliveryFailed(context: Context?, recipient: Recipient?, threadId: Long) fun notifyMessageDeliveryFailed(context: Context?, recipient: Recipient?, threadId: Long)