Add the search feature inside the character sheet.

This commit is contained in:
Thomas Andres Gomez 2023-11-21 15:10:06 +01:00
parent 719ebd4c5e
commit 2eff9f8e2f
3 changed files with 62 additions and 24 deletions

View file

@ -6,8 +6,6 @@ import android.content.res.Configuration
import androidx.activity.compose.BackHandler
import androidx.annotation.StringRes
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
@ -24,12 +22,15 @@ import androidx.compose.material.ModalBottomSheetLayout
import androidx.compose.material.ModalBottomSheetState
import androidx.compose.material.ModalBottomSheetValue
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.pullrefresh.PullRefreshState
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.material.rememberModalBottomSheetState
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
@ -40,7 +41,6 @@ import androidx.compose.material3.Surface
import androidx.compose.material3.Tab
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.minimumInteractiveComponentSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.State
@ -53,7 +53,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
@ -67,6 +66,7 @@ import com.pixelized.rplexicon.ui.composable.Loader
import com.pixelized.rplexicon.ui.composable.edit.HandleHitPointEditDialog
import com.pixelized.rplexicon.ui.composable.error.HandleFetchError
import com.pixelized.rplexicon.ui.navigation.LocalScreenNavHost
import com.pixelized.rplexicon.ui.navigation.screens.navigateToSearch
import com.pixelized.rplexicon.ui.screens.character.CharacterTabUio.Action
import com.pixelized.rplexicon.ui.screens.character.CharacterTabUio.Alteration
import com.pixelized.rplexicon.ui.screens.character.CharacterTabUio.Inventory
@ -131,10 +131,11 @@ fun CharacterSheetScreen(
)
val refresh = rememberPullRefreshState(
refreshing = false,
onRefresh = { scope.launch { viewModel.update(force = true) } },
onRefresh = { scope.launch { viewModel.update(force = true, full = false) } },
)
val tabs = rememberHeaderTabsState()
val pagerState = rememberPagerState { tabs.value.size }
val isMenuExpended = remember { mutableStateOf(false) }
Surface(
modifier = Modifier.fillMaxSize(),
@ -144,6 +145,7 @@ fun CharacterSheetScreen(
pagerState = pagerState,
sheetState = sheetState,
refreshState = refresh,
isMenuExpended = isMenuExpended,
name = viewModel.character,
tabs = tabs,
header = headerViewModel.header,
@ -160,8 +162,14 @@ fun CharacterSheetScreen(
},
onDeathSuccess = headerViewModel::onDeathSuccess,
onDeathFailure = headerViewModel::onDeathFailure,
onRefresh = {
scope.launch { viewModel.update(force = true) }
onMenuRequest = { isMenuExpended.value = it },
onSearch = {
screen.navigateToSearch(
enableLexicon = true,
enableQuests = true,
enableLocations = true,
enableSpells = true,
)
},
onFullRefresh = {
scope.launch { viewModel.update(force = true, full = true) }
@ -241,7 +249,9 @@ private fun CharacterSheetContent(
pagerState: PagerState,
sheetState: ModalBottomSheetState,
refreshState: PullRefreshState,
onRefresh: () -> Unit,
isMenuExpended: State<Boolean>,
onMenuRequest: (Boolean) -> Unit,
onSearch: () -> Unit,
onFullRefresh: () -> Unit,
name: String,
tabs: State<List<CharacterTabUio>>,
@ -274,22 +284,46 @@ private fun CharacterSheetContent(
}
},
actions = {
Box(
modifier = Modifier
.minimumInteractiveComponentSize()
.combinedClickable(
onClick = onRefresh,
onLongClick = onFullRefresh,
role = Role.Button,
interactionSource = remember { MutableInteractionSource() },
indication = rememberRipple(bounded = false)
),
contentAlignment = Alignment.Center
IconButton(onClick = { onMenuRequest(!isMenuExpended.value) }) {
Icon(
imageVector = Icons.Filled.MoreVert,
contentDescription = "More",
)
}
DropdownMenu(
expanded = isMenuExpended.value,
onDismissRequest = { onMenuRequest(false) },
) {
DropdownMenuItem(
leadingIcon = {
Icon(
imageVector = Icons.Default.Search,
contentDescription = null,
)
},
text = {
Text(text = stringResource(id = R.string.search_field_title))
},
onClick = {
onMenuRequest(false)
onSearch()
},
)
DropdownMenuItem(
leadingIcon = {
Icon(
imageVector = Icons.Default.Refresh,
contentDescription = null,
)
},
text = {
Text(text = stringResource(id = R.string.character_sheet_refresh_label))
},
onClick = {
onMenuRequest(false)
onFullRefresh()
},
)
}
},
title = {
@ -456,9 +490,11 @@ private fun CharacterScreenPreview(
name = "Brulkhai",
header = rememberCharacterHeaderStatePreview(),
tabs = rememberHeaderPreview(),
isMenuExpended = remember { mutableStateOf(false) },
onMenuRequest = { },
onBack = { },
onTab = { },
onRefresh = { },
onSearch = { },
onFullRefresh = { },
loader = { },
onHitPoint = { },

View file

@ -78,6 +78,7 @@
<string name="map_destination">Destinations :</string>
<string name="map_illustrations">Illustrations :</string>
<string name="character_sheet_refresh_label">Rafraichir</string>
<string name="character_sheet_tab_proficiency">Talents</string>
<string name="character_sheet_tab_inventory">Inventaire</string>
<string name="character_sheet_tab_alteration">Altérations</string>

View file

@ -86,6 +86,7 @@
<string name="map_destination">Destinations:</string>
<string name="map_illustrations">Illustrations:</string>
<string name="character_sheet_refresh_label">Refresh</string>
<string name="character_sheet_tab_proficiency">Proficiencies</string>
<string name="character_sheet_tab_inventory">Inventory</string>
<string name="character_sheet_tab_alteration">Alterations</string>