From af6dc75738f30fa741da9cfed5875c35f9a0421d Mon Sep 17 00:00:00 2001 From: Fabian Devel Date: Tue, 5 Dec 2023 15:37:16 +0100 Subject: [PATCH] Add onUpdateInstalled --- .../com.infomaniak.lib.stores/StoreUtils.kt | 2 +- .../com.infomaniak.lib.stores/StoreUtils.kt | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Stores/src/fdroid/java/com.infomaniak.lib.stores/StoreUtils.kt b/Stores/src/fdroid/java/com.infomaniak.lib.stores/StoreUtils.kt index 414cc2ba..6553b1cc 100644 --- a/Stores/src/fdroid/java/com.infomaniak.lib.stores/StoreUtils.kt +++ b/Stores/src/fdroid/java/com.infomaniak.lib.stores/StoreUtils.kt @@ -37,7 +37,7 @@ object StoreUtils { //endRegion //region In-App Update - fun initAppUpdateManager(context: Context, onInstall: () -> Unit) = Unit + fun initAppUpdateManager(context: Context, onUpdateDownloaded: () -> Unit, onUpdateInstalled: () -> Unit) = Unit fun FragmentActivity.checkUpdateIsAvailable( appId: String, diff --git a/Stores/src/standard/java/com.infomaniak.lib.stores/StoreUtils.kt b/Stores/src/standard/java/com.infomaniak.lib.stores/StoreUtils.kt index 42d6722f..17b3fdbe 100644 --- a/Stores/src/standard/java/com.infomaniak.lib.stores/StoreUtils.kt +++ b/Stores/src/standard/java/com.infomaniak.lib.stores/StoreUtils.kt @@ -36,14 +36,18 @@ object StoreUtils { private const val UPDATE_TYPE = AppUpdateType.FLEXIBLE private lateinit var appUpdateManager: AppUpdateManager - private lateinit var onInstallDownloaded: () -> Unit + private lateinit var onUpdateDownloaded: () -> Unit + private lateinit var onUpdateInstalled: () -> Unit // Create a listener to track request state updates. private val installStateUpdatedListener by lazy { InstallStateUpdatedListener { state -> when (state.installStatus()) { - InstallStatus.DOWNLOADED -> onInstallDownloaded() - InstallStatus.INSTALLED -> unregisterAppUpdateListener() + InstallStatus.DOWNLOADED -> onUpdateDownloaded() + InstallStatus.INSTALLED -> { + onUpdateInstalled() + unregisterAppUpdateListener() + } else -> Unit } } @@ -62,9 +66,10 @@ object StoreUtils { //endRegion //region In-App Update - fun initAppUpdateManager(context: Context, onInstall: () -> Unit) { + fun initAppUpdateManager(context: Context, onUpdateDownloaded: () -> Unit, onUpdateInstalled: () -> Unit) { appUpdateManager = AppUpdateManagerFactory.create(context) - onInstallDownloaded = onInstall + this.onUpdateDownloaded = onUpdateDownloaded + this.onUpdateInstalled = onUpdateInstalled } fun FragmentActivity.checkUpdateIsAvailable( @@ -87,7 +92,7 @@ object StoreUtils { appUpdateInfo.addOnSuccessListener { appUpdateInfo -> if (appUpdateInfo.installStatus() == InstallStatus.DOWNLOADED) { // If the update is downloaded but not installed, notify the user to complete the update. - onInstallDownloaded.invoke() + onUpdateDownloaded.invoke() } } }