generated from GO-SOPT-ANDROID/android-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature/#9] getUserList 기능에 viewModel 적용
- Loading branch information
Showing
3 changed files
with
38 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/src/main/java/org/android/go/sopt/present/viewModel/MainPageViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.android.go.sopt.present.viewModel | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.launch | ||
import org.android.go.sopt.remote.remoteData.model.ResponseListUsersDto | ||
import org.android.go.sopt.remote.remoteData.repoImpl.MainPageRepoImpl | ||
|
||
class MainPageViewModel(private val mainPageRepoImpl: MainPageRepoImpl) : ViewModel() { | ||
|
||
private val _userList = MutableLiveData<List<ResponseListUsersDto.Data>>() | ||
val userList: LiveData<List<ResponseListUsersDto.Data>> get() = _userList | ||
|
||
fun getUserList() = viewModelScope.launch { | ||
kotlin.runCatching { | ||
mainPageRepoImpl.getUserList() | ||
}.onSuccess { response -> | ||
_userList.value = response.data | ||
}.onFailure { | ||
Log.d("mainPageViewModel", "서버 에러 발생") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters