Skip to content

Commit

Permalink
[fix] 空安全
Browse files Browse the repository at this point in the history
  • Loading branch information
RyensX committed Nov 12, 2024
1 parent 19ec712 commit 790235e
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,21 @@ class ViewPagerViewHolder private constructor(private val binding: ViewComponent

class PageViewModel : ViewModel() {

private var pageLoader by Delegates.notNull<ViewPagerData.PageLoader>()
private var page by Delegates.notNull<Int>()
private var pageLoader: ViewPagerData.PageLoader? = null
private var page: Int = 0

fun bindData(pageLoader: ViewPagerData.PageLoader?, page: Int?) {
pageLoader?.also { this.pageLoader = it }
this.pageLoader = pageLoader
page?.also { this.page = it }
}

private val _pageDataLiveData: MutableLiveData<List<BaseData>?> = MutableLiveData()
private val _pageDataLiveData: MutableLiveData<List<BaseData>?> =
MutableLiveData<List<BaseData>?>()
val pageDataLiveData = _pageDataLiveData.toLiveData()

fun getData() {
viewModelScope.launch(Dispatchers.PluginIO) {
_pageDataLiveData.postValue(pageLoader.loadData(page))
_pageDataLiveData.postValue(pageLoader?.loadData(page))
}
}

Expand Down

0 comments on commit 790235e

Please sign in to comment.