diff --git a/app/src/main/java/com/example/todolisttask/composeui/EditTask.kt b/app/src/main/java/com/example/todolisttask/composeui/EditTask.kt index bbf8741..26fb033 100644 --- a/app/src/main/java/com/example/todolisttask/composeui/EditTask.kt +++ b/app/src/main/java/com/example/todolisttask/composeui/EditTask.kt @@ -88,4 +88,4 @@ fun EditTask(navController: NavController, authViewModel: AuthViewModel, taskVie } } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/example/todolisttask/composeui/Home.kt b/app/src/main/java/com/example/todolisttask/composeui/Home.kt index 7902287..555f7af 100644 --- a/app/src/main/java/com/example/todolisttask/composeui/Home.kt +++ b/app/src/main/java/com/example/todolisttask/composeui/Home.kt @@ -1,3 +1,4 @@ +*/ package com.example.todolisttask.composeui import android.annotation.SuppressLint @@ -41,4 +42,4 @@ fun Home(navController: NavController, authViewModel: AuthViewModel, taskViewMod TaskList(navController, authViewModel, taskViewModel, userViewModel, authViewModel.currentUser?.id ?: -1) } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/example/todolisttask/models/composeui/UserList.kt b/app/src/main/java/com/example/todolisttask/models/composeui/UserList.kt new file mode 100644 index 0000000..91f0c8a --- /dev/null +++ b/app/src/main/java/com/example/todolisttask/models/composeui/UserList.kt @@ -0,0 +1,55 @@ +package com.example.todolisttask.models.composeui + +import android.content.res.Configuration +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Button +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.key +import androidx.compose.runtime.mutableStateListOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.navigation.NavController +import com.example.todolisttask.AppDatabase +import com.example.todolisttask.composeui.navigation.Screen +import com.example.todolisttask.models.model.Task +import com.example.todolisttask.models.model.User +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + +@Composable +fun UserList(navController: NavController?) { + val context = LocalContext.current + val users = remember { mutableStateListOf() } + + LaunchedEffect(Unit) { + withContext(Dispatchers.IO) { + val userList = AppDatabase.getInstance(context).userDao().getAll() + users.clear() + users.add(userList) + } + } + + Column(Modifier.padding(all = 10.dp)) { + users.forEach { task -> + key(task.uid) { + val taskId = Screen.Home.route.replace("{id}", task.uid.toString()) + Button( + modifier = Modifier + .fillMaxWidth() + .padding(all = 10.dp), + onClick = { navController?.navigate(taskId) }) { + Text("${task.name} ${task.login}") + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/todolisttask/models/dao/UserDao.kt b/app/src/main/java/com/example/todolisttask/models/dao/UserDao.kt index 5c4a1a5..852aa08 100644 --- a/app/src/main/java/com/example/todolisttask/models/dao/UserDao.kt +++ b/app/src/main/java/com/example/todolisttask/models/dao/UserDao.kt @@ -25,4 +25,7 @@ interface UserDao { @Delete suspend fun delete(user: User) + + @Query("SELECT * FROM users WHERE login = :username AND password = :password") + suspend fun getUserByUsernameAndPassword(username: String, password: String): User? } \ No newline at end of file