Merge pull request #6643 from vector-im/feature/bma/fix_firebase_popup

Feature/bma/fix firebase popup
This commit is contained in:
Benoit Marty 2022-07-26 20:15:05 +02:00 committed by GitHub
commit f37034c18e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 6 deletions

View File

@ -19,5 +19,5 @@ package im.vector.app.nightly
import javax.inject.Inject
class NightlyProxy @Inject constructor() {
fun updateIfNewReleaseAvailable() = Unit
fun onHomeResumed() = Unit
}

View File

@ -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"
}
}

View File

@ -549,9 +549,7 @@ class HomeActivity :
serverBackupStatusViewModel.refreshRemoteStateIfNeeded()
// Check nightly
if (isFirstCreation()) {
nightlyProxy.updateIfNewReleaseAvailable()
}
nightlyProxy.onHomeResumed()
}
override fun getMenuRes() = R.menu.home