From 8886145985b71446ad9fb21e6dfc42090612e3db Mon Sep 17 00:00:00 2001 From: rumboalla Date: Mon, 25 Mar 2024 08:35:38 +0100 Subject: [PATCH] Play Source * Updates: You can look for updates now. Install should work for normal/split apps but will fail for other cases like apps with dependencies. --- .../kotlin/com/apkupdater/di/MainModule.kt | 2 +- .../apkupdater/repository/PlayRepository.kt | 57 +++++++++++++------ .../repository/UpdatesRepository.kt | 2 + .../com/apkupdater/ui/component/Text.kt | 1 - 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/app/src/main/kotlin/com/apkupdater/di/MainModule.kt b/app/src/main/kotlin/com/apkupdater/di/MainModule.kt index e486075e..10bac5b2 100644 --- a/app/src/main/kotlin/com/apkupdater/di/MainModule.kt +++ b/app/src/main/kotlin/com/apkupdater/di/MainModule.kt @@ -152,7 +152,7 @@ val mainModule = module { single(named("izzy")) { FdroidRepository(get(), "https://apt.izzysoft.de/fdroid/repo/", IzzySource, get()) } - single { UpdatesRepository(get(), get(), get(), get(named("main")), get(named("izzy")), get(), get(), get(), get()) } + single { UpdatesRepository(get(), get(), get(), get(named("main")), get(named("izzy")), get(), get(), get(), get(), get()) } single { SearchRepository(get(), get(named("main")), get(named("izzy")), get(), get(), get(), get(), get(), get()) } diff --git a/app/src/main/kotlin/com/apkupdater/repository/PlayRepository.kt b/app/src/main/kotlin/com/apkupdater/repository/PlayRepository.kt index 3db7e1f7..1be039cd 100644 --- a/app/src/main/kotlin/com/apkupdater/repository/PlayRepository.kt +++ b/app/src/main/kotlin/com/apkupdater/repository/PlayRepository.kt @@ -3,11 +3,16 @@ package com.apkupdater.repository import android.content.Context import android.net.Uri import android.util.Log +import com.apkupdater.data.ui.AppInstalled import com.apkupdater.data.ui.AppUpdate import com.apkupdater.data.ui.PlaySource +import com.apkupdater.data.ui.getPackageNames +import com.apkupdater.data.ui.getVersion +import com.apkupdater.data.ui.getVersionCode import com.apkupdater.prefs.Prefs import com.apkupdater.util.play.NativeDeviceInfoProvider import com.apkupdater.util.play.PlayHttpClient +import com.aurora.gplayapi.data.models.App import com.aurora.gplayapi.data.models.AuthData import com.aurora.gplayapi.helpers.AppDetailsHelper import com.aurora.gplayapi.helpers.PurchaseHelper @@ -45,26 +50,46 @@ class PlayRepository( return@flow } val authData = auth() - val details = AppDetailsHelper(authData).using(PlayHttpClient) - val app = details.getAppByPackageName(text) - val files = PurchaseHelper(authData).purchase(app.packageName, app.versionCode, app.offerType) - val link = files.joinToString(separator = ",") { it.url } - val update = AppUpdate( - app.displayName, - app.packageName, - app.versionName, - "", - app.versionCode.toLong(), - 0L, - PlaySource, - Uri.parse(app.iconArtwork.url), - link, - whatsNew = app.changes - ) + val app = AppDetailsHelper(authData) + .using(PlayHttpClient) + .getAppByPackageName(text) + val update = app.toAppUpdate(PurchaseHelper(authData)) emit(Result.success(listOf(update))) }.catch { emit(Result.failure(it)) Log.e("PlayRepository", "Error searching.", it) } + suspend fun updates(apps: List) = flow { + val authData = auth() + val details = AppDetailsHelper(authData) + .using(PlayHttpClient) + .getAppByPackageName(apps.getPackageNames()) + val purchaseHelper = PurchaseHelper(authData) + val updates = details + .filter { it.versionCode > apps.getVersionCode(it.packageName) } + .map { it.toAppUpdate(purchaseHelper, apps.getVersion(it.packageName), apps.getVersionCode(it.packageName)) } + emit(updates) + }.catch { + emit(emptyList()) + Log.e("AptoideRepository", "Error looking for updates.", it) + } + } + +fun App.toAppUpdate( + purchaseHelper: PurchaseHelper, + oldVersion: String = "", + oldVersionCode: Long = 0L +) = AppUpdate( + displayName, + packageName, + versionName, + oldVersion, + versionCode.toLong(), + oldVersionCode, + PlaySource, + Uri.parse(iconArtwork.url), + purchaseHelper.purchase(packageName, versionCode, offerType).joinToString(",") { it.url }, + whatsNew = changes +) diff --git a/app/src/main/kotlin/com/apkupdater/repository/UpdatesRepository.kt b/app/src/main/kotlin/com/apkupdater/repository/UpdatesRepository.kt index 08c05e83..141c1e89 100644 --- a/app/src/main/kotlin/com/apkupdater/repository/UpdatesRepository.kt +++ b/app/src/main/kotlin/com/apkupdater/repository/UpdatesRepository.kt @@ -19,6 +19,7 @@ class UpdatesRepository( private val aptoideRepository: AptoideRepository, private val apkPureRepository: ApkPureRepository, private val gitLabRepository: GitLabRepository, + private val playRepository: PlayRepository, private val prefs: Prefs ) { @@ -34,6 +35,7 @@ class UpdatesRepository( if (prefs.useAptoide.get()) sources.add(aptoideRepository.updates(filtered)) if (prefs.useApkPure.get()) sources.add(apkPureRepository.updates(filtered)) if (prefs.useGitLab.get()) sources.add(gitLabRepository.updates(filtered)) + if (prefs.usePlay.get()) sources.add(playRepository.updates(filtered)) if (sources.isNotEmpty()) { sources diff --git a/app/src/main/kotlin/com/apkupdater/ui/component/Text.kt b/app/src/main/kotlin/com/apkupdater/ui/component/Text.kt index eab6cce9..f75d93b1 100644 --- a/app/src/main/kotlin/com/apkupdater/ui/component/Text.kt +++ b/app/src/main/kotlin/com/apkupdater/ui/component/Text.kt @@ -151,7 +151,6 @@ fun ScrollableText( } } -@OptIn(ExperimentalMaterial3Api::class) @Composable fun BadgeText(number: String) { if (number.isNotEmpty()) {