From 946db882aa8c528bacb5c3ac9ab6997b9d9e94c0 Mon Sep 17 00:00:00 2001 From: Fabian Devel Date: Thu, 23 Nov 2023 09:21:01 +0100 Subject: [PATCH] Add support for kDrive --- .../java/com.infomaniak.lib.stores/StoreUtils.kt | 11 +++++++++-- .../java/com.infomaniak.lib.stores/StoreUtils.kt | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 4 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 2797f465..414cc2ba 100644 --- a/Stores/src/fdroid/java/com.infomaniak.lib.stores/StoreUtils.kt +++ b/Stores/src/fdroid/java/com.infomaniak.lib.stores/StoreUtils.kt @@ -29,19 +29,26 @@ import kotlinx.coroutines.withContext object StoreUtils { + //region legacy App update + // TODO: Remove this when Ui for kDrive in app update will be made + fun FragmentActivity.checkUpdateIsAvailable(appId: String, versionCode: Int, onResult: (updateIsAvailable: Boolean) -> Unit) { + checkUpdateIsAvailable(appId = appId, versionCode = versionCode, inAppResultLauncher = null, onFDroidResult = onResult) + } + //endRegion + //region In-App Update fun initAppUpdateManager(context: Context, onInstall: () -> Unit) = Unit fun FragmentActivity.checkUpdateIsAvailable( appId: String, versionCode: Int, - inAppResultLauncher: ActivityResultLauncher, + inAppResultLauncher: ActivityResultLauncher?, onFDroidResult: (updateIsAvailable: Boolean) -> Unit, ) { lifecycleScope.launch { val lastVersionCode = FdroidApiTools().getLastRelease(appId) - withContext(Dispatchers.Main) { onResult(versionCode < lastVersionCode) } + withContext(Dispatchers.Main) { onFDroidResult(versionCode < lastVersionCode) } } } 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 0bd1d8ba..93a95828 100644 --- a/Stores/src/standard/java/com.infomaniak.lib.stores/StoreUtils.kt +++ b/Stores/src/standard/java/com.infomaniak.lib.stores/StoreUtils.kt @@ -49,6 +49,18 @@ object StoreUtils { } } + //region legacy App update + // TODO: Remove this when Ui for kDrive in app update will be made + fun FragmentActivity.checkUpdateIsAvailable(appId: String, versionCode: Int, onResult: (updateIsAvailable: Boolean) -> Unit) { + AppUpdateManagerFactory.create(this).appUpdateInfo.addOnSuccessListener { appUpdateInfo -> + val updateIsAvailable = appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && + appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE) + + onResult(updateIsAvailable) + } + } + //endRegion + //region In-App Update fun initAppUpdateManager(context: Context, onInstall: () -> Unit) { appUpdateManager = AppUpdateManagerFactory.create(context) @@ -58,14 +70,14 @@ object StoreUtils { fun checkUpdateIsAvailable( appId: String, versionCode: Int, - inAppResultLauncher: ActivityResultLauncher, + inAppResultLauncher: ActivityResultLauncher?, onFdroidResult: (updateIsAvailable: Boolean) -> Unit, ) { appUpdateManager.appUpdateInfo.addOnSuccessListener { appUpdateInfo -> if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.isUpdateTypeAllowed(UPDATE_TYPE) ) { - startUpdateFlow(appUpdateInfo, inAppResultLauncher) + inAppResultLauncher?.let { startUpdateFlow(appUpdateInfo, it) } } } }