Skip to content

Commit 075aafe

Browse files
committed
clean up diff
1 parent 251b304 commit 075aafe

File tree

2 files changed

+44
-43
lines changed

2 files changed

+44
-43
lines changed

app/src/main/java/me/tatarka/bindingcollectionadapter/sample/ImmutableViewModel.kt

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,53 +16,53 @@ class ImmutableViewModel : ViewModel(), ImmutableListeners {
1616
value = (0 until 3).map { i -> ImmutableItem(index = i, checked = false) }
1717
}
1818
private val headerFooterList =
19-
Transformations.map<List<ImmutableItem>, List<Any>>(mutList) { input ->
20-
val list = ArrayList<Any>(input.size + 2)
21-
list.add("Header")
22-
list.addAll(input)
23-
list.add("Footer")
24-
list
25-
}
19+
Transformations.map<List<ImmutableItem>, List<Any>>(mutList) { input ->
20+
val list = ArrayList<Any>(input.size + 2)
21+
list.add("Header")
22+
list.addAll(input)
23+
list.add("Footer")
24+
list
25+
}
2626
val list: LiveData<List<Any>> = headerFooterList
2727

2828
val pagedList: LiveData<PagedList<Any>> =
29-
LivePagedListBuilder(object : DataSource.Factory<Int, Any>() {
30-
override fun create(): DataSource<Int, Any> =
31-
object : PositionalDataSource<Any>() {
32-
33-
override fun loadInitial(
34-
params: LoadInitialParams,
35-
callback: LoadInitialCallback<Any>
36-
) {
37-
val list =
38-
(0 until params.requestedLoadSize).map {
39-
ImmutableItem(
40-
index = it + params.requestedStartPosition,
41-
checked = false
42-
)
43-
}
44-
// Pretend we are slow
45-
Thread.sleep(1000)
46-
callback.onResult(list, params.requestedStartPosition, TOTAL_COUNT)
29+
LivePagedListBuilder(object : DataSource.Factory<Int, Any>() {
30+
override fun create(): DataSource<Int, Any> =
31+
object : PositionalDataSource<Any>() {
32+
33+
override fun loadInitial(
34+
params: LoadInitialParams,
35+
callback: LoadInitialCallback<Any>
36+
) {
37+
val list =
38+
(0 until params.requestedLoadSize).map {
39+
ImmutableItem(
40+
index = it + params.requestedStartPosition,
41+
checked = false
42+
)
4743
}
48-
49-
override fun loadRange(
50-
params: LoadRangeParams,
51-
callback: LoadRangeCallback<Any>
52-
) {
53-
val list =
54-
(0 until params.loadSize).map {
55-
ImmutableItem(
56-
index = it + params.startPosition,
57-
checked = false
58-
)
59-
}
60-
// Pretend we are slow
61-
Thread.sleep(1000)
62-
callback.onResult(list)
44+
// Pretend we are slow
45+
Thread.sleep(1000)
46+
callback.onResult(list, params.requestedStartPosition, 200)
47+
}
48+
49+
override fun loadRange(
50+
params: LoadRangeParams,
51+
callback: LoadRangeCallback<Any>
52+
) {
53+
val list =
54+
(0 until params.loadSize).map {
55+
ImmutableItem(
56+
index = it + params.startPosition,
57+
checked = false
58+
)
6359
}
64-
}
65-
}, PAGE_SIZE).build()
60+
// Pretend we are slow
61+
Thread.sleep(1000)
62+
callback.onResult(list)
63+
}
64+
}
65+
}, PAGE_SIZE).build()
6666

6767
val pagedListV3: LiveData<PagingData<Any>> = Pager<Int, Any>(PagingConfig(
6868
pageSize = PAGE_SIZE,
@@ -85,7 +85,7 @@ class ImmutableViewModel : ViewModel(), ImmutableListeners {
8585
return LoadResult.Page(
8686
data = list,
8787
prevKey = if (safeKey == 0) null else (safeKey - params.loadSize),
88-
nextKey = if (safeKey >= 200 - params.loadSize) null else (safeKey + params.loadSize),
88+
nextKey = if (safeKey >= TOTAL_COUNT - params.loadSize) null else (safeKey + params.loadSize),
8989
itemsBefore = safeKey,
9090
itemsAfter = TOTAL_COUNT - params.loadSize - safeKey
9191
)

bindingcollectionadapter-paging/src/main/java/me/tatarka/bindingcollectionadapter2/PagedBindingRecyclerViewAdapters.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public static <T> void setAdapter(RecyclerView recyclerView,
9090
for (RecyclerView.Adapter childAdapter : concatAdapter.getAdapters()) {
9191
if (childAdapter instanceof BindingRecyclerViewAdapter) {
9292
oldAdapter = (BindingRecyclerViewAdapter<T>) childAdapter;
93+
break;
9394
}
9495
}
9596
} else if (rootAdapter instanceof BindingRecyclerViewAdapter) {

0 commit comments

Comments
 (0)