Calling refresh() method twice, stops the pagination.
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 35/100
調査の方向性
まず、提供されている pull-to-refresh フローを使って VideosFragment の二重リフレッシュ動作を再現し、その後、VideoPagingSource.kt および PreClassViewModel.kt と併せて adapter.refresh()、submitData()、loadStateFlow を追跡します。refresh() を 2 回呼び出した後もページネーションが機能し続け、リフレッシュ状態も正しくクリアされれば完了です。
索引モデルが issue の本文から書いたものです。
説明
I'm able to populate the list and pagination is working as expected. But when I call adapter.refresh() method twice by using pull to refresh, the pagination stops working.
Please refer the below video to get the better idea about the prolem.
https://www.dropbox.com/s/0k2g9mlktv5gee6/22-05-22-10-26-37.mp4?dl=0
VideoPagingSource.kt
class VideoPagingSource(
private val apiInterface: ApiInterface,
private val schoolId: String,
private val ordering: String?,
private val courseId: String?,
private val moduleId: String?,
private val searchText: String?
) : PagingSource<Int, Video>() {
override fun getRefreshKey(state: PagingState<Int, Video>): Int? = null
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Video> {
val pageNumber = params.key
return try {
val response = apiInterface.getVideos(schoolId, ordering, courseId, moduleId, searchText, pageNumber)
val pagedResponse = response?.body()
var nextPageNumber: Int? = null
if (pagedResponse?.links?.next != null) {
val uri = Uri.parse(pagedResponse.links.next)
val nextPageQuery = uri.getQueryParameter("page")
nextPageNumber = nextPageQuery?.toInt()
}
LoadResult.Page(
data = response?.body()?.objects.orEmpty(),
prevKey = null,
nextKey = nextPageNumber
)
} catch (e: Exception) {
LoadResult.Error(e)
}
}
}
PreClassViewModel.kt
class PreClassViewModel @Inject constructor(private val repository: PreClassRepository) :
ViewModel() {
private val queryParamLiveData = MutableLiveData<QueryParams>()
val videosLiveData = queryParamLiveData.switchMap {
repository.getVideos(
schoolId = it.extraArgs[0],
ordering = it.extraArgs[1],
courseId = it.courseId,
moduleId = it.chapterId,
searchText = it.searchText
).cachedIn(viewModelScope)
}
fun setQueryParam(queryParams: QueryParams){
queryParamLiveData.value = queryParams
}
}
VideosFragment.kt
class VideosFragment : BaseFragment<FragmentVideosBinding>(FragmentVideosBinding::inflate),
VideosPagingAdapter.VideoClickListener {
private val viewModel by viewModels<PreClassViewModel>()
private var chapter: ModulesItem? = null
private var courseId: String? = null
private var adapter: VideosPagingAdapter? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
chapter = Gson().fromJson(arguments?.getString(BUNDLE_CHAPTER), ModulesItem::class.java)
courseId = arguments?.getString(BUNDLE_COURSE_ID)
viewModel.setQueryParam(
QueryParams(
courseId = courseId,
chapterId = chapter?.id.toString(),
searchText = null,
me?.academicProfile?.school?.id?.toString()!!,
"sequence",
)
)
}
override fun initView() {
getMainActivity().showBothNavigation()
getMainActivity().showBackButton()
adapter = VideosPagingAdapter(chapter?.imageUrl, this)
binding.videoRV.adapter = adapter!!.withLoadStateFooter(footer = DefaultFooterAdapter())
lifecycleScope.launch {
adapter?.loadStateFlow?.collectLatest {
binding.progressBar.isVisible = it.refresh is LoadState.Loading
if (binding.swipeContainer.isRefreshing){
binding.swipeContainer.isRefreshing = it.refresh is LoadState.Loading
}
}
}
}
override fun initListener() {
binding.swipeContainer.setOnRefreshListener {
adapter?.refresh()
}
}
override fun addObserver() {
viewModel.videosLiveData.observe(viewLifecycleOwner) {
adapter?.submitData(viewLifecycleOwner.lifecycle, it)
}
}
override var setSelection: String
get() = Constants.FEATURE_LEARN
set(value) {}
override fun onVideoClick(video: Video) {
}
}
- 主要言語
- Kotlin
- スター
- 508
- フォーク
- 268
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
android/codelab-android-paging のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 62/100
android/codelab-android-paging#236 · リアクション 3 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
android/codelab-android-paging#243 · コメント 1 件 · リアクション 1 件 ·
-
難易度 2/5 1〜2日 初心者へのやさしさ 35/100
android/codelab-android-paging#241 · コメント 1 件 ·
android/codelab-android-paging の issue をすべて見る
似ている issue
-
submit-adaption submit-adaption-pre
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
BetterAndroid/android-notification-icon-project#750 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
openbase/planetsudo.engine#107 ·
メンテナーはふだん 1 日以内に返信
-
native-cpu: -Wreturn-type in skainet_row_threads.c:150 (worker fn has no return)対応中かも @Doomguy-BFG9000 が今日担当しました。 オープンgood first issue size:xs skill:native
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
SKaiNET-developers/SKaiNET#1358 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 63/100
IBRAHIMDANS/i18nSupportPlus#577 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
PostHog/posthog-kmp#100 ·
メンテナーはふだん 2 日以内に返信