Skip to content

Commit

Permalink
[FEATURE] #30 Profile - uiState 추가 및 getUser 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
eshc123 committed Sep 28, 2022
1 parent 1532a9d commit 6cdc9b0
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.eshc.feature.profile

import com.eshc.domain.model.User

data class ProfileUiState(
val user : UserModel = User().toUserModel()
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.eshc.feature.profile

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.eshc.domain.usecase.user.GetUserProfileUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.schedulers.Schedulers
import javax.inject.Inject

@HiltViewModel
class ProfileViewModel @Inject constructor(
private val getUserProfileUseCase: GetUserProfileUseCase
) : ViewModel() {

private val _uiState = MutableLiveData(ProfileUiState())
val uiState : LiveData<ProfileUiState>
get() = _uiState

fun getUser(){
getUserProfileUseCase()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { result, error ->
if(result.isSuccess){
result.getOrThrow().let {
_uiState.value = uiState.value?.copy(
user = it.toUserModel()
)
}
}
else {

}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.eshc.feature.profile

import com.eshc.domain.model.User

data class UserModel(
val id : Long,
val login : String,
val avatarUrl : String,
val name : String,
val blog : String,
val location : String,
val email : String,
val bio : String,
val publicRepos : Int,
val followers : Int,
val following : Int,
)

fun User.toUserModel() : UserModel {
return UserModel(
id, login, avatarUrl, name, blog, location, email, bio, publicRepos, followers, following
)
}

0 comments on commit 6cdc9b0

Please sign in to comment.