начало фрагмента редактирования текста

This commit is contained in:
Пытков Роман
2025-01-28 17:23:09 +03:00
parent eba0d0e3cb
commit e1e7b48989
6 changed files with 49 additions and 15 deletions

View File

@@ -25,7 +25,6 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.toRoute
import com.github.nullptroma.wallenc.presentation.navigation.NavBarItemData import com.github.nullptroma.wallenc.presentation.navigation.NavBarItemData
import com.github.nullptroma.wallenc.presentation.navigation.rememberNavigationState import com.github.nullptroma.wallenc.presentation.navigation.rememberNavigationState
import com.github.nullptroma.wallenc.presentation.screens.main.MainRoute import com.github.nullptroma.wallenc.presentation.screens.main.MainRoute
@@ -90,7 +89,7 @@ fun WallencNavRoot(viewModel: WallencViewModel = hiltViewModel()) {
var route = topLevelRoutes[navBarItemData.screenRouteClass] var route = topLevelRoutes[navBarItemData.screenRouteClass]
if (route == null) if (route == null)
throw NullPointerException("Route $route not found") throw NullPointerException("Route $route not found")
if (currentRoute?.startsWith(routeClassName) != true) navState.navigationTo( if (currentRoute?.startsWith(routeClassName) != true) navState.changeTop(
route route
) )
}) })

View File

@@ -11,13 +11,19 @@ import com.github.nullptroma.wallenc.presentation.screens.ScreenRoute
class NavigationState( class NavigationState(
val navHostController: NavHostController val navHostController: NavHostController
) { ) {
fun navigationTo(route: ScreenRoute) { fun changeTop(route: ScreenRoute) {
navHostController.navigate(route) { navHostController.navigate(route) {
popUpTo(navHostController.graph.findStartDestination().id) popUpTo(navHostController.graph.findStartDestination().id)
launchSingleTop = true launchSingleTop = true
restoreState = true restoreState = true
} }
} }
fun push(route: ScreenRoute) {
navHostController.navigate(route) {
restoreState = true
}
}
} }
@Composable @Composable

View File

@@ -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.RemoteVaultsRoute
import com.github.nullptroma.wallenc.presentation.screens.main.screens.remotes.RemoteVaultsScreen 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.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) @OptIn(ExperimentalMaterial3Api::class)
@@ -72,10 +74,10 @@ fun MainScreen(
icon = { Text(stringResource(navBarItemData.nameStringResourceId)) }, icon = { Text(stringResource(navBarItemData.nameStringResourceId)) },
selected = currentRoute?.startsWith(routeClassName) == true, selected = currentRoute?.startsWith(routeClassName) == true,
onClick = { onClick = {
var route = routes[navBarItemData.screenRouteClass] val route = routes[navBarItemData.screenRouteClass]
if (route == null) ?: throw NullPointerException("Route ${navBarItemData.screenRouteClass} not found")
throw NullPointerException("Route $route not found") if (currentRoute?.startsWith(routeClassName) != true)
if (currentRoute?.startsWith(routeClassName) != true) navState.navigationTo( navState.changeTop(
route route
) )
}) })
@@ -84,7 +86,6 @@ fun MainScreen(
HorizontalDivider() HorizontalDivider()
} }
}) { innerPaddings -> }) { innerPaddings ->
NavHost( NavHost(
navState.navHostController, navState.navHostController,
startDestination = routes[LocalVaultRoute::class.qualifiedName]!! startDestination = routes[LocalVaultRoute::class.qualifiedName]!!
@@ -98,7 +99,9 @@ fun MainScreen(
LocalVaultScreen( LocalVaultScreen(
modifier = Modifier.padding(innerPaddings), modifier = Modifier.padding(innerPaddings),
viewModel = localVaultViewModel viewModel = localVaultViewModel
) ) { text ->
navState.push(TextEditRoute(text))
}
} }
composable<RemoteVaultsRoute>(enterTransition = { composable<RemoteVaultsRoute>(enterTransition = {
fadeIn(tween(200)) fadeIn(tween(200))
@@ -110,6 +113,10 @@ fun MainScreen(
viewModel = remoteVaultsViewModel viewModel = remoteVaultsViewModel
) )
} }
composable<TextEditRoute> {
val route: TextEditRoute = it.toRoute()
TextEditScreen(route.text)
}
} }
} }
} }

View File

@@ -53,7 +53,8 @@ import kotlin.random.Random
@Composable @Composable
fun LocalVaultScreen( fun LocalVaultScreen(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
viewModel: LocalVaultViewModel = hiltViewModel() viewModel: LocalVaultViewModel = hiltViewModel(),
openTextEdit: (String)->Unit
) { ) {
val uiState by viewModel.state.collectAsStateWithLifecycle() val uiState by viewModel.state.collectAsStateWithLifecycle()
@@ -68,14 +69,16 @@ fun LocalVaultScreen(
}) { innerPadding -> }) { innerPadding ->
LazyColumn(modifier = Modifier.padding(innerPadding)) { LazyColumn(modifier = Modifier.padding(innerPadding)) {
items(uiState.storagesList) { tree -> items(uiState.storagesList) { tree ->
Storage(Modifier.padding(8.dp), tree) Storage(Modifier.padding(8.dp), tree) {
openTextEdit(it.value.uuid.toString())
}
} }
} }
} }
} }
@Composable @Composable
fun Storage(modifier: Modifier, tree: Tree<IStorageInfo>) { fun Storage(modifier: Modifier, tree: Tree<IStorageInfo>, onClick: (Tree<IStorageInfo>) -> Unit) {
val cur = tree.value val cur = tree.value
val cardShape = RoundedCornerShape(30.dp) val cardShape = RoundedCornerShape(30.dp)
Column(modifier) { Column(modifier) {
@@ -84,6 +87,7 @@ fun Storage(modifier: Modifier, tree: Tree<IStorageInfo>) {
.fillMaxWidth() .fillMaxWidth()
.clip(cardShape) .clip(cardShape)
.clickable { .clickable {
onClick(tree)
//viewModel.printStorageInfoToLog(cur) //viewModel.printStorageInfoToLog(cur)
}, },
shape = cardShape, shape = cardShape,
@@ -123,7 +127,7 @@ fun Storage(modifier: Modifier, tree: Tree<IStorageInfo>) {
} }
} }
for(i in tree.children ?: listOf()) { 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)
} }
} }
} }

View File

@@ -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()

View File

@@ -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")
}