From 83f322980502b707adab3917a7b75de639b22ca8 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 22 Jul 2022 16:52:05 +0200 Subject: [PATCH 1/2] Add in-app alert to let user know if a new version is available. --- dependencies.gradle | 5 +- vector/build.gradle | 6 +++ .../im/vector/app/nightly/NightlyProxy.kt | 25 ++++++++++ .../im/vector/app/nightly/NightlyProxy.kt | 47 +++++++++++++++++++ .../vector/app/features/home/HomeActivity.kt | 5 ++ 5 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 vector/src/fdroid/java/im/vector/app/nightly/NightlyProxy.kt create mode 100644 vector/src/gplay/java/im/vector/app/nightly/NightlyProxy.kt diff --git a/dependencies.gradle b/dependencies.gradle index 97b4ad2ea3..44e62f7ae4 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -15,6 +15,7 @@ def gradle = "7.1.3" def kotlin = "1.6.21" def kotlinCoroutines = "1.6.4" def dagger = "2.42" +def appDistribution = "16.0.0-beta03" def retrofit = "2.9.0" def arrow = "0.8.2" def markwon = "4.6.2" @@ -83,7 +84,9 @@ ext.libs = [ 'transition' : "androidx.transition:transition:1.2.0", ], google : [ - 'material' : "com.google.android.material:material:1.6.1" + 'material' : "com.google.android.material:material:1.6.1", + 'appdistributionApi' : "com.google.firebase:firebase-appdistribution-api-ktx:$appDistribution", + 'appdistribution' : "com.google.firebase:firebase-appdistribution:$appDistribution", ], dagger : [ 'dagger' : "com.google.dagger:dagger:$dagger", diff --git a/vector/build.gradle b/vector/build.gradle index e4313770c4..0f65da4c2e 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -449,6 +449,12 @@ dependencies { implementation libs.airbnb.epoxyPaging implementation libs.airbnb.mavericks + // Nightly + // API-only library + gplayImplementation libs.google.appdistributionApi + // Full SDK implementation + gplayImplementation libs.google.appdistribution + // Work implementation libs.androidx.work diff --git a/vector/src/fdroid/java/im/vector/app/nightly/NightlyProxy.kt b/vector/src/fdroid/java/im/vector/app/nightly/NightlyProxy.kt new file mode 100644 index 0000000000..3683a86c50 --- /dev/null +++ b/vector/src/fdroid/java/im/vector/app/nightly/NightlyProxy.kt @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.nightly + +import javax.inject.Inject + +class NightlyProxy @Inject constructor() { + fun updateIfNewReleaseAvailable() { + // No op + } +} diff --git a/vector/src/gplay/java/im/vector/app/nightly/NightlyProxy.kt b/vector/src/gplay/java/im/vector/app/nightly/NightlyProxy.kt new file mode 100644 index 0000000000..73262e21a9 --- /dev/null +++ b/vector/src/gplay/java/im/vector/app/nightly/NightlyProxy.kt @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.nightly + +import com.google.firebase.appdistribution.FirebaseAppDistribution +import com.google.firebase.appdistribution.FirebaseAppDistributionException +import timber.log.Timber +import javax.inject.Inject + +class NightlyProxy @Inject constructor() { + fun updateIfNewReleaseAvailable() { + val firebaseAppDistribution = FirebaseAppDistribution.getInstance() + firebaseAppDistribution.updateIfNewReleaseAvailable() + .addOnProgressListener { up -> + Timber.d("FirebaseAppDistribution progress: ${up.updateStatus}. ${up.apkBytesDownloaded}/${up.apkFileTotalBytes}") + } + .addOnFailureListener { e -> + if (e is FirebaseAppDistributionException) { + when (e.errorCode) { + FirebaseAppDistributionException.Status.NOT_IMPLEMENTED -> { + // SDK did nothing. This is expected when building for Play. + } + else -> { + // Handle other errors. + Timber.e(e, "FirebaseAppDistribution error, status: ${e.errorCode}") + } + } + } else { + Timber.e(e, "FirebaseAppDistribution - other error") + } + } + } +} diff --git a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt index ff114e4db9..f1848e653f 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt @@ -78,6 +78,7 @@ import im.vector.app.features.spaces.invite.SpaceInviteBottomSheet import im.vector.app.features.spaces.share.ShareSpaceBottomSheet import im.vector.app.features.themes.ThemeUtils import im.vector.app.features.workers.signout.ServerBackupStatusViewModel +import im.vector.app.nightly.NightlyProxy import im.vector.app.push.fcm.FcmHelper import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -132,6 +133,7 @@ class HomeActivity : @Inject lateinit var appStateHandler: AppStateHandler @Inject lateinit var unifiedPushHelper: UnifiedPushHelper @Inject lateinit var fcmHelper: FcmHelper + @Inject lateinit var nightlyProxy: NightlyProxy private val createSpaceResultLauncher = registerStartForActivityResult { activityResult -> if (activityResult.resultCode == Activity.RESULT_OK) { @@ -533,6 +535,9 @@ class HomeActivity : // Force remote backup state update to update the banner if needed serverBackupStatusViewModel.refreshRemoteStateIfNeeded() + + // Check nightly + nightlyProxy.updateIfNewReleaseAvailable() } override fun getMenuRes() = R.menu.home From 4dd5fa7051b373d1a622c6158723fd370d0f8749 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 25 Jul 2022 10:07:52 +0200 Subject: [PATCH 2/2] Shorter code. --- vector/src/fdroid/java/im/vector/app/nightly/NightlyProxy.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/vector/src/fdroid/java/im/vector/app/nightly/NightlyProxy.kt b/vector/src/fdroid/java/im/vector/app/nightly/NightlyProxy.kt index 3683a86c50..40375e5760 100644 --- a/vector/src/fdroid/java/im/vector/app/nightly/NightlyProxy.kt +++ b/vector/src/fdroid/java/im/vector/app/nightly/NightlyProxy.kt @@ -19,7 +19,5 @@ package im.vector.app.nightly import javax.inject.Inject class NightlyProxy @Inject constructor() { - fun updateIfNewReleaseAvailable() { - // No op - } + fun updateIfNewReleaseAvailable() = Unit }