加载下一页
This commit is contained in:
parent
e4dc667e7a
commit
5e6dd1b7d0
|
|
@ -51,7 +51,7 @@ interface YoutubeApi {
|
|||
@Query("regionCode") regionCode: String="BR",
|
||||
@Query("maxResults") maxResults: Int=3,
|
||||
@Query("videoEmbeddable") videoEmbeddable: Boolean=true,
|
||||
@Query("pageToken") pageToken: String=""
|
||||
@Query("pageToken") pageToken: String?=""
|
||||
): ResYoutubePlayList
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import androidx.fragment.app.Fragment
|
|||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.ama.core.architecture.appBase.AppViewsFragment
|
||||
import com.ama.core.architecture.appBase.OnFragmentBackgroundListener
|
||||
|
|
@ -19,6 +20,7 @@ import com.gamedog.vididin.main.fragments.home.fragment.HomeItemFragment
|
|||
import com.gamedog.vididin.main.interfaces.OnSwitchTabListener
|
||||
import com.gamedog.vididin.main.interfaces.OnTabStyleListener
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.getValue
|
||||
import com.gamedog.vididin.databinding.VididinappFeatureHomeFragmentHomeBinding as ViewBinding
|
||||
import com.gamedog.vididin.main.fragments.home.YoutubeViewModel as ViewModel
|
||||
|
|
@ -64,7 +66,9 @@ class HomeFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(), OnSwit
|
|||
|
||||
// load more
|
||||
if (mViewPagerAdapter.itemCount > 0 && position == mViewPagerAdapter.itemCount - 2) {
|
||||
// todo load more
|
||||
lifecycleScope.launch {
|
||||
mViewModel.loadVideoPage()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +91,7 @@ class HomeFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(), OnSwit
|
|||
}
|
||||
|
||||
override fun ViewBinding.onUiStateCollect(uiState: UiState) {
|
||||
mViewPagerAdapter.appendList(uiState.playLists)
|
||||
mViewPagerAdapter.submitList(uiState.playLists)
|
||||
//viewPager2.setDataOrAdapter(uiState.playLists, 1) { mViewPagerAdapter }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,6 @@ class DefaultYoutubeDatasource @Inject constructor(retrofit: Retrofit) : Youtube
|
|||
override suspend fun getChannels(
|
||||
) = shopApi.getChannelList()
|
||||
|
||||
override suspend fun getVideoList(pageToken: String?) = shopApi.getVideoList()
|
||||
override suspend fun getVideoList(pageToken: String?) = shopApi.getVideoList(pageToken = pageToken)
|
||||
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ package com.gamedog.vididin.main.fragments.home
|
|||
|
||||
import com.ama.core.architecture.appBase.vm.AppViewModel
|
||||
import com.ama.core.architecture.page.RefreshRepository
|
||||
import com.gamedog.vididin.beans.ResYoutubePlayList
|
||||
import com.gamedog.vididin.beans.YoutubeVideo
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
|
@ -24,6 +25,10 @@ class YoutubeViewModel @Inject constructor(
|
|||
override fun onRefreshRepository(): RefreshRepository<*> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
fun loadVideoPage() {
|
||||
mRepository.load()
|
||||
}
|
||||
}
|
||||
|
||||
data class YoutubeUiState(
|
||||
|
|
|
|||
|
|
@ -58,8 +58,8 @@ abstract class BaseFragmentStateAdapter<T : BaseFragmentStateDiffItem>(
|
|||
fun appendList(appendList: List<T>?) {
|
||||
val newList = mutableListOf<T>()
|
||||
newList.addAll(getCurrentList())
|
||||
appendList?.let {
|
||||
newList.addAll(appendList)
|
||||
newList?.let {
|
||||
newList.addAll(appendList!!)
|
||||
}
|
||||
mDiffer.submitList(newList)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue