From 2813a3cff7008a8d718e60c19d7c59079ac6d8ad Mon Sep 17 00:00:00 2001 From: Jeff Boek Date: Thu, 1 Aug 2019 08:25:27 -0700 Subject: [PATCH] For #4441 - Keeps the ID 0 based for the recyclerview --- .../mozilla/fenix/library/history/HistoryDataSource.kt | 10 ++++++---- .../org/mozilla/fenix/library/history/HistoryStore.kt | 2 -- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/library/history/HistoryDataSource.kt b/app/src/main/java/org/mozilla/fenix/library/history/HistoryDataSource.kt index 8fae4de9d..79ada6ca5 100644 --- a/app/src/main/java/org/mozilla/fenix/library/history/HistoryDataSource.kt +++ b/app/src/main/java/org/mozilla/fenix/library/history/HistoryDataSource.kt @@ -12,7 +12,11 @@ import org.mozilla.fenix.ext.getHostFromUrl class HistoryDataSource( private val historyProvider: PagedHistoryProvider ) : ItemKeyedDataSource() { - override fun getKey(item: HistoryItem): Int = item.id + + // Because the pagination is not based off of they key + // we want to start at 1, not 0 to be able to send the correct offset + // to the `historyProvider.getHistory` call. + override fun getKey(item: HistoryItem): Int = item.id + 1 override fun loadInitial( params: LoadInitialParams, @@ -43,9 +47,7 @@ class HistoryDataSource( ?: visit.url.getHostFromUrl() ?: visit.url - // We want IDs to start at 1, not 0 to be able to send the correct offset - // to the `historyProvider.getHistory` call. - HistoryItem(offset + id + 1, title, visit.url, visit.visitTime) + HistoryItem(offset + id, title, visit.url, visit.visitTime) } } } diff --git a/app/src/main/java/org/mozilla/fenix/library/history/HistoryStore.kt b/app/src/main/java/org/mozilla/fenix/library/history/HistoryStore.kt index 8abbe7b00..1af172254 100644 --- a/app/src/main/java/org/mozilla/fenix/library/history/HistoryStore.kt +++ b/app/src/main/java/org/mozilla/fenix/library/history/HistoryStore.kt @@ -27,7 +27,6 @@ class HistoryStore(initialState: HistoryState) : * Actions to dispatch through the `HistoryStore` to modify `HistoryState` through the reducer. */ sealed class HistoryAction : Action { - data class Change(val list: List) : HistoryAction() object ExitEditMode : HistoryAction() data class AddItemForRemoval(val item: HistoryItem) : HistoryAction() data class RemoveItemForRemoval(val item: HistoryItem) : HistoryAction() @@ -53,7 +52,6 @@ data class HistoryState(val items: List, val mode: Mode) : State { */ fun historyStateReducer(state: HistoryState, action: HistoryAction): HistoryState { return when (action) { - is HistoryAction.Change -> state.copy(mode = HistoryState.Mode.Normal, items = action.list) is HistoryAction.AddItemForRemoval -> { val mode = state.mode if (mode is HistoryState.Mode.Editing) {