mirror of
https://github.com/ReVanced/revanced-manager
synced 2026-04-25 17:15:36 +02:00
feat: Speed up loading app list
This commit is contained in:
@@ -74,7 +74,6 @@ fun AppsScreen(
|
||||
|
||||
val installedApps by viewModel.installedApps.collectAsStateWithLifecycle()
|
||||
val patchableApps by viewModel.patchableApps.collectAsStateWithLifecycle()
|
||||
val disableUniversalPatchCheckEnabled by viewModel.prefs.disableUniversalPatchCheck.getAsState()
|
||||
|
||||
fun patchedPackageNames(apps: List<InstalledApp>?): Set<String> =
|
||||
apps
|
||||
@@ -314,9 +313,7 @@ fun AppsScreen(
|
||||
}
|
||||
|
||||
val patchedPackageNames = patchedPackageNames(patched)
|
||||
val visiblePatchableApps = patchable.filter {
|
||||
it.packageName !in patchedPackageNames && (disableUniversalPatchCheckEnabled || (it.patches ?: 0) > 0)
|
||||
}
|
||||
val visiblePatchableApps = patchable.filter { it.packageName !in patchedPackageNames }
|
||||
|
||||
if (patched.isNotEmpty()) {
|
||||
item(key = "HEADER_PATCHED") {
|
||||
|
||||
@@ -3,10 +3,7 @@ package app.revanced.manager.ui.viewmodel
|
||||
import android.app.Application
|
||||
import android.content.pm.PackageInfo
|
||||
import android.net.Uri
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateMapOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
@@ -18,7 +15,6 @@ import app.revanced.manager.data.room.apps.installed.InstallType
|
||||
import app.revanced.manager.data.room.apps.installed.InstalledApp
|
||||
import app.revanced.manager.domain.installer.RootInstaller
|
||||
import app.revanced.manager.domain.installer.RootServiceException
|
||||
import app.revanced.manager.domain.manager.PreferencesManager
|
||||
import app.revanced.manager.domain.repository.InstalledAppRepository
|
||||
import app.revanced.manager.ui.model.SelectedApp
|
||||
import app.revanced.manager.util.PM
|
||||
@@ -43,7 +39,6 @@ class AppsViewModel(
|
||||
private val installedAppsRepository: InstalledAppRepository,
|
||||
private val pm: PM,
|
||||
private val rootInstaller: RootInstaller,
|
||||
val prefs: PreferencesManager,
|
||||
fs: Filesystem,
|
||||
savedStateHandle: SavedStateHandle,
|
||||
) : ViewModel() {
|
||||
|
||||
@@ -4,18 +4,19 @@ import android.annotation.SuppressLint
|
||||
import android.app.Application
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageInfo
|
||||
import android.content.pm.PackageManager.PackageInfoFlags
|
||||
import android.content.pm.PackageManager.NameNotFoundException
|
||||
import androidx.core.content.pm.PackageInfoCompat
|
||||
import android.content.pm.PackageManager.PackageInfoFlags
|
||||
import android.os.Build
|
||||
import android.os.Parcelable
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.core.content.pm.PackageInfoCompat
|
||||
import app.revanced.manager.domain.manager.PreferencesManager
|
||||
import app.revanced.manager.domain.repository.PatchBundleRepository
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import ru.solrudev.ackpine.session.await
|
||||
@@ -37,11 +38,15 @@ data class AppInfo(
|
||||
class PM(
|
||||
private val app: Application,
|
||||
patchBundleRepository: PatchBundleRepository,
|
||||
prefs: PreferencesManager,
|
||||
private val uninstaller: PackageUninstaller
|
||||
) {
|
||||
private val scope = CoroutineScope(Dispatchers.IO)
|
||||
|
||||
val appList = patchBundleRepository.bundleInfoFlow.map { bundles ->
|
||||
val appList = combine(
|
||||
patchBundleRepository.bundleInfoFlow,
|
||||
prefs.disableUniversalPatchCheck.flow
|
||||
) { bundles, showInstalled ->
|
||||
val compatibleApps = scope.async {
|
||||
val compatiblePackages = bundles
|
||||
.flatMap { (_, bundle) -> bundle.patches }
|
||||
@@ -64,28 +69,32 @@ class PM(
|
||||
}
|
||||
}
|
||||
|
||||
val installedApps = scope.async {
|
||||
getInstalledPackages().map { packageInfo ->
|
||||
AppInfo(
|
||||
packageInfo.packageName,
|
||||
0,
|
||||
packageInfo
|
||||
)
|
||||
val installedApps = if (showInstalled) {
|
||||
scope.async {
|
||||
getInstalledPackages().map { packageInfo ->
|
||||
AppInfo(packageInfo.packageName, 0, packageInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else null
|
||||
|
||||
if (compatibleApps.await().isNotEmpty()) {
|
||||
(compatibleApps.await() + installedApps.await())
|
||||
.distinctBy { it.packageName }
|
||||
.sortedWith(
|
||||
compareByDescending<AppInfo> {
|
||||
it.packageInfo != null && (it.patches ?: 0) > 0
|
||||
}.thenByDescending {
|
||||
it.patches
|
||||
}.thenBy {
|
||||
it.packageInfo?.label()
|
||||
}.thenBy { it.packageName }
|
||||
)
|
||||
val compatible = compatibleApps.await()
|
||||
|
||||
if (compatible.isNotEmpty()) {
|
||||
val base = if (installedApps != null) {
|
||||
(compatible + installedApps.await()).distinctBy { it.packageName }
|
||||
} else {
|
||||
compatible
|
||||
}
|
||||
|
||||
base.sortedWith(
|
||||
compareByDescending<AppInfo> {
|
||||
it.packageInfo != null && (it.patches ?: 0) > 0
|
||||
}.thenByDescending {
|
||||
it.patches
|
||||
}.thenBy {
|
||||
it.packageInfo?.label()
|
||||
}.thenBy { it.packageName }
|
||||
)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user