4-ую все кроме регистрации
This commit is contained in:
parent
321962fb19
commit
1ebf64982f
@ -19,7 +19,7 @@ interface UserDao {
|
||||
fun getAll(): Flow<List<User>>
|
||||
|
||||
@Query("select * from users where users.id = :id")
|
||||
fun getById(id: Int): User?
|
||||
fun getById(id: Int): Flow<User?>
|
||||
|
||||
@Query("select * from users where users.login = :login")
|
||||
suspend fun getByLogin(login: String): User?
|
||||
|
@ -7,7 +7,7 @@ import kotlinx.coroutines.flow.Flow
|
||||
class OfflineUserRepository(private val userDao: UserDao): UserRepository {
|
||||
override fun getAllUsers(): Flow<List<User>> = userDao.getAll()
|
||||
|
||||
override suspend fun getUserById(id: Int): User? = userDao.getById(id)
|
||||
override suspend fun getUserById(id: Int): Flow<User?> = userDao.getById(id)
|
||||
|
||||
override suspend fun getUserByLogin(login: String): User? = userDao.getByLogin(login)
|
||||
|
||||
|
@ -7,7 +7,7 @@ import kotlinx.coroutines.flow.Flow
|
||||
interface UserRepository {
|
||||
fun getAllUsers(): Flow<List<User>>
|
||||
|
||||
suspend fun getUserById(id: Int): User?
|
||||
suspend fun getUserById(id: Int): Flow<User?>
|
||||
|
||||
suspend fun getUserByLogin(login: String): User?
|
||||
|
||||
|
@ -12,7 +12,7 @@ import kotlinx.coroutines.runBlocking
|
||||
class UserViewModel(private val userRepository: UserRepository): ViewModel() {
|
||||
val getAllUsers = userRepository.getAllUsers()
|
||||
|
||||
suspend fun getUser(id: Int): User? = userRepository.getUserById(id)
|
||||
suspend fun getUser(id: Int): Flow<User?> = userRepository.getUserById(id)
|
||||
|
||||
fun updateUser(user: User) = viewModelScope.launch {
|
||||
userRepository.updateUser(user)
|
||||
|
@ -51,12 +51,15 @@ fun UserSettings(navController: NavHostController,
|
||||
val password = remember { mutableStateOf("") }
|
||||
val userId = GlobalUser.getInstance().getUser()?.id?: 1
|
||||
|
||||
userId?.let {
|
||||
LaunchedEffect(Unit) {
|
||||
withContext(Dispatchers.IO) {
|
||||
val user = MobileAppDataBase.getInstance(context).userDao().getById(userId!!)
|
||||
login.value = user!!.login
|
||||
password.value = user!!.password
|
||||
LaunchedEffect(Unit) {
|
||||
userId?.let {
|
||||
userViewModel.getUser(userId).collect {
|
||||
if (it != null) {
|
||||
login.value = it.login
|
||||
}
|
||||
if (it != null) {
|
||||
password.value = it.password
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user