Advertisement
Guest User

ViewModelAndRepo

a guest
Jun 15th, 2021
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.69 KB | None | 0 0
  1. @HiltViewModel
  2. class ProfileViewModel @Inject constructor(
  3.     private val repository: GirlsRepositoryImpl
  4. ) : ViewModel() {
  5.  
  6.     val user = liveData {
  7.         emit(repository.getUserFromDb())
  8.     }
  9.     fun updateUser2(userEntity: UserEntity) {
  10.         Timber.e("view model name ${userEntity.name}")
  11.         repository.updateUser2(userEntity)
  12.     }
  13. }
  14.  
  15. class GirlsRepositoryImpl @Inject constructor(
  16.     private val localDataSource: LocalDataSource
  17. ) : GirlsRepository {
  18.  
  19.     override fun getUserFromDb(): UserEntity {
  20.         return localDataSource.getUserFromDb()
  21.     }
  22.  
  23.     override fun updateUser2(userEntity: UserEntity) {
  24.         localDataSource.updateUser2(userEntity)
  25.     }
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement