ADD: Breadcrumbs + navigation with "Zurücktaste"
This commit is contained in:
parent
a61493c272
commit
828a4e0fd3
@ -4,7 +4,7 @@
|
||||
<selectionStates>
|
||||
<SelectionState runConfigName="app">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
<DropdownSelection timestamp="2025-05-03T08:34:29.354537334Z">
|
||||
<DropdownSelection timestamp="2025-05-10T09:28:03.000292036Z">
|
||||
<Target type="DEFAULT_BOOT">
|
||||
<handle>
|
||||
<DeviceId pluginId="PhysicalDevice" identifier="serial=R52N50NLGRT" />
|
||||
|
@ -1,11 +1,14 @@
|
||||
package come.stormborntales.notevault.ui.screens
|
||||
|
||||
import android.util.Log
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.wrapContentWidth
|
||||
@ -37,6 +40,7 @@ import androidx.lifecycle.ViewModelStoreOwner
|
||||
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import come.stormborntales.notevault.data.local.AppDatabase
|
||||
import come.stormborntales.notevault.data.local.entity.NoteCollection
|
||||
import come.stormborntales.notevault.data.repository.CollectionRepository
|
||||
import come.stormborntales.notevault.data.repository.NoteRepository
|
||||
import come.stormborntales.notevault.ui.viewmodel.NoteBrowserViewModel
|
||||
@ -97,6 +101,39 @@ fun CreateCollectionDialog(
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun CollectionBreadcrumbs(
|
||||
path: List<NoteCollection>,
|
||||
onNavigateTo: (index: Int) -> Unit
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = "Start",
|
||||
modifier = Modifier
|
||||
.clickable { onNavigateTo(-1) }
|
||||
.padding(horizontal = 4.dp),
|
||||
style = MaterialTheme.typography.labelLarge
|
||||
)
|
||||
|
||||
path.forEachIndexed { index, collection ->
|
||||
Text(" / ", style = MaterialTheme.typography.labelLarge)
|
||||
Text(
|
||||
text = collection.name,
|
||||
modifier = Modifier
|
||||
.clickable { onNavigateTo(index) }
|
||||
.padding(horizontal = 4.dp),
|
||||
style = MaterialTheme.typography.labelLarge
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
fun NotesScreen(
|
||||
collectionRepository: CollectionRepository,
|
||||
@ -145,6 +182,19 @@ fun NotesScreen(
|
||||
}
|
||||
},
|
||||
content = { innerPadding ->
|
||||
|
||||
val path by viewModel.pathStack.collectAsState()
|
||||
BackHandler(enabled = path.isNotEmpty()) {
|
||||
viewModel.navigateUp()
|
||||
}
|
||||
CollectionBreadcrumbs(
|
||||
path = path,
|
||||
onNavigateTo = { index ->
|
||||
if (index == -1) viewModel.loadContentForParent(null)
|
||||
else viewModel.navigateToLevel(index)
|
||||
}
|
||||
)
|
||||
|
||||
LazyColumn(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
@ -162,7 +212,7 @@ fun NotesScreen(
|
||||
ListItem(
|
||||
headlineContent = { Text(collection.name) },
|
||||
modifier = Modifier
|
||||
.clickable { viewModel.loadContentForParent(collection.id) }
|
||||
.clickable { viewModel.loadContentForParent(collection.id, collection) }
|
||||
.padding(horizontal = 8.dp)
|
||||
)
|
||||
}
|
||||
|
@ -24,11 +24,14 @@ class NoteBrowserViewModel (
|
||||
private val _currentParentId = MutableStateFlow<Int?>(null)
|
||||
val currentParentId: StateFlow<Int?> = _currentParentId.asStateFlow()
|
||||
|
||||
private val _pathStack = MutableStateFlow<List<NoteCollection>>(emptyList())
|
||||
val pathStack: StateFlow<List<NoteCollection>> = _pathStack.asStateFlow()
|
||||
|
||||
init {
|
||||
loadContentForParent(null)
|
||||
}
|
||||
|
||||
fun loadContentForParent(parentId: Int?) {
|
||||
fun loadContentForParent(parentId: Int?, selectedCollection: NoteCollection? = null) {
|
||||
_currentParentId.value = parentId
|
||||
viewModelScope.launch {
|
||||
launch {
|
||||
@ -41,6 +44,11 @@ class NoteBrowserViewModel (
|
||||
_currentNotes.value = it
|
||||
}
|
||||
}
|
||||
if (selectedCollection != null) {
|
||||
_pathStack.value = _pathStack.value + selectedCollection
|
||||
} else if (parentId == null) {
|
||||
_pathStack.value = emptyList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,4 +59,18 @@ class NoteBrowserViewModel (
|
||||
loadContentForParent(_currentParentId.value)
|
||||
}
|
||||
}
|
||||
|
||||
fun navigateToLevel(index: Int) {
|
||||
val newStack = _pathStack.value.take(index + 1)
|
||||
_pathStack.value = newStack
|
||||
val newParent = newStack.lastOrNull()?.id
|
||||
loadContentForParent(newParent)
|
||||
}
|
||||
|
||||
fun navigateUp() {
|
||||
val newStack = _pathStack.value.dropLast(1)
|
||||
_pathStack.value = newStack
|
||||
val newParentId = newStack.lastOrNull()?.id
|
||||
loadContentForParent(newParentId)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user