Skip to content

Commit

Permalink
Merge pull request #7723 from vector-im/feature/bma/disableNightlyPopup
Browse files Browse the repository at this point in the history
Disable nightly popup
  • Loading branch information
bmarty authored Dec 7, 2022
2 parents 0344030 + c9c5483 commit d0b1a7b
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog.d/7723.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disable nightly popup and add an entry point in the advanced settings instead.
3 changes: 3 additions & 0 deletions library/ui-strings/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion vector-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ dependencies {
// API-only library
gplayImplementation libs.google.appdistributionApi
// Full SDK implementation
gplayImplementation libs.google.appdistribution
nightlyImplementation libs.google.appdistribution

// OSS License, gplay flavor only
gplayImplementation 'com.google.android.gms:play-services-oss-licenses:17.0.0'
Expand Down
6 changes: 3 additions & 3 deletions vector-app/src/fdroid/java/im/vector/app/di/FlavorModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ abstract class FlavorModule {

@Provides
fun provideNightlyProxy() = object : NightlyProxy {
override fun onHomeResumed() {
// no op
}
override fun canDisplayPopup() = false
override fun isNightlyBuild() = false
override fun updateApplication() = Unit
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -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.
Expand All @@ -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)
Expand All @@ -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"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,9 @@ class HomeActivity :
serverBackupStatusViewModel.refreshRemoteStateIfNeeded()

// Check nightly
nightlyProxy.onHomeResumed()
if (nightlyProxy.canDisplayPopup()) {
nightlyProxy.updateApplication()
}

checkNewAppLayoutFlagChange()
}
Expand Down
15 changes: 14 additions & 1 deletion vector/src/main/java/im/vector/app/features/home/NightlyProxy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand All @@ -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?) {
Expand All @@ -57,6 +62,11 @@ class VectorSettingsAdvancedSettingsFragment :
}

override fun bindPref() {
setupRageShakeSection()
setupNightlySection()
}

private fun setupRageShakeSection() {
val isRageShakeAvailable = RageShake.isAvailable(requireContext())

if (isRageShakeAvailable) {
Expand Down Expand Up @@ -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
}
}
}
12 changes: 12 additions & 0 deletions vector/src/main/res/xml/vector_settings_advanced_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit d0b1a7b

Please sign in to comment.