Remove the back navigation on charactersheet edit and add a save action

This commit is contained in:
Thomas Andres Gomez 2024-11-27 11:53:58 +01:00
parent f8168a8997
commit d2ae180cf7
5 changed files with 29 additions and 36 deletions

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:pathData="M0 0h24v24H0z" />
<path
android:fillColor="#000000"
android:pathData="M17 3H5c-1.11 0-2 0.9-2 2v14c0 1.1 0.89 2 2 2h14c1.1 0 2-0.9 2-2V7l-4-4zm-5 16c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm3-10H5V5h10v4z" />
</vector>

View file

@ -144,7 +144,6 @@ private fun WindowsHandler(
is CharacterSheetCreateWindow -> CharacterSheetMainNavHost( is CharacterSheetCreateWindow -> CharacterSheetMainNavHost(
startDestination = CharacterSheetEditDestination.navigationRoute( startDestination = CharacterSheetEditDestination.navigationRoute(
id = window.sheetId, id = window.sheetId,
enableBack = false,
), ),
) )
} }

View file

@ -12,33 +12,24 @@ import com.pixelized.desktop.lwa.utils.extention.ARG
object CharacterSheetEditDestination { object CharacterSheetEditDestination {
private const val ROUTE = "character.sheet.edit" private const val ROUTE = "character.sheet.edit"
private const val CHARACTER_ID = "id" private const val CHARACTER_ID = "id"
private const val ENABLE_BACK = "enable_back"
fun baseRoute() = "$ROUTE?${CHARACTER_ID.ARG}&${ENABLE_BACK.ARG}" fun baseRoute() = "$ROUTE?${CHARACTER_ID.ARG}"
fun navigationRoute(id: String?, enableBack: Boolean) = ROUTE + fun navigationRoute(id: String?) = ROUTE +
"?$CHARACTER_ID=$id" + "?$CHARACTER_ID=$id"
"&$ENABLE_BACK=$enableBack"
fun arguments() = listOf( fun arguments() = listOf(
navArgument(CHARACTER_ID) { navArgument(CHARACTER_ID) {
nullable = true nullable = true
type = NavType.StringType type = NavType.StringType
}, },
navArgument(ENABLE_BACK) {
nullable = false
type = NavType.BoolType
}
) )
data class Argument( data class Argument(
val id: String?, val id: String?,
val enableBack: Boolean,
) { ) {
constructor(savedStateHandle: SavedStateHandle) : this( constructor(savedStateHandle: SavedStateHandle) : this(
id = savedStateHandle.get<String>(CHARACTER_ID), id = savedStateHandle.get<String>(CHARACTER_ID),
enableBack = savedStateHandle.get<Boolean>(ENABLE_BACK)
?: error("Missing enableBack argument"),
) )
} }
} }
@ -54,8 +45,7 @@ fun NavGraphBuilder.composableCharacterSheetEditPage() {
fun NavHostController.navigateToCharacterSheetEdit( fun NavHostController.navigateToCharacterSheetEdit(
id: String? = null, id: String? = null,
enableBack: Boolean = true,
) { ) {
val route = CharacterSheetEditDestination.navigationRoute(id = id, enableBack = enableBack) val route = CharacterSheetEditDestination.navigationRoute(id = id)
navigate(route = route) navigate(route = route)
} }

View file

@ -49,6 +49,9 @@ import lwacharactersheet.composeapp.generated.resources.character_sheet_edit__sa
import lwacharactersheet.composeapp.generated.resources.character_sheet_edit__skills__magic_action import lwacharactersheet.composeapp.generated.resources.character_sheet_edit__skills__magic_action
import lwacharactersheet.composeapp.generated.resources.character_sheet_edit__skills__special_action import lwacharactersheet.composeapp.generated.resources.character_sheet_edit__skills__special_action
import lwacharactersheet.composeapp.generated.resources.character_sheet_edit__sub_characteristics__title import lwacharactersheet.composeapp.generated.resources.character_sheet_edit__sub_characteristics__title
import lwacharactersheet.composeapp.generated.resources.ic_save_24dp
import lwacharactersheet.composeapp.generated.resources.ic_skull_32dp
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.stringResource import org.jetbrains.compose.resources.stringResource
import org.koin.compose.viewmodel.koinViewModel import org.koin.compose.viewmodel.koinViewModel
@ -109,13 +112,6 @@ fun CharacterSheetEditPage(
CharacterSheetEdit( CharacterSheetEdit(
title = window.title, title = window.title,
form = viewModel.characterSheet.value, form = viewModel.characterSheet.value,
onBack = remember {
if (viewModel.enableBack) {
{ screen.popBackStack() }
} else {
null
}
},
onNewSpecialSkill = { onNewSpecialSkill = {
scope.launch { scope.launch {
viewModel.onNewSpecialSkill() viewModel.onNewSpecialSkill()
@ -148,7 +144,6 @@ fun CharacterSheetEdit(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
title: String, title: String,
form: CharacterSheetEditPageUio, form: CharacterSheetEditPageUio,
onBack: (() -> Unit)?,
onNewSpecialSkill: () -> Unit, onNewSpecialSkill: () -> Unit,
onNewMagicSkill: () -> Unit, onNewMagicSkill: () -> Unit,
onNewAction: () -> Unit, onNewAction: () -> Unit,
@ -165,18 +160,17 @@ fun CharacterSheetEdit(
text = title, text = title,
) )
}, },
navigationIcon = onBack?.let { action: () -> Unit -> actions = {
{ IconButton(
IconButton( onClick = onSave,
onClick = action, ) {
) { Icon(
Icon( painter = painterResource(Res.drawable.ic_save_24dp),
imageVector = Icons.AutoMirrored.Filled.ArrowBack, tint = MaterialTheme.colors.primary,
contentDescription = null, contentDescription = null,
) )
}
} }
} },
) )
}, },
content = { paddingValues -> content = { paddingValues ->

View file

@ -24,8 +24,6 @@ class CharacterSheetEditViewModel(
private val argument = CharacterSheetEditDestination.Argument(savedStateHandle) private val argument = CharacterSheetEditDestination.Argument(savedStateHandle)
val enableBack = argument.enableBack
private val _characterSheet = mutableStateOf( private val _characterSheet = mutableStateOf(
characterSheetRepository.characterSheetFlow(id = argument.id).value.let { characterSheetRepository.characterSheetFlow(id = argument.id).value.let {
runBlocking { runBlocking {