Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable nightly popup #7723

Merged
merged 4 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BillCarsonFr once merged, you may want to add other package(s) to this list.

)
}
}
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>