Merge pull request #6643 from vector-im/feature/bma/fix_firebase_popup
Feature/bma/fix firebase popup
This commit is contained in:
		
						commit
						f37034c18e
					
				| @ -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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user