Merge pull request #657 from hjubb/prevent_notifications_on_home

Don't Show Notifications Banners on Home Screen
This commit is contained in:
Niels Andriesse 2021-07-13 16:41:30 +10:00 committed by GitHub
commit 9c60c2133c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 1 deletions

View File

@ -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) {

View File

@ -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);
}
}

View File

@ -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);}

View File

@ -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)