Closes #24276: fixed history tests

upstream-sync
mike a 2 years ago committed by mergify[bot]
parent 019e244f0d
commit 9f699e2b40

@ -11,8 +11,7 @@ import org.mozilla.fenix.components.history.HistoryDB
import org.mozilla.fenix.components.history.PagedHistoryProvider
class HistoryDataSource(
private val historyProvider: PagedHistoryProvider,
private val onZeroItemsLoaded: () -> Unit
private val historyProvider: PagedHistoryProvider
) : PagingSource<Int, History>() {
// having any value but null creates visual glitches in case or swipe to refresh and immediate
@ -26,9 +25,6 @@ class HistoryDataSource(
positionWithOffset(offset)
}
val nextOffset = if (historyItems.isEmpty()) {
if (params.key == null) {
onZeroItemsLoaded.invoke()
}
null
} else {
(offset + historyItems.size) + 1

@ -99,7 +99,8 @@ class HistoryFragment : LibraryPageFragment<History>(), UserInteractionHandler {
)
_historyView = HistoryView(
binding.historyLayout,
historyInteractor
historyInteractor,
onZeroItemsLoaded = { viewModel.userHasHistory.value = false }
)
return view

@ -4,9 +4,11 @@
package org.mozilla.fenix.library.history
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.paging.LoadState
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.SimpleItemAnimator
import mozilla.components.support.base.feature.UserInteractionHandler
@ -21,7 +23,8 @@ import org.mozilla.fenix.theme.ThemeManager
*/
class HistoryView(
container: ViewGroup,
val interactor: HistoryInteractor
val interactor: HistoryInteractor,
val onZeroItemsLoaded: () -> Unit
) : LibraryPageView(container), UserInteractionHandler {
val binding = ComponentHistoryBinding.inflate(
@ -31,8 +34,20 @@ class HistoryView(
var mode: HistoryFragmentState.Mode = HistoryFragmentState.Mode.Normal
private set
val historyAdapter = HistoryAdapter(interactor)
val historyAdapter = HistoryAdapter(interactor).apply {
addLoadStateListener {
adapterItemCount = itemCount
Log.d("hehehaha", "adapterItemCount = $adapterItemCount")
if (it.source.refresh is LoadState.NotLoading &&
it.append.endOfPaginationReached &&
itemCount < 1
) {
onZeroItemsLoaded.invoke()
}
}
}
private val layoutManager = LinearLayoutManager(container.context)
private var adapterItemCount: Int? = null
init {
binding.historyList.apply {
@ -61,7 +76,7 @@ class HistoryView(
historyAdapter.updatePendingDeletionIds(state.pendingDeletionIds)
updateEmptyState(state.pendingDeletionIds.size != historyAdapter.itemCount)
updateEmptyState(state.pendingDeletionIds.size != adapterItemCount)
historyAdapter.updateMode(state.mode)
val first = layoutManager.findFirstVisibleItemPosition()

@ -13,20 +13,15 @@ import kotlinx.coroutines.flow.Flow
import org.mozilla.fenix.components.history.PagedHistoryProvider
class HistoryViewModel(historyProvider: PagedHistoryProvider) : ViewModel() {
var history: Flow<PagingData<History>>
var userHasHistory = MutableLiveData(true)
init {
history = Pager(
PagingConfig(PAGE_SIZE),
null
) {
HistoryDataSource(
historyProvider = historyProvider,
onZeroItemsLoaded = { userHasHistory.value = false }
)
}.flow
}
var history: Flow<PagingData<History>> = Pager(
PagingConfig(PAGE_SIZE),
null
) {
HistoryDataSource(
historyProvider = historyProvider
)
}.flow
companion object {
private const val PAGE_SIZE = 25

Loading…
Cancel
Save