Skip to content

Commit 92ec7e1

Browse files
committed
Implement background time threshold check for modal message display.
1 parent 9a50672 commit 92ec7e1

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

app/src/main/java/com/duckduckgo/app/browser/remotemessage/RemoteMessageModalSurfaceEvaluator.kt

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.duckduckgo.app.browser.remotemessage
1818

1919
import android.content.Context
2020
import android.content.Intent
21+
import android.os.SystemClock
2122
import androidx.lifecycle.LifecycleOwner
2223
import com.duckduckgo.app.cta.db.DismissedCtaDao
2324
import com.duckduckgo.app.cta.model.CtaId
@@ -80,25 +81,46 @@ class RemoteMessageModalSurfaceEvaluatorImpl @Inject constructor(
8081
return@withContext
8182
}
8283

83-
// TODO ANA: This is now called all the time. Update!
84+
if (!hasMetBackgroundTimeThreshold()) {
85+
return@withContext
86+
}
87+
8488
val message = remoteMessagingRepository.message() ?: return@withContext
89+
8590
if (message.surfaces.contains(Surface.MODAL)) {
8691
val intent = globalActivityStarter.startIntent(
8792
applicationContext,
8893
ModalSurfaceActivityFromMessageId(message.id, message.content.messageType),
8994
) ?: return@withContext
9095

91-
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP
92-
applicationContext.startActivity(intent)
96+
withContext(dispatchers.main()) {
97+
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP
98+
applicationContext.startActivity(intent)
99+
}
93100
}
94101
}
95102
}
96103

104+
private fun hasMetBackgroundTimeThreshold(): Boolean {
105+
if (!settingsDataStore.hasBackgroundTimestampRecorded()) {
106+
return false
107+
}
108+
109+
val backgroundTimestamp = settingsDataStore.appBackgroundedTimestamp
110+
// Using elapsed real time as this is how it's saved in the data store.
111+
val currentTimestamp = SystemClock.elapsedRealtime()
112+
return (currentTimestamp - backgroundTimestamp) >= BACKGROUND_THRESHOLD_MILLIS
113+
}
114+
97115
private fun isHomeOnboardingComplete(): Boolean {
98116
val noBrowserCtaExperiment = extendedOnboardingFeatureToggles.noBrowserCtas().isEnabled()
99117
return dismissedCtaDao.exists(CtaId.DAX_END) ||
100118
noBrowserCtaExperiment ||
101119
settingsDataStore.hideTips ||
102120
dismissedCtaDao.exists(CtaId.ADD_WIDGET)
103121
}
122+
123+
companion object {
124+
private const val BACKGROUND_THRESHOLD_MILLIS = 4 * 60 * 60 * 1000L // 4 hours
125+
}
104126
}

0 commit comments

Comments
 (0)