Change navigation for RollHistory into window
This commit is contained in:
parent
f99a938e64
commit
fa87f05be6
11 changed files with 105 additions and 88 deletions
|
|
@ -34,11 +34,13 @@ import com.pixelized.desktop.lwa.navigation.screen.destination.CharacterSheetDes
|
|||
import com.pixelized.desktop.lwa.navigation.screen.destination.CharacterSheetEditDestination
|
||||
import com.pixelized.desktop.lwa.navigation.window.WindowController
|
||||
import com.pixelized.desktop.lwa.navigation.window.WindowsNavHost
|
||||
import com.pixelized.desktop.lwa.navigation.window.destination.CharacterSheetCreateWindow
|
||||
import com.pixelized.desktop.lwa.navigation.window.destination.CharacterSheetEditWindow
|
||||
import com.pixelized.desktop.lwa.navigation.window.destination.CharacterSheetWindow
|
||||
import com.pixelized.desktop.lwa.navigation.window.destination.RollHistoryWindow
|
||||
import com.pixelized.desktop.lwa.repository.network.NetworkRepository
|
||||
import com.pixelized.desktop.lwa.repository.network.NetworkRepository.Status
|
||||
import com.pixelized.desktop.lwa.screen.characterSheet.CharacterSheetMainNavHost
|
||||
import com.pixelized.desktop.lwa.screen.rollhistory.RollHistoryPage
|
||||
import com.pixelized.desktop.lwa.theme.LwaTheme
|
||||
import kotlinx.coroutines.launch
|
||||
import lwacharactersheet.composeapp.generated.resources.Res
|
||||
|
|
@ -141,11 +143,13 @@ private fun WindowsHandler(
|
|||
),
|
||||
)
|
||||
|
||||
is CharacterSheetCreateWindow -> CharacterSheetMainNavHost(
|
||||
is CharacterSheetEditWindow -> CharacterSheetMainNavHost(
|
||||
startDestination = CharacterSheetEditDestination.navigationRoute(
|
||||
id = window.sheetId,
|
||||
),
|
||||
)
|
||||
|
||||
is RollHistoryWindow -> RollHistoryPage()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import androidx.navigation.compose.rememberNavController
|
|||
import com.pixelized.desktop.lwa.navigation.screen.destination.MainDestination
|
||||
import com.pixelized.desktop.lwa.navigation.screen.destination.composableMainPage
|
||||
import com.pixelized.desktop.lwa.navigation.screen.destination.composableNetworkPage
|
||||
import com.pixelized.desktop.lwa.navigation.screen.destination.composableRollHistory
|
||||
|
||||
val LocalScreenController = compositionLocalOf<NavHostController> {
|
||||
error("MainNavHost controller is not yet ready")
|
||||
|
|
@ -29,7 +28,6 @@ fun MainNavHost(
|
|||
) {
|
||||
composableMainPage()
|
||||
composableNetworkPage()
|
||||
composableRollHistory()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package com.pixelized.desktop.lwa.navigation.screen.destination
|
||||
|
||||
import androidx.navigation.NavGraphBuilder
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.composable
|
||||
import com.pixelized.desktop.lwa.screen.rollhistory.RollHistoryPage
|
||||
|
||||
object RollHistoryDestination {
|
||||
private const val ROUTE = "roll_history"
|
||||
|
||||
fun baseRoute() = ROUTE
|
||||
fun navigationRoute() = ROUTE
|
||||
}
|
||||
|
||||
fun NavGraphBuilder.composableRollHistory() {
|
||||
composable(
|
||||
route = RollHistoryDestination.baseRoute()
|
||||
) {
|
||||
RollHistoryPage()
|
||||
}
|
||||
}
|
||||
|
||||
fun NavHostController.navigateToRollHistory() {
|
||||
val route = RollHistoryDestination.navigationRoute()
|
||||
navigate(route = route)
|
||||
}
|
||||
|
|
@ -3,9 +3,10 @@ package com.pixelized.desktop.lwa.navigation.window.destination
|
|||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.ui.unit.DpSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.pixelized.desktop.lwa.navigation.window.WindowController
|
||||
|
||||
@Stable
|
||||
class CharacterSheetCreateWindow(
|
||||
class CharacterSheetEditWindow(
|
||||
title: String,
|
||||
val sheetId: String?,
|
||||
) : Window(
|
||||
|
|
@ -15,4 +16,16 @@ class CharacterSheetCreateWindow(
|
|||
companion object {
|
||||
val size = DpSize(600.dp, 900.dp)
|
||||
}
|
||||
}
|
||||
|
||||
fun WindowController.navigateToCharacterSheetEdit(
|
||||
title: String,
|
||||
characterId: String?,
|
||||
) {
|
||||
showWindow(
|
||||
window = CharacterSheetEditWindow(
|
||||
title = title,
|
||||
sheetId = characterId,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
@ -3,13 +3,14 @@ package com.pixelized.desktop.lwa.navigation.window.destination
|
|||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.ui.unit.DpSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.pixelized.desktop.lwa.navigation.window.WindowController
|
||||
|
||||
@Stable
|
||||
class CharacterSheetWindow(
|
||||
title: String,
|
||||
val characterId: String,
|
||||
characterName: String,
|
||||
) : Window(
|
||||
title = characterName,
|
||||
title = title,
|
||||
size = size,
|
||||
) {
|
||||
companion object {
|
||||
|
|
@ -20,3 +21,14 @@ class CharacterSheetWindow(
|
|||
}
|
||||
}
|
||||
|
||||
fun WindowController.navigateToCharacterSheet(
|
||||
title: String,
|
||||
characterId: String,
|
||||
) {
|
||||
showWindow(
|
||||
window = CharacterSheetWindow(
|
||||
title = title,
|
||||
characterId = characterId,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.pixelized.desktop.lwa.navigation.window.destination
|
||||
|
||||
import androidx.compose.ui.unit.DpSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.pixelized.desktop.lwa.navigation.window.WindowController
|
||||
|
||||
class RollHistoryWindow: Window(
|
||||
title = "",
|
||||
size = size,
|
||||
) {
|
||||
companion object {
|
||||
val size = DpSize(
|
||||
width = 400.dp + 64.dp,
|
||||
height = 900.dp,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun WindowController.navigateToRollHistory() {
|
||||
showWindow(window = RollHistoryWindow())
|
||||
}
|
||||
|
|
@ -61,7 +61,7 @@ import com.pixelized.desktop.lwa.composable.tooltip.TooltipLayout
|
|||
import com.pixelized.desktop.lwa.composable.tooltip.TooltipUio
|
||||
import com.pixelized.desktop.lwa.navigation.screen.LocalScreenController
|
||||
import com.pixelized.desktop.lwa.navigation.window.LocalWindow
|
||||
import com.pixelized.desktop.lwa.navigation.window.destination.CharacterSheetCreateWindow
|
||||
import com.pixelized.desktop.lwa.navigation.window.destination.navigateToCharacterSheetEdit
|
||||
import com.pixelized.desktop.lwa.screen.characterSheet.detail.dialog.CharacterSheetDeleteConfirmationDialog
|
||||
import com.pixelized.desktop.lwa.screen.characterSheet.detail.dialog.CharacterSheetStatDialog
|
||||
import com.pixelized.desktop.lwa.screen.characterSheet.detail.dialog.DiminishedStatDialog
|
||||
|
|
@ -148,11 +148,9 @@ fun CharacterSheetPage(
|
|||
}
|
||||
},
|
||||
onEdit = {
|
||||
windowController.showWindow(
|
||||
window = CharacterSheetCreateWindow(
|
||||
title = runBlocking { getString(Res.string.character_sheet_edit__edit__title) },
|
||||
sheetId = sheet.id,
|
||||
),
|
||||
windowController.navigateToCharacterSheetEdit(
|
||||
title = runBlocking { getString(Res.string.character_sheet_edit__edit__title) },
|
||||
characterId = sheet.id,
|
||||
)
|
||||
},
|
||||
onDelete = {
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ import androidx.compose.ui.unit.dp
|
|||
import com.pixelized.desktop.lwa.LocalWindowController
|
||||
import com.pixelized.desktop.lwa.navigation.screen.LocalScreenController
|
||||
import com.pixelized.desktop.lwa.navigation.screen.destination.navigateToNetwork
|
||||
import com.pixelized.desktop.lwa.navigation.screen.destination.navigateToRollHistory
|
||||
import com.pixelized.desktop.lwa.navigation.window.destination.CharacterSheetCreateWindow
|
||||
import com.pixelized.desktop.lwa.navigation.window.destination.CharacterSheetWindow
|
||||
import com.pixelized.desktop.lwa.navigation.window.destination.navigateToCharacterSheet
|
||||
import com.pixelized.desktop.lwa.navigation.window.destination.navigateToCharacterSheetEdit
|
||||
import com.pixelized.desktop.lwa.navigation.window.destination.navigateToRollHistory
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import lwacharactersheet.composeapp.generated.resources.Res
|
||||
import lwacharactersheet.composeapp.generated.resources.character_sheet_edit__create__title
|
||||
|
|
@ -70,24 +70,21 @@ fun MainPage(
|
|||
) {
|
||||
MainPageContent(
|
||||
characters = viewModel.characters,
|
||||
enableRollHistory = viewModel.enableRollHistory,
|
||||
onCharacter = {
|
||||
window.showWindow(
|
||||
window = CharacterSheetWindow(
|
||||
characterId = it.id,
|
||||
characterName = it.name,
|
||||
)
|
||||
window.navigateToCharacterSheet(
|
||||
characterId = it.id,
|
||||
title = it.name,
|
||||
)
|
||||
},
|
||||
onCreateCharacter = {
|
||||
window.showWindow(
|
||||
window = CharacterSheetCreateWindow(
|
||||
title = runBlocking { getString(Res.string.character_sheet_edit__create__title) },
|
||||
sheetId = null,
|
||||
)
|
||||
window.navigateToCharacterSheetEdit(
|
||||
title = runBlocking { getString(Res.string.character_sheet_edit__create__title) },
|
||||
characterId = null,
|
||||
)
|
||||
},
|
||||
onRollHistory = {
|
||||
screen.navigateToRollHistory()
|
||||
window.navigateToRollHistory()
|
||||
},
|
||||
onOpenSaveDirectory = {
|
||||
viewModel.openSaveDirectory()
|
||||
|
|
@ -104,6 +101,7 @@ fun MainPage(
|
|||
fun MainPageContent(
|
||||
modifier: Modifier = Modifier,
|
||||
characters: State<List<CharacterUio>>,
|
||||
enableRollHistory: State<Boolean>,
|
||||
onCharacter: (CharacterUio) -> Unit,
|
||||
onCreateCharacter: () -> Unit,
|
||||
onRollHistory: () -> Unit,
|
||||
|
|
@ -173,6 +171,7 @@ fun MainPageContent(
|
|||
}
|
||||
|
||||
TextButton(
|
||||
enabled = enableRollHistory.value,
|
||||
onClick = onRollHistory,
|
||||
) {
|
||||
Row(
|
||||
|
|
|
|||
|
|
@ -1,31 +1,36 @@
|
|||
package com.pixelized.desktop.lwa.screen.main
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.lordcodes.turtle.shellRun
|
||||
import com.pixelized.desktop.lwa.repository.OperatingSystem
|
||||
import com.pixelized.desktop.lwa.repository.characterSheet.CharacterSheetRepository
|
||||
import com.pixelized.desktop.lwa.repository.network.NetworkRepository
|
||||
import com.pixelized.desktop.lwa.repository.storePath
|
||||
import com.pixelized.desktop.lwa.utils.extention.collectAsState
|
||||
|
||||
class MainPageViewModel(
|
||||
private val repository: CharacterSheetRepository
|
||||
repository: CharacterSheetRepository,
|
||||
networkRepository: NetworkRepository,
|
||||
) : ViewModel() {
|
||||
|
||||
private val charactersFlow = repository.characterSheetFlow()
|
||||
val characters: State<List<CharacterUio>>
|
||||
@Composable
|
||||
@Stable
|
||||
get() = repository
|
||||
.characterSheetFlow()
|
||||
.collectAsState { sheets ->
|
||||
sheets.map { sheet ->
|
||||
CharacterUio(
|
||||
id = sheet.id,
|
||||
name = sheet.name,
|
||||
)
|
||||
}
|
||||
get() = charactersFlow.collectAsState { sheets ->
|
||||
sheets.map { sheet ->
|
||||
CharacterUio(
|
||||
id = sheet.id,
|
||||
name = sheet.name,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private val networkStatus = networkRepository.status
|
||||
val enableRollHistory: State<Boolean>
|
||||
@Composable
|
||||
get() = networkStatus.collectAsState { it == NetworkRepository.Status.CONNECTED }
|
||||
|
||||
fun openSaveDirectory(
|
||||
os: OperatingSystem = OperatingSystem.current
|
||||
|
|
|
|||
|
|
@ -48,11 +48,15 @@ fun RollHistoryItem(
|
|||
modifier = Modifier.alignByBaseline(),
|
||||
style = MaterialTheme.typography.body1,
|
||||
fontWeight = FontWeight.Bold,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1,
|
||||
text = roll.from,
|
||||
)
|
||||
Text(
|
||||
modifier = Modifier.alignByBaseline(),
|
||||
style = MaterialTheme.typography.caption,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1,
|
||||
text = stringResource(Res.string.roll_history__item__throw),
|
||||
)
|
||||
Text(
|
||||
|
|
@ -69,14 +73,20 @@ fun RollHistoryItem(
|
|||
roll.rollDifficulty?.let {
|
||||
Text(
|
||||
style = MaterialTheme.typography.caption,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1,
|
||||
text = stringResource(Res.string.roll_history__item__difficulty),
|
||||
)
|
||||
Text(
|
||||
style = MaterialTheme.typography.caption,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1,
|
||||
text = it,
|
||||
)
|
||||
Text(
|
||||
style = MaterialTheme.typography.caption,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1,
|
||||
text = "-",
|
||||
)
|
||||
}
|
||||
|
|
@ -84,6 +94,8 @@ fun RollHistoryItem(
|
|||
Text(
|
||||
style = MaterialTheme.typography.caption,
|
||||
fontWeight = FontWeight.Bold,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1,
|
||||
text = it,
|
||||
)
|
||||
}
|
||||
|
|
@ -96,6 +108,8 @@ fun RollHistoryItem(
|
|||
modifier = Modifier.alignByBaseline(),
|
||||
style = MaterialTheme.typography.h5,
|
||||
fontWeight = FontWeight.Bold,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1,
|
||||
text = "${roll.rollValue}",
|
||||
)
|
||||
roll.rollSuccessLimit?.let {
|
||||
|
|
@ -103,6 +117,8 @@ fun RollHistoryItem(
|
|||
modifier = Modifier.alignByBaseline(),
|
||||
style = MaterialTheme.typography.caption,
|
||||
fontWeight = FontWeight.Light,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1,
|
||||
text = "/ $it",
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,43 +7,31 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
|||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.material.Icon
|
||||
import androidx.compose.material.IconButton
|
||||
import androidx.compose.material.Scaffold
|
||||
import androidx.compose.material.Surface
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.TopAppBar
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.pixelized.desktop.lwa.navigation.screen.LocalScreenController
|
||||
import lwacharactersheet.composeapp.generated.resources.Res
|
||||
import lwacharactersheet.composeapp.generated.resources.roll_history__title
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
import org.koin.compose.viewmodel.koinViewModel
|
||||
import org.koin.core.annotation.KoinExperimentalAPI
|
||||
|
||||
|
||||
@OptIn(KoinExperimentalAPI::class)
|
||||
@Composable
|
||||
fun RollHistoryPage(
|
||||
viewModel: RollHistoryViewModel = koinViewModel(),
|
||||
) {
|
||||
val screen = LocalScreenController.current
|
||||
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
) {
|
||||
RollHistoryContent(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
rolls = viewModel.rolls,
|
||||
onBack = {
|
||||
screen.popBackStack()
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -52,7 +40,6 @@ fun RollHistoryPage(
|
|||
private fun RollHistoryContent(
|
||||
modifier: Modifier = Modifier,
|
||||
rolls: State<List<RollHistoryItemUio>>,
|
||||
onBack: () -> Unit,
|
||||
) {
|
||||
Scaffold(
|
||||
modifier = modifier,
|
||||
|
|
@ -65,16 +52,6 @@ private fun RollHistoryContent(
|
|||
text = stringResource(Res.string.roll_history__title),
|
||||
)
|
||||
},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = onBack,
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
content = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue