Skip to content

Commit

Permalink
Added Q parameter to Aptoide Source
Browse files Browse the repository at this point in the history
  • Loading branch information
rumboalla committed Aug 2, 2023
1 parent e6da65e commit eda25ac
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import java.util.Collections.emptyList
data class ListAppsUpdatesRequest(
val apks_data: List<ApksData> = emptyList(),
val notApkTags: String = "alpha,beta",
val q: String
//val storeIds: List<Long>? = listOf(15L, 1966380L),
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 1 addition & 1 deletion app/src/main/java/com/apkupdater/di/MainModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()) }

Expand Down
58 changes: 56 additions & 2 deletions app/src/main/java/com/apkupdater/repository/AptoideRepository.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
) {
Expand All @@ -28,17 +35,22 @@ class AptoideRepository(
private fun getArch() = System.getProperty("os.arch")
}

private val query: String by lazy {
computeFilters(context)
}

suspend fun updates(apps: List<AppInstalled>) = 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())
Log.e("AptoideRepository", "Error looking for updates.", it)
}

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 {
Expand All @@ -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
}
}

}
3 changes: 2 additions & 1 deletion app/src/main/java/com/apkupdater/viewmodel/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
Expand Down

0 comments on commit eda25ac

Please sign in to comment.