From eda25ac48cf9f0fe20c3e36052f192911015d5cf Mon Sep 17 00:00:00 2001 From: rumboalla Date: Wed, 2 Aug 2023 10:34:48 +0200 Subject: [PATCH] Added Q parameter to Aptoide Source --- .../data/aptoide/ListAppsUpdatesRequest.kt | 1 + .../data/aptoide/ListSearchAppsRequest.kt | 3 +- .../main/java/com/apkupdater/di/MainModule.kt | 2 +- .../repository/AptoideRepository.kt | 58 ++++++++++++++++++- .../com/apkupdater/viewmodel/MainViewModel.kt | 3 +- 5 files changed, 62 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/apkupdater/data/aptoide/ListAppsUpdatesRequest.kt b/app/src/main/java/com/apkupdater/data/aptoide/ListAppsUpdatesRequest.kt index 72eef4b4..ea2d9c05 100644 --- a/app/src/main/java/com/apkupdater/data/aptoide/ListAppsUpdatesRequest.kt +++ b/app/src/main/java/com/apkupdater/data/aptoide/ListAppsUpdatesRequest.kt @@ -6,5 +6,6 @@ import java.util.Collections.emptyList data class ListAppsUpdatesRequest( val apks_data: List = emptyList(), val notApkTags: String = "alpha,beta", + val q: String //val storeIds: List? = listOf(15L, 1966380L), ) diff --git a/app/src/main/java/com/apkupdater/data/aptoide/ListSearchAppsRequest.kt b/app/src/main/java/com/apkupdater/data/aptoide/ListSearchAppsRequest.kt index dd3c3265..4d9f5e7a 100644 --- a/app/src/main/java/com/apkupdater/data/aptoide/ListSearchAppsRequest.kt +++ b/app/src/main/java/com/apkupdater/data/aptoide/ListSearchAppsRequest.kt @@ -4,5 +4,6 @@ package com.apkupdater.data.aptoide data class ListSearchAppsRequest( val query: String = "", val limit: String = "10", - val notApkTags: String = "alpha,beta" + val notApkTags: String = "alpha,beta", + val q: String ) diff --git a/app/src/main/java/com/apkupdater/di/MainModule.kt b/app/src/main/java/com/apkupdater/di/MainModule.kt index 9763e334..192bb783 100644 --- a/app/src/main/java/com/apkupdater/di/MainModule.kt +++ b/app/src/main/java/com/apkupdater/di/MainModule.kt @@ -118,7 +118,7 @@ val mainModule = module { single { FdroidRepository(get(), get()) } - single { AptoideRepository(get(), get()) } + single { AptoideRepository(get(), get(), get()) } single { UpdatesRepository(get(), get(), get(), get(), get(), get()) } diff --git a/app/src/main/java/com/apkupdater/repository/AptoideRepository.kt b/app/src/main/java/com/apkupdater/repository/AptoideRepository.kt index 92608578..f2bc0076 100644 --- a/app/src/main/java/com/apkupdater/repository/AptoideRepository.kt +++ b/app/src/main/java/com/apkupdater/repository/AptoideRepository.kt @@ -1,6 +1,11 @@ package com.apkupdater.repository +import android.app.ActivityManager +import android.content.Context +import android.content.res.Configuration +import android.content.res.Resources import android.os.Build +import android.util.Base64 import android.util.Log import com.apkupdater.data.aptoide.App import com.apkupdater.data.aptoide.ListAppsUpdatesRequest @@ -10,12 +15,14 @@ import com.apkupdater.data.ui.AppInstalled import com.apkupdater.data.ui.toApksData import com.apkupdater.prefs.Prefs import com.apkupdater.service.AptoideService +import com.apkupdater.util.isAndroidTv import com.apkupdater.util.randomUUID import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.flow class AptoideRepository( + private val context: Context, private val service: AptoideService, private val prefs: Prefs ) { @@ -28,9 +35,13 @@ class AptoideRepository( private fun getArch() = System.getProperty("os.arch") } + private val query: String by lazy { + computeFilters(context) + } + suspend fun updates(apps: List) = flow { val data = apps.map(AppInstalled::toApksData) - val r = service.findUpdates(ListAppsUpdatesRequest(data, buildFilterList())) + val r = service.findUpdates(ListAppsUpdatesRequest(data, buildFilterList(), query)) emit(r.list.map(App::toAppUpdate)) }.catch { emit(emptyList()) @@ -38,7 +49,8 @@ class AptoideRepository( } suspend fun search(text: String) = flow { - val response = service.searchApps(ListSearchAppsRequest(text, "10", buildFilterList())) + val request = ListSearchAppsRequest(text, "10", buildFilterList(), query) + val response = service.searchApps(request) val updates = response.datalist.list.map(App::toAppUpdate) emit(Result.success(updates)) }.catch { @@ -53,4 +65,46 @@ class AptoideRepository( return list.joinToString(separator = ",") } + private fun computeFilters(context: Context): String { + val filters = "maxSdk=${getSdkVer()}&maxScreen=${getScreenSize()}&maxGles=" + + "${getGlEs(context)}&myCPU=${getAbis()}&leanback=${hasLeanback(context)}" + + "&myDensity=${getDensityDpi()}" + + return Base64.encodeToString(filters.toByteArray(), 0) + .replace("=", "") + .replace("/", "*") + .replace("+", "_") + .replace("\n", "") + } + + private fun getSdkVer() = Build.VERSION.SDK_INT + + private fun getScreenSize(): String { + val size = Resources.getSystem().configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK + val sizes = listOf("notfound", "small", "normal", "large", "xlarge") + return sizes[size] + } + + private fun getGlEs(context: Context): String { + val manager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager + return manager.deviceConfigurationInfo.glEsVersion + } + + private fun getAbis() = Build.SUPPORTED_ABIS.joinToString(separator = ",") + + private fun hasLeanback(context: Context): String = if (context.isAndroidTv()) "1" else "0" + + private fun getDensityDpi(): Int { + val dpi = Resources.getSystem().displayMetrics.densityDpi + return when { + dpi <= 120 -> 120 + dpi <= 160 -> 160 + dpi <= 213 -> 213 + dpi <= 240 -> 240 + dpi <= 320 -> 320 + dpi <= 480 -> 480 + else -> 640 + } + } + } diff --git a/app/src/main/java/com/apkupdater/viewmodel/MainViewModel.kt b/app/src/main/java/com/apkupdater/viewmodel/MainViewModel.kt index 33eac2c9..2c6765af 100644 --- a/app/src/main/java/com/apkupdater/viewmodel/MainViewModel.kt +++ b/app/src/main/java/com/apkupdater/viewmodel/MainViewModel.kt @@ -100,7 +100,8 @@ class MainViewModel : ViewModel() { intent.getAppId()?.let { appInstallLog.emit(AppInstallStatus(false, it)) } - Log.e("MainViewModel", "processInstallIntent: ${intent.toString()}") + val message = intent.extras?.getString(PackageInstaller.EXTRA_STATUS_MESSAGE) + Log.e("MainViewModel", "Failed to install app: $message $intent") } } }