diff --git a/Core b/Core index 8f180e79ee..5bcd9e5b22 160000 --- a/Core +++ b/Core @@ -1 +1 @@ -Subproject commit 8f180e79eef387b2cfcc0ca0f9ef3c7e187d7d57 +Subproject commit 5bcd9e5b22ce0b7965ade51945925d2045a70012 diff --git a/app/src/main/java/com/infomaniak/mail/ui/MainActivity.kt b/app/src/main/java/com/infomaniak/mail/ui/MainActivity.kt index 6fa51b6002..f9ff186fa4 100644 --- a/app/src/main/java/com/infomaniak/mail/ui/MainActivity.kt +++ b/app/src/main/java/com/infomaniak/mail/ui/MainActivity.kt @@ -42,8 +42,11 @@ import com.infomaniak.lib.core.utils.SentryLog import com.infomaniak.lib.core.utils.Utils import com.infomaniak.lib.core.utils.Utils.toEnumOrThrow import com.infomaniak.lib.core.utils.UtilsUi.openUrl -import com.infomaniak.lib.stores.checkUpdateIsAvailable -import com.infomaniak.lib.stores.launchInAppReview +import com.infomaniak.lib.stores.StoreUtils.checkStalledUpdate +import com.infomaniak.lib.stores.StoreUtils.checkUpdateIsAvailable +import com.infomaniak.lib.stores.StoreUtils.initAppUpdateManager +import com.infomaniak.lib.stores.StoreUtils.launchInAppReview +import com.infomaniak.lib.stores.StoreUtils.unregisterAppUpdateListener import com.infomaniak.mail.BuildConfig import com.infomaniak.mail.MatomoMail.trackDestination import com.infomaniak.mail.MatomoMail.trackEvent @@ -113,6 +116,10 @@ class MainActivity : BaseActivity() { } } + private val inAppUpdateResultLauncher = registerForActivityResult(StartIntentSenderForResult()) { result -> + localSettings.isUserWantingUpdates = result.resultCode == RESULT_OK + } + @Inject lateinit var draftsActionsWorkerScheduler: DraftsActionsWorker.Scheduler @@ -176,6 +183,8 @@ class MainActivity : BaseActivity() { loadCurrentMailbox() permissionUtils.requestMainPermissionsIfNeeded() + + initAppUpdateManager() } private fun observeNetworkStatus() { @@ -318,6 +327,8 @@ class MainActivity : BaseActivity() { super.onResume() playServicesUtils.checkPlayServices(this) + checkStalledUpdate() + if (binding.drawerLayout.isOpen) colorSystemBarsWithMenuDrawer() } @@ -350,6 +361,7 @@ class MainActivity : BaseActivity() { override fun onStop() { descriptionDialog.resetLoadingAndDismiss() + unregisterAppUpdateListener() super.onStop() } @@ -449,11 +461,23 @@ class MainActivity : BaseActivity() { } } + private fun initAppUpdateManager() { + initAppUpdateManager( + context = this, + onInstall = { mainViewModel.canInstallUpdate.value = true }, + ) + } + private fun showUpdateAvailable() = with(localSettings) { if (isUserWantingUpdates || (appLaunches != 0 && appLaunches % 10 == 0)) { - checkUpdateIsAvailable(BuildConfig.APPLICATION_ID, BuildConfig.VERSION_CODE) { updateIsAvailable -> - if (updateIsAvailable) navController.navigate(R.id.updateAvailableBottomSheetDialog) - } + checkUpdateIsAvailable( + appId = BuildConfig.APPLICATION_ID, + versionCode = BuildConfig.VERSION_CODE, + inAppResultLauncher = inAppUpdateResultLauncher, + onFDroidResult = { updateIsAvailable -> + if (updateIsAvailable) navController.navigate(R.id.updateAvailableBottomSheetDialog) + }, + ) } } diff --git a/app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt b/app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt index 9ed9a0c401..f3306cdca8 100644 --- a/app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt +++ b/app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt @@ -97,6 +97,7 @@ class MainViewModel @Inject constructor( val flushFolderTrigger = SingleLiveEvent() val newFolderResultTrigger = MutableLiveData() val reportPhishingTrigger = SingleLiveEvent() + val canInstallUpdate = MutableLiveData(false) val snackBarManager by lazy { SnackBarManager() } diff --git a/app/src/main/java/com/infomaniak/mail/ui/main/folder/ThreadListFragment.kt b/app/src/main/java/com/infomaniak/mail/ui/main/folder/ThreadListFragment.kt index 18e499b421..bda7755767 100644 --- a/app/src/main/java/com/infomaniak/mail/ui/main/folder/ThreadListFragment.kt +++ b/app/src/main/java/com/infomaniak/mail/ui/main/folder/ThreadListFragment.kt @@ -49,6 +49,7 @@ import com.ernestoyaquello.dragdropswiperecyclerview.listener.OnListScrollListen import com.infomaniak.lib.core.MatomoCore.TrackerAction import com.infomaniak.lib.core.utils.* import com.infomaniak.lib.core.utils.Utils +import com.infomaniak.lib.stores.StoreUtils import com.infomaniak.mail.MatomoMail.trackEvent import com.infomaniak.mail.MatomoMail.trackMenuDrawerEvent import com.infomaniak.mail.MatomoMail.trackMultiSelectionEvent @@ -160,6 +161,7 @@ class ThreadListFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener { observeContacts() observerDraftsActionsCompletedWorks() observeFlushFolderTrigger() + observeUpdateInstall() }.getOrDefault(Unit) private fun navigateFromNotificationToNewMessage() { @@ -569,6 +571,23 @@ class ThreadListFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener { mainViewModel.flushFolderTrigger.observe(viewLifecycleOwner) { descriptionDialog.resetLoadingAndDismiss() } } + private fun observeUpdateInstall() = with(binding) { + mainViewModel.canInstallUpdate.observe(viewLifecycleOwner) { isUpdateDownloaded -> + installUpdateGroup.isVisible = isUpdateDownloaded + installUpdate.setOnClickListener { + trackEvent("inAppUpdate", "installUpdate") + mainViewModel.canInstallUpdate.value = false + + StoreUtils.installDownloadedUpdate { + Sentry.captureException(it) + // This avoid the user being instantly reprompted to download update + localSettings.isUserWantingUpdates = false + mainViewModel.snackBarManager.setValue(getString(RCore.string.errorUpdateInstall)) + } + } + } + } + private fun observerDraftsActionsCompletedWorks() { fun observeDraftsActions() { diff --git a/app/src/main/res/drawable/ic_app_update.xml b/app/src/main/res/drawable/ic_app_update.xml new file mode 100644 index 0000000000..43fb1eab01 --- /dev/null +++ b/app/src/main/res/drawable/ic_app_update.xml @@ -0,0 +1,26 @@ + + + + diff --git a/app/src/main/res/layout/fragment_thread_list.xml b/app/src/main/res/layout/fragment_thread_list.xml index a5678bd7e9..ae6510a4d0 100644 --- a/app/src/main/res/layout/fragment_thread_list.xml +++ b/app/src/main/res/layout/fragment_thread_list.xml @@ -193,15 +193,62 @@ android:layout_height="wrap_content" android:nestedScrollingEnabled="true"> - + android:layout_height="match_parent"> + + + + + + + + + + + +