mirror of
https://github.com/revanced/revanced-manager
synced 2024-05-14 13:56:57 +02:00
feat: improved compose stability
This commit is contained in:
parent
1be9c9c1bd
commit
fcb75dd780
@ -1,13 +1,16 @@
|
||||
package app.revanced.manager.compose.domain.sources
|
||||
|
||||
import androidx.compose.runtime.Stable
|
||||
import app.revanced.manager.compose.network.api.ManagerAPI
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.koin.core.component.get
|
||||
import java.io.File
|
||||
|
||||
@Stable
|
||||
class RemoteSource(id: Int, directory: File) : Source(id, directory) {
|
||||
private val api: ManagerAPI = get()
|
||||
|
||||
suspend fun downloadLatest() = withContext(Dispatchers.IO) {
|
||||
api.downloadBundle(patchesJar, integrations).also { (patchesVer, integrationsVer) ->
|
||||
saveVersion(patchesVer, integrationsVer)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package app.revanced.manager.compose.domain.sources
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.Stable
|
||||
import app.revanced.manager.compose.patcher.patch.PatchBundle
|
||||
import app.revanced.manager.compose.domain.repository.SourcePersistenceRepository
|
||||
import app.revanced.manager.compose.util.tag
|
||||
@ -13,6 +14,7 @@ import java.io.File
|
||||
/**
|
||||
* A [PatchBundle] source.
|
||||
*/
|
||||
@Stable
|
||||
sealed class Source(val id: Int, directory: File) : KoinComponent {
|
||||
private val configRepository: SourcePersistenceRepository by inject()
|
||||
protected companion object {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package app.revanced.manager.compose.patcher.patch
|
||||
|
||||
import android.os.Parcelable
|
||||
import androidx.compose.runtime.Immutable
|
||||
import app.revanced.manager.compose.patcher.PatchClass
|
||||
import app.revanced.patcher.annotation.Package
|
||||
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
|
||||
@ -10,24 +10,24 @@ import app.revanced.patcher.extensions.PatchExtensions.include
|
||||
import app.revanced.patcher.extensions.PatchExtensions.options
|
||||
import app.revanced.patcher.extensions.PatchExtensions.patchName
|
||||
import app.revanced.patcher.patch.PatchOption
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
@Parcelize
|
||||
data class PatchInfo(
|
||||
val name: String,
|
||||
val description: String?,
|
||||
val dependencies: List<String>?,
|
||||
val dependencies: ImmutableList<String>?,
|
||||
val include: Boolean,
|
||||
val compatiblePackages: List<CompatiblePackage>?,
|
||||
val options: List<Option>?
|
||||
) : Parcelable {
|
||||
val compatiblePackages: ImmutableList<CompatiblePackage>?,
|
||||
val options: ImmutableList<Option>?
|
||||
) {
|
||||
constructor(patch: PatchClass) : this(
|
||||
patch.patchName,
|
||||
patch.description,
|
||||
patch.dependencies?.map { it.java.patchName },
|
||||
patch.dependencies?.map { it.java.patchName }?.toImmutableList(),
|
||||
patch.include,
|
||||
patch.compatiblePackages?.map { CompatiblePackage(it) },
|
||||
patch.options?.map { Option(it) })
|
||||
patch.compatiblePackages?.map { CompatiblePackage(it) }?.toImmutableList(),
|
||||
patch.options?.map { Option(it) }?.toImmutableList())
|
||||
|
||||
fun compatibleWith(packageName: String) = compatiblePackages?.any { it.name == packageName } ?: true
|
||||
|
||||
@ -36,12 +36,14 @@ data class PatchInfo(
|
||||
?: true
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
data class CompatiblePackage(val name: String, val versions: List<String>) : Parcelable {
|
||||
constructor(pkg: Package) : this(pkg.name, pkg.versions.toList())
|
||||
@Immutable
|
||||
data class CompatiblePackage(
|
||||
val name: String,
|
||||
val versions: ImmutableList<String>
|
||||
) {
|
||||
constructor(pkg: Package) : this(pkg.name, pkg.versions.toList().toImmutableList())
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
data class Option(val title: String, val key: String, val description: String, val required: Boolean) : Parcelable {
|
||||
data class Option(val title: String, val key: String, val description: String, val required: Boolean) {
|
||||
constructor(option: PatchOption<*>) : this(option.title, option.key, option.description, option.required)
|
||||
}
|
@ -6,6 +6,9 @@ import androidx.work.Data
|
||||
import androidx.work.workDataOf
|
||||
import app.revanced.manager.compose.R
|
||||
import app.revanced.manager.compose.patcher.Session
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
@ -31,7 +34,7 @@ enum class StepStatus {
|
||||
class Step(val name: String, val status: StepStatus = StepStatus.WAITING)
|
||||
|
||||
@Serializable
|
||||
class StepGroup(@StringRes val name: Int, val steps: List<Step>, val status: StepStatus = StepStatus.WAITING)
|
||||
class StepGroup(@StringRes val name: Int, val steps: ImmutableList<Step>, val status: StepStatus = StepStatus.WAITING)
|
||||
|
||||
class PatcherProgressManager(context: Context, selectedPatches: List<String>) {
|
||||
val stepGroups = generateGroupsList(context, selectedPatches)
|
||||
@ -53,18 +56,18 @@ class PatcherProgressManager(context: Context, selectedPatches: List<String>) {
|
||||
fun generateGroupsList(context: Context, selectedPatches: List<String>) = mutableListOf(
|
||||
StepGroup(
|
||||
R.string.patcher_step_group_prepare,
|
||||
listOf(
|
||||
persistentListOf(
|
||||
Step(context.getString(R.string.patcher_step_unpack)),
|
||||
Step(context.getString(R.string.patcher_step_integrations))
|
||||
)
|
||||
),
|
||||
StepGroup(
|
||||
R.string.patcher_step_group_patching,
|
||||
selectedPatches.map { Step(it) }
|
||||
selectedPatches.map { Step(it) }.toImmutableList()
|
||||
),
|
||||
StepGroup(
|
||||
R.string.patcher_step_group_saving,
|
||||
listOf(Step(context.getString(R.string.patcher_step_write_patched)))
|
||||
persistentListOf(Step(context.getString(R.string.patcher_step_write_patched)))
|
||||
)
|
||||
)
|
||||
|
||||
@ -95,7 +98,7 @@ class PatcherProgressManager(context: Context, selectedPatches: List<String>) {
|
||||
|
||||
StepGroup(group.name, group.steps.toMutableList().mutateIndex(key.stepIndex) { step ->
|
||||
Step(step.name, newStatus)
|
||||
}, newGroupStatus)
|
||||
}.toImmutableList(), newGroupStatus)
|
||||
}
|
||||
|
||||
val isFinalStep = isLastStepOfGroup && key.groupIndex == stepGroups.size - 1
|
||||
|
@ -25,7 +25,6 @@ import androidx.compose.material.icons.filled.BatteryAlert
|
||||
import androidx.compose.material.icons.outlined.*
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
@ -41,14 +40,12 @@ import app.revanced.manager.compose.ui.component.AppTopBar
|
||||
import app.revanced.manager.compose.ui.destination.SettingsDestination
|
||||
import app.revanced.manager.compose.ui.screen.settings.*
|
||||
import app.revanced.manager.compose.ui.viewmodel.SettingsViewModel
|
||||
import app.revanced.manager.compose.ui.viewmodel.UpdateSettingsViewModel
|
||||
import dev.olshevski.navigation.reimagined.*
|
||||
import org.koin.androidx.compose.getViewModel
|
||||
|
||||
@SuppressLint("BatteryLife")
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalAnimationApi::class)
|
||||
@Composable
|
||||
@Stable
|
||||
fun SettingsScreen(
|
||||
onBackClick: () -> Unit,
|
||||
viewModel: SettingsViewModel = getViewModel()
|
||||
|
@ -1,6 +1,5 @@
|
||||
package app.revanced.manager.compose.ui.screen.settings
|
||||
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
@ -26,7 +25,6 @@ import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
@ -45,7 +43,7 @@ import dev.olshevski.navigation.reimagined.NavController
|
||||
import dev.olshevski.navigation.reimagined.navigate
|
||||
import org.koin.androidx.compose.getViewModel
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalAnimationApi::class)
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun UpdatesSettingsScreen(
|
||||
onBackClick: () -> Unit,
|
||||
@ -142,7 +140,6 @@ fun UpdateNotification(
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@Stable
|
||||
fun UpdateProgressScreen(
|
||||
onBackClick: () -> Unit,
|
||||
vm: UpdateSettingsViewModel = getViewModel()
|
||||
|
@ -7,6 +7,7 @@ import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.PackageInstaller
|
||||
import android.net.Uri
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@ -32,6 +33,7 @@ import org.koin.core.component.inject
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
@Stable
|
||||
class InstallerViewModel(
|
||||
input: AppInfo,
|
||||
selectedPatches: PatchesSelection
|
||||
|
@ -1,5 +1,6 @@
|
||||
package app.revanced.manager.compose.ui.viewmodel
|
||||
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateListOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@ -13,6 +14,7 @@ import kotlinx.coroutines.flow.map
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.get
|
||||
|
||||
@Stable
|
||||
class PatchesSelectorViewModel(appInfo: AppInfo) : ViewModel(), KoinComponent {
|
||||
val bundlesFlow = get<SourceRepository>().bundles.map { bundles ->
|
||||
bundles.mapValues { (_, bundle) -> bundle.patches }.map { (name, patches) ->
|
||||
|
Loading…
Reference in New Issue
Block a user