Disable the Nightly popup, user registration (with `updateIfNewReleaseAvailable()`) to get upgrade does not work.

Add a nightly build section in the preferences to manually try to upgrade.
This commit is contained in:
Benoit Marty 2022-12-06 12:21:07 +01:00 committed by Benoit Marty
parent a65e13970d
commit 0d12dbbe7e
6 changed files with 67 additions and 6 deletions

View File

@ -2487,6 +2487,9 @@
<string name="settings_key_requests">Key Requests</string>
<string name="settings_export_trail">Export Audit</string>
<string name="settings_nightly_build">Nightly build</string>
<string name="settings_nightly_build_update">Get the latest build (note: you may have trouble to sign in)</string>
<string name="e2e_use_keybackup">Unlock encrypted messages history</string>
<string name="refresh">Refresh</string>

View File

@ -34,8 +34,11 @@ class FirebaseNightlyProxy @Inject constructor(
private val buildMeta: BuildMeta,
) : NightlyProxy {
override fun onHomeResumed() {
if (!canDisplayPopup()) return
override fun isNightlyBuild(): Boolean {
return buildMeta.applicationId in nightlyPackages
}
override fun updateApplication() {
val firebaseAppDistribution = FirebaseAppDistribution.getInstance()
firebaseAppDistribution.updateIfNewReleaseAvailable()
.addOnProgressListener { up ->
@ -46,6 +49,7 @@ class FirebaseNightlyProxy @Inject constructor(
when (e.errorCode) {
FirebaseAppDistributionException.Status.NOT_IMPLEMENTED -> {
// SDK did nothing. This is expected when building for Play.
Timber.d("FirebaseAppDistribution NOT_IMPLEMENTED error")
}
else -> {
// Handle other errors.
@ -56,10 +60,14 @@ class FirebaseNightlyProxy @Inject constructor(
Timber.e(e, "FirebaseAppDistribution - other error")
}
}
.addOnSuccessListener {
Timber.d("FirebaseAppDistribution Success!")
}
}
private fun canDisplayPopup(): Boolean {
if (buildMeta.applicationId != "im.vector.app.nightly") return false
override fun canDisplayPopup(): Boolean {
if (!POPUP_IS_ENABLED) return false
if (!isNightlyBuild()) return false
val today = clock.epochMillis() / A_DAY_IN_MILLIS
val lastDisplayPopupDay = sharedPreferences.getLong(SHARED_PREF_KEY, 0)
return (today > lastDisplayPopupDay)
@ -73,7 +81,12 @@ class FirebaseNightlyProxy @Inject constructor(
}
companion object {
private const val POPUP_IS_ENABLED = false
private const val A_DAY_IN_MILLIS = 8_600_000L
private const val SHARED_PREF_KEY = "LAST_NIGHTLY_POPUP_DAY"
private val nightlyPackages = listOf(
"im.vector.app.nightly"
)
}
}

View File

@ -580,7 +580,9 @@ class HomeActivity :
serverBackupStatusViewModel.refreshRemoteStateIfNeeded()
// Check nightly
nightlyProxy.onHomeResumed()
if (nightlyProxy.canDisplayPopup()) {
nightlyProxy.updateApplication()
}
checkNewAppLayoutFlagChange()
}

View File

@ -17,5 +17,18 @@
package im.vector.app.features.home
interface NightlyProxy {
fun onHomeResumed()
/**
* Return true if this is a nightly build (checking the package of the app), and only once a day.
*/
fun canDisplayPopup(): Boolean
/**
* Return true if this is a nightly build (checking the package of the app).
*/
fun isNightlyBuild(): Boolean
/**
* Try to update the application, if update is available. Will also take care of the user sign in.
*/
fun updateApplication()
}

View File

@ -22,10 +22,13 @@ import androidx.preference.SeekBarPreference
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.core.preference.VectorPreference
import im.vector.app.core.preference.VectorPreferenceCategory
import im.vector.app.core.preference.VectorSwitchPreference
import im.vector.app.features.analytics.plan.MobileScreen
import im.vector.app.features.home.NightlyProxy
import im.vector.app.features.rageshake.RageShake
import javax.inject.Inject
@AndroidEntryPoint
class VectorSettingsAdvancedSettingsFragment :
@ -34,6 +37,8 @@ class VectorSettingsAdvancedSettingsFragment :
override var titleRes = R.string.settings_advanced_settings
override val preferenceXmlRes = R.xml.vector_settings_advanced_settings
@Inject lateinit var nightlyProxy: NightlyProxy
private var rageshake: RageShake? = null
override fun onCreate(savedInstanceState: Bundle?) {
@ -57,6 +62,11 @@ class VectorSettingsAdvancedSettingsFragment :
}
override fun bindPref() {
setupRageShakeSection()
setupNightlySection()
}
private fun setupRageShakeSection() {
val isRageShakeAvailable = RageShake.isAvailable(requireContext())
if (isRageShakeAvailable) {
@ -86,4 +96,12 @@ class VectorSettingsAdvancedSettingsFragment :
findPreference<VectorPreferenceCategory>("SETTINGS_RAGE_SHAKE_CATEGORY_KEY")!!.isVisible = false
}
}
private fun setupNightlySection() {
findPreference<VectorPreferenceCategory>("SETTINGS_NIGHTLY_BUILD_PREFERENCE_KEY")?.isVisible = nightlyProxy.isNightlyBuild()
findPreference<VectorPreference>("SETTINGS_NIGHTLY_BUILD_UPDATE_PREFERENCE_KEY")?.setOnPreferenceClickListener {
nightlyProxy.updateApplication()
true
}
}
}

View File

@ -95,4 +95,16 @@
</im.vector.app.core.preference.VectorPreferenceCategory>
<im.vector.app.core.preference.VectorPreferenceCategory
android:key="SETTINGS_NIGHTLY_BUILD_PREFERENCE_KEY"
android:title="@string/settings_nightly_build"
app:isPreferenceVisible="true">
<im.vector.app.core.preference.VectorPreference
android:key="SETTINGS_NIGHTLY_BUILD_UPDATE_PREFERENCE_KEY"
android:persistent="false"
android:title="@string/settings_nightly_build_update" />
</im.vector.app.core.preference.VectorPreferenceCategory>
</androidx.preference.PreferenceScreen>