Remove the back navigation on charactersheet edit and add a save action
This commit is contained in:
parent
f8168a8997
commit
d2ae180cf7
5 changed files with 29 additions and 36 deletions
|
|
@ -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>
|
||||
|
|
@ -144,7 +144,6 @@ private fun WindowsHandler(
|
|||
is CharacterSheetCreateWindow -> CharacterSheetMainNavHost(
|
||||
startDestination = CharacterSheetEditDestination.navigationRoute(
|
||||
id = window.sheetId,
|
||||
enableBack = false,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,33 +12,24 @@ import com.pixelized.desktop.lwa.utils.extention.ARG
|
|||
object CharacterSheetEditDestination {
|
||||
private const val ROUTE = "character.sheet.edit"
|
||||
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 +
|
||||
"?$CHARACTER_ID=$id" +
|
||||
"&$ENABLE_BACK=$enableBack"
|
||||
fun navigationRoute(id: String?) = ROUTE +
|
||||
"?$CHARACTER_ID=$id"
|
||||
|
||||
fun arguments() = listOf(
|
||||
navArgument(CHARACTER_ID) {
|
||||
nullable = true
|
||||
type = NavType.StringType
|
||||
},
|
||||
navArgument(ENABLE_BACK) {
|
||||
nullable = false
|
||||
type = NavType.BoolType
|
||||
}
|
||||
)
|
||||
|
||||
data class Argument(
|
||||
val id: String?,
|
||||
val enableBack: Boolean,
|
||||
) {
|
||||
constructor(savedStateHandle: SavedStateHandle) : this(
|
||||
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(
|
||||
id: String? = null,
|
||||
enableBack: Boolean = true,
|
||||
) {
|
||||
val route = CharacterSheetEditDestination.navigationRoute(id = id, enableBack = enableBack)
|
||||
val route = CharacterSheetEditDestination.navigationRoute(id = id)
|
||||
navigate(route = route)
|
||||
}
|
||||
|
|
@ -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__special_action
|
||||
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.koin.compose.viewmodel.koinViewModel
|
||||
|
||||
|
|
@ -109,13 +112,6 @@ fun CharacterSheetEditPage(
|
|||
CharacterSheetEdit(
|
||||
title = window.title,
|
||||
form = viewModel.characterSheet.value,
|
||||
onBack = remember {
|
||||
if (viewModel.enableBack) {
|
||||
{ screen.popBackStack() }
|
||||
} else {
|
||||
null
|
||||
}
|
||||
},
|
||||
onNewSpecialSkill = {
|
||||
scope.launch {
|
||||
viewModel.onNewSpecialSkill()
|
||||
|
|
@ -148,7 +144,6 @@ fun CharacterSheetEdit(
|
|||
modifier: Modifier = Modifier,
|
||||
title: String,
|
||||
form: CharacterSheetEditPageUio,
|
||||
onBack: (() -> Unit)?,
|
||||
onNewSpecialSkill: () -> Unit,
|
||||
onNewMagicSkill: () -> Unit,
|
||||
onNewAction: () -> Unit,
|
||||
|
|
@ -165,18 +160,17 @@ fun CharacterSheetEdit(
|
|||
text = title,
|
||||
)
|
||||
},
|
||||
navigationIcon = onBack?.let { action: () -> Unit ->
|
||||
{
|
||||
IconButton(
|
||||
onClick = action,
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = null,
|
||||
)
|
||||
}
|
||||
actions = {
|
||||
IconButton(
|
||||
onClick = onSave,
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(Res.drawable.ic_save_24dp),
|
||||
tint = MaterialTheme.colors.primary,
|
||||
contentDescription = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
},
|
||||
content = { paddingValues ->
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@ class CharacterSheetEditViewModel(
|
|||
|
||||
private val argument = CharacterSheetEditDestination.Argument(savedStateHandle)
|
||||
|
||||
val enableBack = argument.enableBack
|
||||
|
||||
private val _characterSheet = mutableStateOf(
|
||||
characterSheetRepository.characterSheetFlow(id = argument.id).value.let {
|
||||
runBlocking {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue