Skip to content

Commit

Permalink
Play Source
Browse files Browse the repository at this point in the history
* Updates: You can look for updates now. Install should work for normal/split apps but will fail for other cases like apps with dependencies.
  • Loading branch information
rumboalla committed Mar 25, 2024
1 parent 8bfd3f0 commit 8886145
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/src/main/kotlin/com/apkupdater/di/MainModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()) }

Expand Down
57 changes: 41 additions & 16 deletions app/src/main/kotlin/com/apkupdater/repository/PlayRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<AppInstalled>) = 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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {

Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion app/src/main/kotlin/com/apkupdater/ui/component/Text.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ fun ScrollableText(
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun BadgeText(number: String) {
if (number.isNotEmpty()) {
Expand Down

0 comments on commit 8886145

Please sign in to comment.