diff --git a/vector/src/fdroid/java/im/vector/app/nightly/NightlyProxy.kt b/vector/src/fdroid/java/im/vector/app/nightly/NightlyProxy.kt index 40375e5760..eecf3a24f2 100644 --- a/vector/src/fdroid/java/im/vector/app/nightly/NightlyProxy.kt +++ b/vector/src/fdroid/java/im/vector/app/nightly/NightlyProxy.kt @@ -19,5 +19,5 @@ package im.vector.app.nightly import javax.inject.Inject class NightlyProxy @Inject constructor() { - fun updateIfNewReleaseAvailable() = Unit + fun onHomeResumed() = Unit } diff --git a/vector/src/gplay/java/im/vector/app/nightly/NightlyProxy.kt b/vector/src/gplay/java/im/vector/app/nightly/NightlyProxy.kt index 73262e21a9..7c6685f5ce 100644 --- a/vector/src/gplay/java/im/vector/app/nightly/NightlyProxy.kt +++ b/vector/src/gplay/java/im/vector/app/nightly/NightlyProxy.kt @@ -16,13 +16,23 @@ package im.vector.app.nightly +import android.content.SharedPreferences +import androidx.core.content.edit import com.google.firebase.appdistribution.FirebaseAppDistribution import com.google.firebase.appdistribution.FirebaseAppDistributionException +import im.vector.app.BuildConfig +import im.vector.app.core.di.DefaultPreferences +import im.vector.app.core.time.Clock import timber.log.Timber import javax.inject.Inject -class NightlyProxy @Inject constructor() { - fun updateIfNewReleaseAvailable() { +class NightlyProxy @Inject constructor( + private val clock: Clock, + @DefaultPreferences + private val sharedPreferences: SharedPreferences, +) { + fun onHomeResumed() { + if (!canDisplayPopup()) return val firebaseAppDistribution = FirebaseAppDistribution.getInstance() firebaseAppDistribution.updateIfNewReleaseAvailable() .addOnProgressListener { up -> @@ -44,4 +54,23 @@ class NightlyProxy @Inject constructor() { } } } + + private fun canDisplayPopup(): Boolean { + if (BuildConfig.APPLICATION_ID != "im.vector.app.nightly") return false + val today = clock.epochMillis() / A_DAY_IN_MILLIS + val lastDisplayPopupDay = sharedPreferences.getLong(SHARED_PREF_KEY, 0) + return (today > lastDisplayPopupDay) + .also { canDisplayPopup -> + if (canDisplayPopup) { + sharedPreferences.edit { + putLong(SHARED_PREF_KEY, today) + } + } + } + } + + companion object { + private const val A_DAY_IN_MILLIS = 8_600_000L + private const val SHARED_PREF_KEY = "LAST_NIGHTLY_POPUP_DAY" + } } diff --git a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt index e8437eae1a..2d5f94a749 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt @@ -549,9 +549,7 @@ class HomeActivity : serverBackupStatusViewModel.refreshRemoteStateIfNeeded() // Check nightly - if (isFirstCreation()) { - nightlyProxy.updateIfNewReleaseAvailable() - } + nightlyProxy.onHomeResumed() } override fun getMenuRes() = R.menu.home