начало фрагмента редактирования текста
This commit is contained in:
@@ -25,7 +25,6 @@ import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
import androidx.navigation.toRoute
|
||||
import com.github.nullptroma.wallenc.presentation.navigation.NavBarItemData
|
||||
import com.github.nullptroma.wallenc.presentation.navigation.rememberNavigationState
|
||||
import com.github.nullptroma.wallenc.presentation.screens.main.MainRoute
|
||||
@@ -90,7 +89,7 @@ fun WallencNavRoot(viewModel: WallencViewModel = hiltViewModel()) {
|
||||
var route = topLevelRoutes[navBarItemData.screenRouteClass]
|
||||
if (route == null)
|
||||
throw NullPointerException("Route $route not found")
|
||||
if (currentRoute?.startsWith(routeClassName) != true) navState.navigationTo(
|
||||
if (currentRoute?.startsWith(routeClassName) != true) navState.changeTop(
|
||||
route
|
||||
)
|
||||
})
|
||||
|
||||
@@ -11,13 +11,19 @@ import com.github.nullptroma.wallenc.presentation.screens.ScreenRoute
|
||||
class NavigationState(
|
||||
val navHostController: NavHostController
|
||||
) {
|
||||
fun navigationTo(route: ScreenRoute) {
|
||||
fun changeTop(route: ScreenRoute) {
|
||||
navHostController.navigate(route) {
|
||||
popUpTo(navHostController.graph.findStartDestination().id)
|
||||
launchSingleTop = true
|
||||
restoreState = true
|
||||
}
|
||||
}
|
||||
|
||||
fun push(route: ScreenRoute) {
|
||||
navHostController.navigate(route) {
|
||||
restoreState = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
@@ -34,6 +34,8 @@ import com.github.nullptroma.wallenc.presentation.screens.main.screens.local.vau
|
||||
import com.github.nullptroma.wallenc.presentation.screens.main.screens.remotes.RemoteVaultsRoute
|
||||
import com.github.nullptroma.wallenc.presentation.screens.main.screens.remotes.RemoteVaultsScreen
|
||||
import com.github.nullptroma.wallenc.presentation.screens.main.screens.remotes.RemoteVaultsViewModel
|
||||
import com.github.nullptroma.wallenc.presentation.screens.shared.TextEditRoute
|
||||
import com.github.nullptroma.wallenc.presentation.screens.shared.TextEditScreen
|
||||
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@@ -72,19 +74,18 @@ fun MainScreen(
|
||||
icon = { Text(stringResource(navBarItemData.nameStringResourceId)) },
|
||||
selected = currentRoute?.startsWith(routeClassName) == true,
|
||||
onClick = {
|
||||
var route = routes[navBarItemData.screenRouteClass]
|
||||
if (route == null)
|
||||
throw NullPointerException("Route $route not found")
|
||||
if (currentRoute?.startsWith(routeClassName) != true) navState.navigationTo(
|
||||
route
|
||||
)
|
||||
val route = routes[navBarItemData.screenRouteClass]
|
||||
?: throw NullPointerException("Route ${navBarItemData.screenRouteClass} not found")
|
||||
if (currentRoute?.startsWith(routeClassName) != true)
|
||||
navState.changeTop(
|
||||
route
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
HorizontalDivider()
|
||||
}
|
||||
}) { innerPaddings ->
|
||||
|
||||
NavHost(
|
||||
navState.navHostController,
|
||||
startDestination = routes[LocalVaultRoute::class.qualifiedName]!!
|
||||
@@ -98,7 +99,9 @@ fun MainScreen(
|
||||
LocalVaultScreen(
|
||||
modifier = Modifier.padding(innerPaddings),
|
||||
viewModel = localVaultViewModel
|
||||
)
|
||||
) { text ->
|
||||
navState.push(TextEditRoute(text))
|
||||
}
|
||||
}
|
||||
composable<RemoteVaultsRoute>(enterTransition = {
|
||||
fadeIn(tween(200))
|
||||
@@ -110,6 +113,10 @@ fun MainScreen(
|
||||
viewModel = remoteVaultsViewModel
|
||||
)
|
||||
}
|
||||
composable<TextEditRoute> {
|
||||
val route: TextEditRoute = it.toRoute()
|
||||
TextEditScreen(route.text)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,8 @@ import kotlin.random.Random
|
||||
@Composable
|
||||
fun LocalVaultScreen(
|
||||
modifier: Modifier = Modifier,
|
||||
viewModel: LocalVaultViewModel = hiltViewModel()
|
||||
viewModel: LocalVaultViewModel = hiltViewModel(),
|
||||
openTextEdit: (String)->Unit
|
||||
) {
|
||||
|
||||
val uiState by viewModel.state.collectAsStateWithLifecycle()
|
||||
@@ -68,14 +69,16 @@ fun LocalVaultScreen(
|
||||
}) { innerPadding ->
|
||||
LazyColumn(modifier = Modifier.padding(innerPadding)) {
|
||||
items(uiState.storagesList) { tree ->
|
||||
Storage(Modifier.padding(8.dp), tree)
|
||||
Storage(Modifier.padding(8.dp), tree) {
|
||||
openTextEdit(it.value.uuid.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Storage(modifier: Modifier, tree: Tree<IStorageInfo>) {
|
||||
fun Storage(modifier: Modifier, tree: Tree<IStorageInfo>, onClick: (Tree<IStorageInfo>) -> Unit) {
|
||||
val cur = tree.value
|
||||
val cardShape = RoundedCornerShape(30.dp)
|
||||
Column(modifier) {
|
||||
@@ -84,6 +87,7 @@ fun Storage(modifier: Modifier, tree: Tree<IStorageInfo>) {
|
||||
.fillMaxWidth()
|
||||
.clip(cardShape)
|
||||
.clickable {
|
||||
onClick(tree)
|
||||
//viewModel.printStorageInfoToLog(cur)
|
||||
},
|
||||
shape = cardShape,
|
||||
@@ -123,7 +127,7 @@ fun Storage(modifier: Modifier, tree: Tree<IStorageInfo>) {
|
||||
}
|
||||
}
|
||||
for(i in tree.children ?: listOf()) {
|
||||
Storage(Modifier.padding(16.dp,0.dp,0.dp,0.dp), i)
|
||||
Storage(Modifier.padding(16.dp,0.dp,0.dp,0.dp), i, onClick)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.github.nullptroma.wallenc.presentation.screens.shared
|
||||
|
||||
import com.github.nullptroma.wallenc.presentation.screens.ScreenRoute
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@Parcelize
|
||||
data class TextEditRoute(val text: String): ScreenRoute()
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.github.nullptroma.wallenc.presentation.screens.shared
|
||||
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
@Composable
|
||||
fun TextEditScreen(text: String) {
|
||||
Text("Hello from TextEdit with text $text")
|
||||
}
|
||||
Reference in New Issue
Block a user