From d3b6668a51760c20046cab52af8ab09d3db4d12a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=91=D0=B0=D1=82=D1=8B?= =?UTF-8?q?=D0=BB=D0=BA=D0=B8=D0=BD?= Date: Mon, 13 Nov 2023 23:30:01 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=20=D1=87=D1=91=20=D1=8F=20=D1=81=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B0=D0=BB=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todolisttask/composeui/EditTask.kt | 2 +- .../example/todolisttask/composeui/Home.kt | 3 +- .../todolisttask/models/composeui/UserList.kt | 55 +++++++++++++++++++ .../todolisttask/models/dao/UserDao.kt | 3 + 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/com/example/todolisttask/models/composeui/UserList.kt 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