wip: icon options screen model sharing

This commit is contained in:
rushiiMachine 2025-03-29 16:18:35 -07:00
parent 9cd713ef70
commit b8cf2176c6
No known key found for this signature in database
GPG key ID: DCBE5952BB3B6420
6 changed files with 71 additions and 15 deletions

View file

@ -9,6 +9,7 @@ import com.aliucord.manager.manager.download.KtorDownloadManager
import com.aliucord.manager.network.services.*
import com.aliucord.manager.ui.screens.about.AboutModel
import com.aliucord.manager.ui.screens.home.HomeModel
import com.aliucord.manager.ui.screens.iconopts.IconOptionsModel
import com.aliucord.manager.ui.screens.patching.PatchingScreenModel
import com.aliucord.manager.ui.screens.patchopts.PatchOptionsModel
import com.aliucord.manager.ui.screens.plugins.PluginsModel
@ -52,6 +53,7 @@ class ManagerApplication : Application() {
factoryOf(::PatchingScreenModel)
factoryOf(::SettingsModel)
factoryOf(::PatchOptionsModel)
factoryOf(::IconOptionsModel)
viewModelOf(::UpdaterViewModel)
})

View file

@ -0,0 +1,28 @@
package com.aliucord.manager.ui.screens.iconopts
import androidx.compose.runtime.*
import androidx.compose.ui.graphics.Color
import cafe.adriel.voyager.core.model.ScreenModel
import com.aliucord.manager.ui.screens.patchopts.PatchOptions.IconReplacement
class IconOptionsModel(
prefilledOptions: IconReplacement,
) : ScreenModel {
var selectedColor by mutableStateOf<Color>(((prefilledOptions as? IconReplacement.CustomColor) ?: IconReplacement.Discord).color)
private set
fun changeSelectedColor(color: Color) {
this.selectedColor = color
}
fun generateConfig(): IconReplacement {
// TODO: other branches
return IconReplacement.CustomColor(color = selectedColor)
}
enum class Mode {
Original,
ReplaceColor,
ReplaceForeground,
}
}

View file

@ -1,31 +1,44 @@
package com.aliucord.manager.ui.screens.iconopts
import android.os.Parcelable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import cafe.adriel.voyager.core.screen.Screen
import com.aliucord.manager.ui.screens.iconopts.components.IconOptionsAppBar
import com.aliucord.manager.ui.screens.patchopts.PatchOptions.IconReplacement
import dev.zt64.compose.pipette.CircularColorPicker
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
interface IconOptionsScreenParent : Parcelable {
/**
* The screen model is elevated outside of this screen
* in order to share the state with the parent screen.
*/
@Composable
fun getIconModel(): IconOptionsModel
}
@Parcelize
class IconOptionsScreen(
private val prefilledOptions: IconReplacement,
) : Screen {
private val parent: IconOptionsScreenParent,
) : Screen, Parcelable {
@IgnoredOnParcel
override val key = "IconOptions"
@Composable
override fun Content() {
var (color, setColor) = remember { mutableStateOf(IconReplacement.Aliucord.color) }
val model = parent.getIconModel()
IconOptionsScreenContent(
selectedColor = color,
setSelectedColor = setColor,
selectedColor = model.selectedColor,
setSelectedColor = model::changeSelectedColor,
)
}
}

View file

@ -80,6 +80,11 @@ data class PatchOptions(
* The default icon replacement option.
*/
val Aliucord = CustomColor(Color(0xFF00C853))
/**
* The Discord icon color.
*/
val Discord = CustomColor(Color(0xFF7289DA))
}
}

View file

@ -59,15 +59,14 @@ class PatchOptionsModel(
invalidChecks.none { it }
}
fun generateConfig(): PatchOptions {
fun generateConfig(icon: PatchOptions.IconReplacement): PatchOptions {
if (!isConfigValid) error("invalid config state")
return PatchOptions(
appName = appName,
packageName = packageName,
debuggable = debuggable,
// TODO: advanced icon options
iconReplacement = PatchOptions.IconReplacement.Aliucord,
iconReplacement = icon,
)
}

View file

@ -23,7 +23,7 @@ import com.aliucord.manager.R
import com.aliucord.manager.ui.components.TextDivider
import com.aliucord.manager.ui.components.dialogs.NetworkWarningDialog
import com.aliucord.manager.ui.components.dialogs.UnknownSourcesPermissionDialog
import com.aliucord.manager.ui.screens.iconopts.IconOptionsScreen
import com.aliucord.manager.ui.screens.iconopts.*
import com.aliucord.manager.ui.screens.patching.PatchingScreen
import com.aliucord.manager.ui.screens.patchopts.components.PackageNameStateLabel
import com.aliucord.manager.ui.screens.patchopts.components.PatchOptionsAppBar
@ -40,15 +40,21 @@ import org.koin.core.parameter.parametersOf
@Parcelize
class PatchOptionsScreen(
private val prefilledOptions: PatchOptions? = null,
) : Screen, Parcelable {
) : Screen, Parcelable, IconOptionsScreenParent {
@IgnoredOnParcel
override val key = "PatchOptions"
@Composable
override fun getIconModel(): IconOptionsModel {
return getScreenModel<IconOptionsModel>()
}
@Composable
override fun Content() {
val context = LocalContext.current
val navigator = LocalNavigator.currentOrThrow
val model = getScreenModel<PatchOptionsModel> { parametersOf(prefilledOptions ?: PatchOptions.Default) }
val iconModel = getScreenModel<IconOptionsModel> { parametersOf((prefilledOptions ?: PatchOptions.Default).iconReplacement) }
LaunchedEffect(Unit) {
// Ensure that when popping this screen off the stack that permission requests don't get triggered
@ -81,8 +87,7 @@ class PatchOptionsScreen(
debuggable = model.debuggable,
setDebuggable = model::changeDebuggable,
// TODO: actual filled in options
onOpenIconOptions = { navigator.push(IconOptionsScreen(PatchOptions.Default.iconReplacement)) },
onOpenIconOptions = { navigator.push(IconOptionsScreen(this@PatchOptionsScreen)) },
appName = model.appName,
appNameIsError = model.appNameIsError,
@ -93,7 +98,11 @@ class PatchOptionsScreen(
setPackageName = model::changePackageName,
isConfigValid = model.isConfigValid,
onInstall = { navigator.push(PatchingScreen(model.generateConfig())) },
onInstall = {
val iconConfig = iconModel.generateConfig()
val patchConfig = model.generateConfig(iconConfig)
navigator.push(PatchingScreen(patchConfig))
},
)
}
}