Skip to content

Commit

Permalink
clean up diff
Browse files Browse the repository at this point in the history
  • Loading branch information
kedzie committed Aug 6, 2020
1 parent 251b304 commit 075aafe
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImmutableItem>, List<Any>>(mutList) { input ->
val list = ArrayList<Any>(input.size + 2)
list.add("Header")
list.addAll(input)
list.add("Footer")
list
}
Transformations.map<List<ImmutableItem>, List<Any>>(mutList) { input ->
val list = ArrayList<Any>(input.size + 2)
list.add("Header")
list.addAll(input)
list.add("Footer")
list
}
val list: LiveData<List<Any>> = headerFooterList

val pagedList: LiveData<PagedList<Any>> =
LivePagedListBuilder(object : DataSource.Factory<Int, Any>() {
override fun create(): DataSource<Int, Any> =
object : PositionalDataSource<Any>() {

override fun loadInitial(
params: LoadInitialParams,
callback: LoadInitialCallback<Any>
) {
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<Int, Any>() {
override fun create(): DataSource<Int, Any> =
object : PositionalDataSource<Any>() {

override fun loadInitial(
params: LoadInitialParams,
callback: LoadInitialCallback<Any>
) {
val list =
(0 until params.requestedLoadSize).map {
ImmutableItem(
index = it + params.requestedStartPosition,
checked = false
)
}

override fun loadRange(
params: LoadRangeParams,
callback: LoadRangeCallback<Any>
) {
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<Any>
) {
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<PagingData<Any>> = Pager<Int, Any>(PagingConfig(
pageSize = PAGE_SIZE,
Expand All @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public static <T> void setAdapter(RecyclerView recyclerView,
for (RecyclerView.Adapter childAdapter : concatAdapter.getAdapters()) {
if (childAdapter instanceof BindingRecyclerViewAdapter) {
oldAdapter = (BindingRecyclerViewAdapter<T>) childAdapter;
break;
}
}
} else if (rootAdapter instanceof BindingRecyclerViewAdapter) {
Expand Down

0 comments on commit 075aafe

Please sign in to comment.