Skip to content

Commit d0b1a7b

Browse files
authored
Merge pull request #7723 from vector-im/feature/bma/disableNightlyPopup
Disable nightly popup
2 parents 0344030 + c9c5483 commit d0b1a7b

File tree

9 files changed

+72
-10
lines changed

9 files changed

+72
-10
lines changed

changelog.d/7723.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Disable nightly popup and add an entry point in the advanced settings instead.

library/ui-strings/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,6 +2487,9 @@
24872487
<string name="settings_key_requests">Key Requests</string>
24882488
<string name="settings_export_trail">Export Audit</string>
24892489

2490+
<string name="settings_nightly_build">Nightly build</string>
2491+
<string name="settings_nightly_build_update">Get the latest build (note: you may have trouble to sign in)</string>
2492+
24902493
<string name="e2e_use_keybackup">Unlock encrypted messages history</string>
24912494

24922495
<string name="refresh">Refresh</string>

vector-app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ dependencies {
374374
// API-only library
375375
gplayImplementation libs.google.appdistributionApi
376376
// Full SDK implementation
377-
gplayImplementation libs.google.appdistribution
377+
nightlyImplementation libs.google.appdistribution
378378

379379
// OSS License, gplay flavor only
380380
gplayImplementation 'com.google.android.gms:play-services-oss-licenses:17.0.0'

vector-app/src/fdroid/java/im/vector/app/di/FlavorModule.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ abstract class FlavorModule {
4646

4747
@Provides
4848
fun provideNightlyProxy() = object : NightlyProxy {
49-
override fun onHomeResumed() {
50-
// no op
51-
}
49+
override fun canDisplayPopup() = false
50+
override fun isNightlyBuild() = false
51+
override fun updateApplication() = Unit
5252
}
5353

5454
@Provides

vector-app/src/gplay/java/im/vector/app/nightly/FirebaseNightlyProxy.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ class FirebaseNightlyProxy @Inject constructor(
3434
private val buildMeta: BuildMeta,
3535
) : NightlyProxy {
3636

37-
override fun onHomeResumed() {
38-
if (!canDisplayPopup()) return
37+
override fun isNightlyBuild(): Boolean {
38+
return buildMeta.applicationId in nightlyPackages
39+
}
40+
41+
override fun updateApplication() {
3942
val firebaseAppDistribution = FirebaseAppDistribution.getInstance()
4043
firebaseAppDistribution.updateIfNewReleaseAvailable()
4144
.addOnProgressListener { up ->
@@ -46,6 +49,7 @@ class FirebaseNightlyProxy @Inject constructor(
4649
when (e.errorCode) {
4750
FirebaseAppDistributionException.Status.NOT_IMPLEMENTED -> {
4851
// SDK did nothing. This is expected when building for Play.
52+
Timber.d("FirebaseAppDistribution NOT_IMPLEMENTED error")
4953
}
5054
else -> {
5155
// Handle other errors.
@@ -56,10 +60,14 @@ class FirebaseNightlyProxy @Inject constructor(
5660
Timber.e(e, "FirebaseAppDistribution - other error")
5761
}
5862
}
63+
.addOnSuccessListener {
64+
Timber.d("FirebaseAppDistribution Success!")
65+
}
5966
}
6067

61-
private fun canDisplayPopup(): Boolean {
62-
if (buildMeta.applicationId != "im.vector.app.nightly") return false
68+
override fun canDisplayPopup(): Boolean {
69+
if (!POPUP_IS_ENABLED) return false
70+
if (!isNightlyBuild()) return false
6371
val today = clock.epochMillis() / A_DAY_IN_MILLIS
6472
val lastDisplayPopupDay = sharedPreferences.getLong(SHARED_PREF_KEY, 0)
6573
return (today > lastDisplayPopupDay)
@@ -73,7 +81,12 @@ class FirebaseNightlyProxy @Inject constructor(
7381
}
7482

7583
companion object {
84+
private const val POPUP_IS_ENABLED = false
7685
private const val A_DAY_IN_MILLIS = 8_600_000L
7786
private const val SHARED_PREF_KEY = "LAST_NIGHTLY_POPUP_DAY"
87+
88+
private val nightlyPackages = listOf(
89+
"im.vector.app.nightly"
90+
)
7891
}
7992
}

vector/src/main/java/im/vector/app/features/home/HomeActivity.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,9 @@ class HomeActivity :
580580
serverBackupStatusViewModel.refreshRemoteStateIfNeeded()
581581

582582
// Check nightly
583-
nightlyProxy.onHomeResumed()
583+
if (nightlyProxy.canDisplayPopup()) {
584+
nightlyProxy.updateApplication()
585+
}
584586

585587
checkNewAppLayoutFlagChange()
586588
}

vector/src/main/java/im/vector/app/features/home/NightlyProxy.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,18 @@
1717
package im.vector.app.features.home
1818

1919
interface NightlyProxy {
20-
fun onHomeResumed()
20+
/**
21+
* Return true if this is a nightly build (checking the package of the app), and only once a day.
22+
*/
23+
fun canDisplayPopup(): Boolean
24+
25+
/**
26+
* Return true if this is a nightly build (checking the package of the app).
27+
*/
28+
fun isNightlyBuild(): Boolean
29+
30+
/**
31+
* Try to update the application, if update is available. Will also take care of the user sign in.
32+
*/
33+
fun updateApplication()
2134
}

vector/src/main/java/im/vector/app/features/settings/VectorSettingsAdvancedSettingsFragment.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ import androidx.preference.SeekBarPreference
2222
import dagger.hilt.android.AndroidEntryPoint
2323
import im.vector.app.R
2424
import im.vector.app.core.platform.VectorBaseActivity
25+
import im.vector.app.core.preference.VectorPreference
2526
import im.vector.app.core.preference.VectorPreferenceCategory
2627
import im.vector.app.core.preference.VectorSwitchPreference
2728
import im.vector.app.features.analytics.plan.MobileScreen
29+
import im.vector.app.features.home.NightlyProxy
2830
import im.vector.app.features.rageshake.RageShake
31+
import javax.inject.Inject
2932

3033
@AndroidEntryPoint
3134
class VectorSettingsAdvancedSettingsFragment :
@@ -34,6 +37,8 @@ class VectorSettingsAdvancedSettingsFragment :
3437
override var titleRes = R.string.settings_advanced_settings
3538
override val preferenceXmlRes = R.xml.vector_settings_advanced_settings
3639

40+
@Inject lateinit var nightlyProxy: NightlyProxy
41+
3742
private var rageshake: RageShake? = null
3843

3944
override fun onCreate(savedInstanceState: Bundle?) {
@@ -57,6 +62,11 @@ class VectorSettingsAdvancedSettingsFragment :
5762
}
5863

5964
override fun bindPref() {
65+
setupRageShakeSection()
66+
setupNightlySection()
67+
}
68+
69+
private fun setupRageShakeSection() {
6070
val isRageShakeAvailable = RageShake.isAvailable(requireContext())
6171

6272
if (isRageShakeAvailable) {
@@ -86,4 +96,12 @@ class VectorSettingsAdvancedSettingsFragment :
8696
findPreference<VectorPreferenceCategory>("SETTINGS_RAGE_SHAKE_CATEGORY_KEY")!!.isVisible = false
8797
}
8898
}
99+
100+
private fun setupNightlySection() {
101+
findPreference<VectorPreferenceCategory>("SETTINGS_NIGHTLY_BUILD_PREFERENCE_KEY")?.isVisible = nightlyProxy.isNightlyBuild()
102+
findPreference<VectorPreference>("SETTINGS_NIGHTLY_BUILD_UPDATE_PREFERENCE_KEY")?.setOnPreferenceClickListener {
103+
nightlyProxy.updateApplication()
104+
true
105+
}
106+
}
89107
}

vector/src/main/res/xml/vector_settings_advanced_settings.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,16 @@
9595

9696
</im.vector.app.core.preference.VectorPreferenceCategory>
9797

98+
<im.vector.app.core.preference.VectorPreferenceCategory
99+
android:key="SETTINGS_NIGHTLY_BUILD_PREFERENCE_KEY"
100+
android:title="@string/settings_nightly_build"
101+
app:isPreferenceVisible="true">
102+
103+
<im.vector.app.core.preference.VectorPreference
104+
android:key="SETTINGS_NIGHTLY_BUILD_UPDATE_PREFERENCE_KEY"
105+
android:persistent="false"
106+
android:title="@string/settings_nightly_build_update" />
107+
108+
</im.vector.app.core.preference.VectorPreferenceCategory>
109+
98110
</androidx.preference.PreferenceScreen>

0 commit comments

Comments
 (0)