mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 18:35:40 +03:00
Merge pull request #6643 from vector-im/feature/bma/fix_firebase_popup
Feature/bma/fix firebase popup
This commit is contained in:
commit
f37034c18e
3 changed files with 33 additions and 6 deletions
|
@ -19,5 +19,5 @@ package im.vector.app.nightly
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class NightlyProxy @Inject constructor() {
|
class NightlyProxy @Inject constructor() {
|
||||||
fun updateIfNewReleaseAvailable() = Unit
|
fun onHomeResumed() = Unit
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,13 +16,23 @@
|
||||||
|
|
||||||
package im.vector.app.nightly
|
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.FirebaseAppDistribution
|
||||||
import com.google.firebase.appdistribution.FirebaseAppDistributionException
|
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 timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class NightlyProxy @Inject constructor() {
|
class NightlyProxy @Inject constructor(
|
||||||
fun updateIfNewReleaseAvailable() {
|
private val clock: Clock,
|
||||||
|
@DefaultPreferences
|
||||||
|
private val sharedPreferences: SharedPreferences,
|
||||||
|
) {
|
||||||
|
fun onHomeResumed() {
|
||||||
|
if (!canDisplayPopup()) return
|
||||||
val firebaseAppDistribution = FirebaseAppDistribution.getInstance()
|
val firebaseAppDistribution = FirebaseAppDistribution.getInstance()
|
||||||
firebaseAppDistribution.updateIfNewReleaseAvailable()
|
firebaseAppDistribution.updateIfNewReleaseAvailable()
|
||||||
.addOnProgressListener { up ->
|
.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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -549,9 +549,7 @@ class HomeActivity :
|
||||||
serverBackupStatusViewModel.refreshRemoteStateIfNeeded()
|
serverBackupStatusViewModel.refreshRemoteStateIfNeeded()
|
||||||
|
|
||||||
// Check nightly
|
// Check nightly
|
||||||
if (isFirstCreation()) {
|
nightlyProxy.onHomeResumed()
|
||||||
nightlyProxy.updateIfNewReleaseAvailable()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getMenuRes() = R.menu.home
|
override fun getMenuRes() = R.menu.home
|
||||||
|
|
Loading…
Reference in a new issue