mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 09:25:49 +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
|
||||
|
||||
class NightlyProxy @Inject constructor() {
|
||||
fun updateIfNewReleaseAvailable() = Unit
|
||||
fun onHomeResumed() = Unit
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -549,9 +549,7 @@ class HomeActivity :
|
|||
serverBackupStatusViewModel.refreshRemoteStateIfNeeded()
|
||||
|
||||
// Check nightly
|
||||
if (isFirstCreation()) {
|
||||
nightlyProxy.updateIfNewReleaseAvailable()
|
||||
}
|
||||
nightlyProxy.onHomeResumed()
|
||||
}
|
||||
|
||||
override fun getMenuRes() = R.menu.home
|
||||
|
|
Loading…
Reference in a new issue