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 e2227769..262f29ab 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,16 +66,17 @@ 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( appId: String, versionCode: Int, inAppResultLauncher: ActivityResultLauncher?, - onFdroidResult: (updateIsAvailable: Boolean) -> Unit, + onFDroidResult: (updateIsAvailable: Boolean) -> Unit, ) { appUpdateManager.appUpdateInfo.addOnSuccessListener { appUpdateInfo -> if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE @@ -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() } } }