Last active
November 13, 2021 09:46
-
-
Save seoft/13767eb5481c20403d908aa7a500381a to your computer and use it in GitHub Desktop.
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
class CommonViewModel(private val api: MockApi = MockService()) : ViewModel() // 생성자 구조 | |
private val _uiModels = MutableLiveData<List<NormalUiModel>>(emptyList()) | |
val uiModels: LiveData<List<NormalUiModel>> = _uiModels | |
val uiModelsValue get() = uiModels.value ?: emptyList() | |
fun loadMoreUiModels() { | |
if (requestLock.getAndSet(true)) return | |
isShowProgress.value = true | |
api.loadMore() | |
.map { NormalModelMapper.from(it) } | |
.doFinally { | |
requestLock.set(false) | |
isShowProgress.postValue(false) | |
} | |
.subscribe({ | |
_uiModels.postValue(uiModelsValue + it) | |
}, { | |
_throwable.postValue(it) | |
}).addTo(compositeDisposable) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment