Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit a77c116

Browse files
authored
Merge pull request #3090 from wordpress-mobile/issue/12491-fix-load-more
Fix load more
2 parents 3d8b46e + 3d6d1df commit a77c116

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

fluxc/src/main/java/org/wordpress/android/fluxc/model/list/ListState.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ enum class ListState(val value: Int) {
2121
fun isLoadingMore() = this == LOADING_MORE
2222

2323
companion object {
24-
val defaultState = ListState.NEEDS_REFRESH
24+
val defaultState = NEEDS_REFRESH
25+
val notExpiredStates = setOf(CAN_LOAD_MORE, FETCHED)
2526
}
2627
}

fluxc/src/main/java/org/wordpress/android/fluxc/store/ListStore.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,17 @@ class ListStore @Inject constructor(
351351
/**
352352
* A helper function that returns the [ListState] for the given [ListDescriptor].
353353
*/
354-
private fun getListState(listDescriptor: ListDescriptor): ListState {
354+
fun getListState(listDescriptor: ListDescriptor): ListState {
355355
val listModel = listSqlUtils.getList(listDescriptor)
356-
return if (listModel != null && !isListStateOutdated(listModel)) {
357-
requireNotNull(ListState.values().firstOrNull { it.value == listModel.stateDbValue }) {
356+
val currentState = listModel?.let {
357+
requireNotNull(ListState.entries.firstOrNull { it.value == listModel.stateDbValue }) {
358358
"The stateDbValue of the ListModel didn't match any of the `ListState`s. This likely happened " +
359359
"because the ListState values were altered without a DB migration."
360360
}
361-
} else ListState.defaultState
361+
}
362+
val isListStateValid = currentState != null
363+
&& (isListStateOutdated(listModel).not() || (currentState in ListState.notExpiredStates))
364+
return if (isListStateValid) currentState!! else ListState.defaultState
362365
}
363366

364367
/**

0 commit comments

Comments
 (0)