feat: use rememberSaveable where applicable

This commit is contained in:
rushiiMachine 2025-02-09 18:49:51 -08:00
parent 5818526d77
commit 197c20fbaa
No known key found for this signature in database
GPG key ID: DCBE5952BB3B6420
6 changed files with 17 additions and 9 deletions

View file

@ -1,6 +1,8 @@
package com.aliucord.manager.network.utils
import android.os.Parcelable
import androidx.compose.runtime.Immutable
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.PrimitiveKind
@ -12,13 +14,14 @@ import kotlinx.serialization.encoding.Encoder
* Parses a Semantic version in the format of `v1.0.0` (v[major].[minor].[patch])
*/
@Immutable
@Parcelize
@Serializable(SemVer.Serializer::class)
data class SemVer(
val major: Int,
val minor: Int,
val patch: Int,
private val vPrefix: Boolean = false,
) : Comparable<SemVer> {
) : Comparable<SemVer>, Parcelable {
override fun compareTo(other: SemVer): Int {
val pairs = arrayOf(
major to other.major,

View file

@ -1,21 +1,24 @@
package com.aliucord.manager.patcher.steps
import android.os.Parcelable
import androidx.annotation.StringRes
import androidx.compose.runtime.Immutable
import com.aliucord.manager.R
import kotlinx.parcelize.Parcelize
/**
* A group of steps that is shown under one section in the patching UI.
* This has no functional impact other than organization.
*/
@Immutable
@Parcelize
enum class StepGroup(
/**
* The UI name to display this group as
*/
@get:StringRes
val localizedName: Int,
) {
) : Parcelable {
Prepare(R.string.install_group_prepare),
Download(R.string.install_group_download),
Patch(R.string.install_group_patch),

View file

@ -5,6 +5,7 @@ import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@ -25,7 +26,7 @@ fun CustomComponentVersionPicker(
onDelete: (SemVer) -> Unit,
onCancel: () -> Unit,
) {
var selectedVersion by remember { mutableStateOf<SemVer?>(null) }
var selectedVersion by rememberSaveable { mutableStateOf<SemVer?>(null) }
AlertDialog(
properties = DialogProperties(

View file

@ -131,7 +131,7 @@ private fun UserEntry(name: String, roles: String, username: String = name) {
.clickable(
onClick = { uriHandler.openUri("https://github.com/$username") },
indication = ripple(bounded = false, radius = 90.dp),
interactionSource = remember { MutableInteractionSource() }
interactionSource = remember(::MutableInteractionSource)
)
.widthIn(min = 100.dp)
) {

View file

@ -13,6 +13,7 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
@ -61,10 +62,10 @@ class PatchingScreen(private val data: PatchOptions) : Screen, Parcelable {
val showMinimizationWarning = remember { !context.isIgnoringBatteryOptimizations() }
// Exit warning dialog (dismiss itself if install process state changes, esp. for Success)
var showAbortWarning by remember(model.state.collectAsState().value) { mutableStateOf(false) }
var showAbortWarning by rememberSaveable(model.state.collectAsState().value) { mutableStateOf(false) }
// The currently expanded step group on this screen
var expandedGroup by remember { mutableStateOf<StepGroup?>(StepGroup.Prepare) }
var expandedGroup by rememberSaveable { mutableStateOf<StepGroup?>(StepGroup.Prepare) }
// Only show exit warning if currently working
val onTryExit: () -> Unit = remember {
@ -210,7 +211,7 @@ class PatchingScreen(private val data: PatchOptions) : Screen, Parcelable {
}
item(key = "BUTTONS") {
var cacheCleared by remember { mutableStateOf(false) }
var cacheCleared by rememberSaveable { mutableStateOf(false) }
val filteredState by remember { model.state.filter { it.isProgressChange } }
.collectAsState(initial = PatchingScreenState.Working)

View file

@ -61,7 +61,7 @@ class PatchOptionsScreen(
context.requestNoBatteryOptimizations()
}
var showNetworkWarningDialog by rememberSaveable { mutableStateOf(model.isNetworkDangerous()) }
var showNetworkWarningDialog by remember { mutableStateOf(model.isNetworkDangerous()) }
if (showNetworkWarningDialog) {
NetworkWarningDialog(
onConfirm = { showNetworkWarningDialog = false },
@ -92,7 +92,7 @@ class PatchOptionsScreen(
textAlign = TextAlign.Center,
)
var animatedVersion by remember { mutableStateOf<DiscordVersion>(DiscordVersion.None) }
var animatedVersion by rememberSaveable { mutableStateOf<DiscordVersion>(DiscordVersion.None) }
LaunchedEffect(Unit) {
animatedVersion = supportedVersion
}