Skip to content

Commit

Permalink
Add support for kDrive
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianDevel authored and KevinBoulongne committed Nov 24, 2023
1 parent c5776c3 commit a86f277
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
11 changes: 9 additions & 2 deletions Stores/src/fdroid/java/com.infomaniak.lib.stores/StoreUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<IntentSenderRequest>,
inAppResultLauncher: ActivityResultLauncher<IntentSenderRequest>?,
onFDroidResult: (updateIsAvailable: Boolean) -> Unit,
) {
lifecycleScope.launch {
val lastVersionCode = FdroidApiTools().getLastRelease(appId)

withContext(Dispatchers.Main) { onResult(versionCode < lastVersionCode) }
withContext(Dispatchers.Main) { onFDroidResult(versionCode < lastVersionCode) }
}
}

Expand Down
16 changes: 14 additions & 2 deletions Stores/src/standard/java/com.infomaniak.lib.stores/StoreUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -58,14 +70,14 @@ object StoreUtils {
fun checkUpdateIsAvailable(
appId: String,
versionCode: Int,
inAppResultLauncher: ActivityResultLauncher<IntentSenderRequest>,
inAppResultLauncher: ActivityResultLauncher<IntentSenderRequest>?,
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) }
}
}
}
Expand Down

0 comments on commit a86f277

Please sign in to comment.