1
0
Fork 0

For #4441 - Keeps the ID 0 based for the recyclerview

master
Jeff Boek 2019-08-01 08:25:27 -07:00
parent 9887945296
commit 2813a3cff7
2 changed files with 6 additions and 6 deletions

View File

@ -12,7 +12,11 @@ import org.mozilla.fenix.ext.getHostFromUrl
class HistoryDataSource(
private val historyProvider: PagedHistoryProvider
) : ItemKeyedDataSource<Int, HistoryItem>() {
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<Int>,
@ -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)
}
}
}

View File

@ -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<HistoryItem>) : 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<HistoryItem>, 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) {