pull/600/head
mike a 2 years ago committed by mergify[bot]
parent b9eef2be49
commit 637bd89f84

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

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

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

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

Loading…
Cancel
Save