|
|
@ -1,5 +1,6 @@ |
|
|
|
package at.xaxa.demonstrator2.ui |
|
|
|
package at.xaxa.demonstrator2.ui |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.compose.foundation.layout.Arrangement |
|
|
|
import androidx.compose.foundation.layout.Box |
|
|
|
import androidx.compose.foundation.layout.Box |
|
|
|
import androidx.compose.foundation.layout.Column |
|
|
|
import androidx.compose.foundation.layout.Column |
|
|
|
import androidx.compose.foundation.layout.Row |
|
|
|
import androidx.compose.foundation.layout.Row |
|
|
@ -14,26 +15,34 @@ import androidx.compose.material.icons.Icons |
|
|
|
import androidx.compose.material.icons.automirrored.filled.List |
|
|
|
import androidx.compose.material.icons.automirrored.filled.List |
|
|
|
import androidx.compose.material.icons.filled.Add |
|
|
|
import androidx.compose.material.icons.filled.Add |
|
|
|
import androidx.compose.material.icons.outlined.Edit |
|
|
|
import androidx.compose.material.icons.outlined.Edit |
|
|
|
|
|
|
|
import androidx.compose.material3.FilledTonalButton |
|
|
|
import androidx.compose.material3.Icon |
|
|
|
import androidx.compose.material3.Icon |
|
|
|
import androidx.compose.material3.IconButton |
|
|
|
import androidx.compose.material3.IconButton |
|
|
|
import androidx.compose.material3.NavigationBarItem |
|
|
|
import androidx.compose.material3.NavigationBarItem |
|
|
|
|
|
|
|
import androidx.compose.material3.OutlinedButton |
|
|
|
import androidx.compose.material3.OutlinedCard |
|
|
|
import androidx.compose.material3.OutlinedCard |
|
|
|
|
|
|
|
import androidx.compose.material3.OutlinedTextField |
|
|
|
import androidx.compose.material3.Scaffold |
|
|
|
import androidx.compose.material3.Scaffold |
|
|
|
import androidx.compose.material3.Text |
|
|
|
import androidx.compose.material3.Text |
|
|
|
import androidx.compose.runtime.Composable |
|
|
|
import androidx.compose.runtime.Composable |
|
|
|
import androidx.compose.runtime.getValue |
|
|
|
import androidx.compose.runtime.getValue |
|
|
|
|
|
|
|
import androidx.compose.runtime.mutableStateOf |
|
|
|
|
|
|
|
import androidx.compose.runtime.remember |
|
|
|
|
|
|
|
import androidx.compose.runtime.setValue |
|
|
|
import androidx.compose.ui.Alignment |
|
|
|
import androidx.compose.ui.Alignment |
|
|
|
import androidx.compose.ui.Modifier |
|
|
|
import androidx.compose.ui.Modifier |
|
|
|
import androidx.compose.ui.tooling.preview.Preview |
|
|
|
import androidx.compose.ui.tooling.preview.Preview |
|
|
|
import androidx.compose.ui.unit.dp |
|
|
|
import androidx.compose.ui.unit.dp |
|
|
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle |
|
|
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle |
|
|
|
import androidx.lifecycle.viewmodel.compose.viewModel |
|
|
|
import androidx.lifecycle.viewmodel.compose.viewModel |
|
|
|
|
|
|
|
import androidx.navigation.NavHostController |
|
|
|
import androidx.navigation.NavType |
|
|
|
import androidx.navigation.NavType |
|
|
|
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.compose.rememberNavController |
|
|
|
import androidx.navigation.compose.rememberNavController |
|
|
|
import androidx.navigation.navArgument |
|
|
|
import androidx.navigation.navArgument |
|
|
|
|
|
|
|
import androidx.room.util.TableInfo |
|
|
|
import at.xaxa.demonstrator2.data.Task |
|
|
|
import at.xaxa.demonstrator2.data.Task |
|
|
|
import at.xaxa.demonstrator2.ui.edit.TaskEditScreen |
|
|
|
import at.xaxa.demonstrator2.ui.edit.TaskEditScreen |
|
|
|
import at.xaxa.demonstrator2.ui.theme.Typography |
|
|
|
import at.xaxa.demonstrator2.ui.theme.Typography |
|
|
@ -79,7 +88,7 @@ fun DemoApp(modifier: Modifier = Modifier) { |
|
|
|
navController.navigate(DemoRoutes.Detail.route.replace("{taskId}", "$it")) |
|
|
|
navController.navigate(DemoRoutes.Detail.route.replace("{taskId}", "$it")) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
composable(DemoRoutes.Add.route) { AddScreen() } |
|
|
|
composable(DemoRoutes.Add.route) { AddScreen(navController = navController) } |
|
|
|
composable( |
|
|
|
composable( |
|
|
|
route = DemoRoutes.Detail.route, |
|
|
|
route = DemoRoutes.Detail.route, |
|
|
|
arguments = listOf(navArgument("taskId") { |
|
|
|
arguments = listOf(navArgument("taskId") { |
|
|
@ -107,7 +116,7 @@ fun ListScreen( |
|
|
|
modifier: Modifier = Modifier, |
|
|
|
modifier: Modifier = Modifier, |
|
|
|
demoViewModel: DemoViewModel = viewModel(factory = AppViewModelProvider.Factory), |
|
|
|
demoViewModel: DemoViewModel = viewModel(factory = AppViewModelProvider.Factory), |
|
|
|
onEditClick: (Int) -> Unit, |
|
|
|
onEditClick: (Int) -> Unit, |
|
|
|
onCardClick: (Int) -> Unit |
|
|
|
onCardClick: (Int) -> Unit, |
|
|
|
) { |
|
|
|
) { |
|
|
|
Box(Modifier.fillMaxSize()) { |
|
|
|
Box(Modifier.fillMaxSize()) { |
|
|
|
val state by demoViewModel.taskUiState.collectAsStateWithLifecycle(); |
|
|
|
val state by demoViewModel.taskUiState.collectAsStateWithLifecycle(); |
|
|
@ -126,7 +135,7 @@ fun ListScreen( |
|
|
|
|
|
|
|
|
|
|
|
@Composable |
|
|
|
@Composable |
|
|
|
fun TaskDetailsScreen(modifier: Modifier = Modifier, demoDetailsViewModel: DemoDetailsViewModel = viewModel(factory = AppViewModelProvider.Factory)) { |
|
|
|
fun TaskDetailsScreen(modifier: Modifier = Modifier, demoDetailsViewModel: DemoDetailsViewModel = viewModel(factory = AppViewModelProvider.Factory)) { |
|
|
|
val detailUiState by demoDetailsViewModel.detailUiState.collectAsStateWithLifecycle() |
|
|
|
val detailUiState by demoDetailsViewModel.taskUiState.collectAsStateWithLifecycle() |
|
|
|
|
|
|
|
|
|
|
|
TaskDetails(detailUiState.task, modifier) |
|
|
|
TaskDetails(detailUiState.task, modifier) |
|
|
|
} |
|
|
|
} |
|
|
@ -148,9 +157,52 @@ fun TaskDetails(task: Task, modifier: Modifier = Modifier) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Composable |
|
|
|
@Composable |
|
|
|
fun AddScreen() { |
|
|
|
fun AddScreen( |
|
|
|
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { |
|
|
|
//task: Task, |
|
|
|
|
|
|
|
modifier: Modifier = Modifier, |
|
|
|
|
|
|
|
demoViewModel: DemoViewModel = viewModel(factory = AppViewModelProvider.Factory), |
|
|
|
|
|
|
|
navController: NavHostController |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
var taskText by remember { mutableStateOf("") } |
|
|
|
|
|
|
|
var descText by remember { mutableStateOf("") } |
|
|
|
|
|
|
|
val state by demoViewModel.taskUiState.collectAsStateWithLifecycle() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Column(Modifier.fillMaxSize().padding(8.dp)) { |
|
|
|
Text("Add Screen") |
|
|
|
Text("Add Screen") |
|
|
|
|
|
|
|
OutlinedTextField( |
|
|
|
|
|
|
|
value = taskText, |
|
|
|
|
|
|
|
modifier = Modifier.fillMaxWidth(), |
|
|
|
|
|
|
|
label = { Text("Task") }, |
|
|
|
|
|
|
|
onValueChange = { |
|
|
|
|
|
|
|
taskText = it |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
OutlinedTextField( |
|
|
|
|
|
|
|
value = descText, |
|
|
|
|
|
|
|
modifier = Modifier.fillMaxWidth(), |
|
|
|
|
|
|
|
label = { Text("Description") }, |
|
|
|
|
|
|
|
onValueChange = { |
|
|
|
|
|
|
|
descText = it |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(4.dp)) { |
|
|
|
|
|
|
|
OutlinedButton( |
|
|
|
|
|
|
|
modifier = Modifier.fillMaxWidth(0.5f), |
|
|
|
|
|
|
|
onClick = { |
|
|
|
|
|
|
|
taskText = "" |
|
|
|
|
|
|
|
descText = "" |
|
|
|
|
|
|
|
}) { |
|
|
|
|
|
|
|
Text("Reset") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
FilledTonalButton( |
|
|
|
|
|
|
|
modifier = Modifier.fillMaxWidth(), |
|
|
|
|
|
|
|
onClick = { |
|
|
|
|
|
|
|
demoViewModel.onAddButtonClicked(Task(0, taskText, descText)) |
|
|
|
|
|
|
|
navController.navigate(DemoRoutes.List.route) |
|
|
|
|
|
|
|
}) { |
|
|
|
|
|
|
|
Text("Save") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|