From 075aafebea2b7fd5db0664a3d6ecef31944e3a55 Mon Sep 17 00:00:00 2001 From: kedzie Date: Wed, 5 Aug 2020 22:54:37 -0500 Subject: [PATCH] clean up diff --- .../sample/ImmutableViewModel.kt | 86 +++++++++---------- .../PagedBindingRecyclerViewAdapters.java | 1 + 2 files changed, 44 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/me/tatarka/bindingcollectionadapter/sample/ImmutableViewModel.kt b/app/src/main/java/me/tatarka/bindingcollectionadapter/sample/ImmutableViewModel.kt index 5b0e36e..9d93482 100644 --- a/app/src/main/java/me/tatarka/bindingcollectionadapter/sample/ImmutableViewModel.kt +++ b/app/src/main/java/me/tatarka/bindingcollectionadapter/sample/ImmutableViewModel.kt @@ -16,53 +16,53 @@ class ImmutableViewModel : ViewModel(), ImmutableListeners { value = (0 until 3).map { i -> ImmutableItem(index = i, checked = false) } } private val headerFooterList = - Transformations.map, List>(mutList) { input -> - val list = ArrayList(input.size + 2) - list.add("Header") - list.addAll(input) - list.add("Footer") - list - } + Transformations.map, List>(mutList) { input -> + val list = ArrayList(input.size + 2) + list.add("Header") + list.addAll(input) + list.add("Footer") + list + } val list: LiveData> = headerFooterList val pagedList: LiveData> = - LivePagedListBuilder(object : DataSource.Factory() { - override fun create(): DataSource = - object : PositionalDataSource() { - - override fun loadInitial( - params: LoadInitialParams, - callback: LoadInitialCallback - ) { - val list = - (0 until params.requestedLoadSize).map { - ImmutableItem( - index = it + params.requestedStartPosition, - checked = false - ) - } - // Pretend we are slow - Thread.sleep(1000) - callback.onResult(list, params.requestedStartPosition, TOTAL_COUNT) + LivePagedListBuilder(object : DataSource.Factory() { + override fun create(): DataSource = + object : PositionalDataSource() { + + override fun loadInitial( + params: LoadInitialParams, + callback: LoadInitialCallback + ) { + val list = + (0 until params.requestedLoadSize).map { + ImmutableItem( + index = it + params.requestedStartPosition, + checked = false + ) } - - override fun loadRange( - params: LoadRangeParams, - callback: LoadRangeCallback - ) { - val list = - (0 until params.loadSize).map { - ImmutableItem( - index = it + params.startPosition, - checked = false - ) - } - // Pretend we are slow - Thread.sleep(1000) - callback.onResult(list) + // Pretend we are slow + Thread.sleep(1000) + callback.onResult(list, params.requestedStartPosition, 200) + } + + override fun loadRange( + params: LoadRangeParams, + callback: LoadRangeCallback + ) { + val list = + (0 until params.loadSize).map { + ImmutableItem( + index = it + params.startPosition, + checked = false + ) } - } - }, PAGE_SIZE).build() + // Pretend we are slow + Thread.sleep(1000) + callback.onResult(list) + } + } + }, PAGE_SIZE).build() val pagedListV3: LiveData> = Pager(PagingConfig( pageSize = PAGE_SIZE, @@ -85,7 +85,7 @@ class ImmutableViewModel : ViewModel(), ImmutableListeners { return LoadResult.Page( data = list, prevKey = if (safeKey == 0) null else (safeKey - params.loadSize), - nextKey = if (safeKey >= 200 - params.loadSize) null else (safeKey + params.loadSize), + nextKey = if (safeKey >= TOTAL_COUNT - params.loadSize) null else (safeKey + params.loadSize), itemsBefore = safeKey, itemsAfter = TOTAL_COUNT - params.loadSize - safeKey ) diff --git a/bindingcollectionadapter-paging/src/main/java/me/tatarka/bindingcollectionadapter2/PagedBindingRecyclerViewAdapters.java b/bindingcollectionadapter-paging/src/main/java/me/tatarka/bindingcollectionadapter2/PagedBindingRecyclerViewAdapters.java index 5aefd18..22a83fd 100644 --- a/bindingcollectionadapter-paging/src/main/java/me/tatarka/bindingcollectionadapter2/PagedBindingRecyclerViewAdapters.java +++ b/bindingcollectionadapter-paging/src/main/java/me/tatarka/bindingcollectionadapter2/PagedBindingRecyclerViewAdapters.java @@ -90,6 +90,7 @@ public static void setAdapter(RecyclerView recyclerView, for (RecyclerView.Adapter childAdapter : concatAdapter.getAdapters()) { if (childAdapter instanceof BindingRecyclerViewAdapter) { oldAdapter = (BindingRecyclerViewAdapter) childAdapter; + break; } } } else if (rootAdapter instanceof BindingRecyclerViewAdapter) {