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