Compare commits

..

No commits in common. 'd18bc9f1e4ade9af1f8bdb807a01d160608abcb8' and '846aeb2ab1b16b7dfc100a7a6deff6c61e9e9f10' have entirely different histories.

  1. 4
      app/build.gradle.kts
  2. 2
      app/src/main/java/at/xaxa/demonstrator2/data/db/TaskDatabase.kt
  3. 2
      app/src/main/java/at/xaxa/demonstrator2/data/db/TaskEntity.kt
  4. 6
      app/src/main/java/at/xaxa/demonstrator2/ui/DemoDetailsViewModel.kt
  5. 62
      app/src/main/java/at/xaxa/demonstrator2/ui/DemoUI.kt
  6. 5
      app/src/main/java/at/xaxa/demonstrator2/ui/DemoViewModel.kt
  7. 4
      gradle/libs.versions.toml

4
app/build.gradle.kts

@ -51,8 +51,8 @@ android { @@ -51,8 +51,8 @@ android {
}
dependencies {
implementation ("androidx.room:room-runtime:2.5.0")
ksp ("androidx.room:room-compiler:2.6.1")
implementation (libs.androidx.room.runtime)
ksp (libs.androidx.room.compiler)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.material)

2
app/src/main/java/at/xaxa/demonstrator2/data/db/TaskDatabase.kt

@ -5,7 +5,7 @@ import androidx.room.Database @@ -5,7 +5,7 @@ import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
@Database(entities = [TaskEntity::class], version = 2)
@Database(entities = [TaskEntity::class], version = 1)
abstract class TaskDatabase : RoomDatabase() {
abstract fun TaskDao(): TaskDao

2
app/src/main/java/at/xaxa/demonstrator2/data/db/TaskEntity.kt

@ -5,7 +5,7 @@ import androidx.room.PrimaryKey @@ -5,7 +5,7 @@ import androidx.room.PrimaryKey
@Entity(tableName = "tasks")
data class TaskEntity(
@PrimaryKey(autoGenerate = true)
@PrimaryKey
val _id: Int = 0,
val name :String,
val details: String = "empty"

6
app/src/main/java/at/xaxa/demonstrator2/ui/DemoDetailsViewModel.kt

@ -20,15 +20,15 @@ class DemoDetailsViewModel(savedStateHandle: SavedStateHandle, private val taskR @@ -20,15 +20,15 @@ class DemoDetailsViewModel(savedStateHandle: SavedStateHandle, private val taskR
private val taskId: Int = checkNotNull(savedStateHandle["taskId"])
private val _taskUiState = MutableStateFlow(TaskDetailUi())
val taskUiState = _taskUiState.asStateFlow()
private val _detailUiState = MutableStateFlow(TaskDetailUi())
val detailUiState = _detailUiState.asStateFlow()
init {
viewModelScope.launch {
val task = withContext(Dispatchers.IO) {
taskRepository.getTaskById(taskId)
}
_taskUiState.update {
_detailUiState.update {
TaskDetailUi(task)
}
}

62
app/src/main/java/at/xaxa/demonstrator2/ui/DemoUI.kt

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

5
app/src/main/java/at/xaxa/demonstrator2/ui/DemoViewModel.kt

@ -2,7 +2,6 @@ package at.xaxa.demonstrator2.ui @@ -2,7 +2,6 @@ package at.xaxa.demonstrator2.ui
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import at.xaxa.demonstrator2.data.Task
import at.xaxa.demonstrator2.data.TaskRepository
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.map
@ -26,9 +25,9 @@ class DemoViewModel(val repository: TaskRepository) : ViewModel() { @@ -26,9 +25,9 @@ class DemoViewModel(val repository: TaskRepository) : ViewModel() {
initialValue = DemoUiState(emptyList())
)
fun onAddButtonClicked(task: Task) {
fun onAddButtonClicked() {
viewModelScope.launch {
repository.addTask(task)
repository.addRandomTask()
}
}
}

4
gradle/libs.versions.toml

@ -16,13 +16,17 @@ material3 = "1.2.0" @@ -16,13 +16,17 @@ material3 = "1.2.0"
navigationCompose = "2.8.4"
navigationComposeVersion = "2.7.2"
roomCommon = "2.6.1"
roomCompiler = "2.6.1"
roomKtx = "2.6.1"
roomRuntime = "2.5.0"
[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
androidx-material = { module = "androidx.compose.material:material", version.ref = "material" }
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigationCompose" }
androidx-navigation-compose-v272 = { module = "androidx.navigation:navigation-compose", version.ref = "navigationComposeVersion" }
androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "roomCompiler" }
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "roomRuntime" }
converter-kotlinx-serialization = { module = "com.squareup.retrofit2:converter-kotlinx-serialization", version.ref = "converterKotlinxSerialization" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }

Loading…
Cancel
Save