레퍼런스 : https://todaycode.tistory.com/12
binding.mainRecycler.addOnScrollListener(object : RecyclerView.OnScrollListener(){
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
if(!binding.mainRecycler.canScrollVertically(1)){
getIssueList(parentViewModel.getIssuePage())
}
}
})
fun getIssueList(owner : String, repo : String, page : Int) {
CoroutineScope(Dispatchers.Default).launch{
val result = issueRepository.getIssueList(owner, repo, page)
withContext(Dispatchers.Main){
val newList = mutableListOf<IssueUiData>()
issuePage++
_issueList.value?.let{
newList.addAll(it)
newList.addAll(result)
_issueList.postValue(newList)
}?:run{
_issueList.postValue(result)
}
}
}
}
binding.mainRecycler.addOnScrollListener(object : RecyclerView.OnScrollListener(){
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
if(!binding.mainRecycler.canScrollVertically(1)){
getIssueList(parentViewModel.getIssuePage())
}
if(!binding.mainRecycler.canScrollVertically(-1)){
if (isInitState){
isInitState = false
} else{
getIssueList(1)
}
}
}
})