Closes #25942: use HistoryFragment to show synced history

This commit is contained in:
mike a 2022-07-28 11:01:02 -07:00 committed by mergify[bot]
parent 586aca8924
commit 6483e1c647
9 changed files with 62 additions and 78 deletions

View File

@ -16,6 +16,7 @@ import org.mozilla.fenix.library.history.viewholders.HistoryListItemViewHolder
*/
class HistoryAdapter(
private val historyInteractor: HistoryInteractor,
private val isSyncedHistory: Boolean,
private val onEmptyStateChanged: (Boolean) -> Unit,
) : PagingDataAdapter<History, HistoryListItemViewHolder>(historyDiffCallback),
SelectionHolder<History> {
@ -116,12 +117,12 @@ class HistoryAdapter(
}
holder.bind(
current,
timeGroup,
position == 0,
mode,
isPendingDeletion,
groupPendingDeletionCount
item = current,
timeGroup = timeGroup,
showTopContent = !isSyncedHistory && position == 0,
mode = mode,
isPendingDeletion = isPendingDeletion,
groupPendingDeletionCount = groupPendingDeletionCount,
)
}

View File

@ -22,7 +22,6 @@ import org.mozilla.fenix.components.AppStore
import org.mozilla.fenix.components.appstate.AppAction
import org.mozilla.fenix.components.history.DefaultPagedHistoryProvider
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.navigateSafe
import org.mozilla.fenix.library.history.HistoryFragment.DeleteConfirmationDialogFragment
import org.mozilla.fenix.utils.Settings
import org.mozilla.fenix.GleanMetrics.History as GleanHistory
@ -52,7 +51,7 @@ interface HistoryController {
fun handleEnterRecentlyClosed()
/**
* Navigates to [org.mozilla.fenix.library.syncedhistory.SyncedHistoryFragment]
* Navigates to [HistoryFragment] that would display history synced from other devices.
*/
fun handleEnterSyncedHistory()
}
@ -128,7 +127,7 @@ class DefaultHistoryController(
HistoryFragmentDirections.actionGlobalHistorySearchDialog()
}
navController.navigateSafe(R.id.historyFragment, directions)
navController.navigate(directions)
}
override fun handleDeleteTimeRange() {
@ -218,8 +217,6 @@ class DefaultHistoryController(
}
override fun handleEnterSyncedHistory() {
navController.navigate(
HistoryFragmentDirections.actionHistoryFragmentToSyncedHistoryFragment()
)
navController.navigate(HistoryFragmentDirections.actionSyncedHistoryFragment())
}
}

View File

@ -21,13 +21,14 @@ import androidx.fragment.app.DialogFragment
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavDirections
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch
import mozilla.components.concept.engine.prompt.ShareData
import mozilla.components.lib.state.ext.consumeFrom
@ -68,10 +69,11 @@ class HistoryFragment : LibraryPageFragment<History>(), UserInteractionHandler {
) {
HistoryDataSource(
historyProvider = historyProvider,
isRemote = if (FeatureFlags.showSyncedHistory) false else null
isRemote = if (FeatureFlags.showSyncedHistory) args.isSyncedHistory else null,
)
}.flow
private val args: HistoryFragmentArgs by navArgs()
private var _historyView: HistoryView? = null
private val historyView: HistoryView
get() = _historyView!!
@ -127,7 +129,8 @@ class HistoryFragment : LibraryPageFragment<History>(), UserInteractionHandler {
historyStore.dispatch(
HistoryFragmentAction.ChangeEmptyState(it)
)
}
},
isSyncedHistory = args.isSyncedHistory,
)
return view

View File

@ -26,7 +26,8 @@ class HistoryView(
container: ViewGroup,
val interactor: HistoryInteractor,
val onZeroItemsLoaded: () -> Unit,
val onEmptyStateChanged: (Boolean) -> Unit
val onEmptyStateChanged: (Boolean) -> Unit,
val isSyncedHistory: Boolean,
) : LibraryPageView(container), UserInteractionHandler {
val binding = ComponentHistoryBinding.inflate(
@ -36,9 +37,13 @@ class HistoryView(
var mode: HistoryFragmentState.Mode = HistoryFragmentState.Mode.Normal
private set
val historyAdapter = HistoryAdapter(interactor) { isEmpty ->
onEmptyStateChanged(isEmpty)
}.apply {
val historyAdapter = HistoryAdapter(
historyInteractor = interactor,
isSyncedHistory = isSyncedHistory,
onEmptyStateChanged = { isEmpty ->
onEmptyStateChanged(isEmpty)
},
).apply {
addLoadStateListener {
// First call will always have itemCount == 0, but we want to keep adapterItemCount
// as null until we can distinguish an empty list from populated, so updateEmptyState()
@ -97,9 +102,12 @@ class HistoryView(
when (val mode = state.mode) {
is HistoryFragmentState.Mode.Normal -> {
setUiForNormalMode(
val title = if (isSyncedHistory) {
context.getString(R.string.history_from_other_devices)
} else {
context.getString(R.string.library_history)
)
}
setUiForNormalMode(title = title)
}
is HistoryFragmentState.Mode.Editing -> {
setUiForSelectingMode(
@ -115,7 +123,7 @@ class HistoryView(
private fun updateEmptyState(userHasHistory: Boolean) {
binding.historyList.isInvisible = !userHasHistory
binding.historyEmptyView.isVisible = !userHasHistory
binding.topSpacer.isVisible = !userHasHistory
binding.topSpacer.isVisible = !isSyncedHistory && !userHasHistory
with(binding.recentlyClosedNavEmpty) {
recentlyClosedNav.setOnClickListener {
@ -132,14 +140,15 @@ class HistoryView(
),
numRecentTabs
)
recentlyClosedNav.isVisible = !userHasHistory
recentlyClosedNav.isVisible = !isSyncedHistory && !userHasHistory
}
with(binding.syncedHistoryNavEmpty) {
syncedHistoryNav.setOnClickListener {
interactor.onSyncedHistoryClicked()
}
syncedHistoryNav.isVisible = FeatureFlags.showSyncedHistory && !userHasHistory
syncedHistoryNav.isVisible =
!isSyncedHistory && FeatureFlags.showSyncedHistory && !userHasHistory
}
if (!userHasHistory) {

View File

@ -1,22 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.library.syncedhistory
import mozilla.components.support.base.feature.UserInteractionHandler
import org.mozilla.fenix.library.LibraryPageFragment
import org.mozilla.fenix.library.history.History
/**
* A screen displaying history items that were opened on other devices, not local.
*/
class SyncedHistoryFragment : LibraryPageFragment<History>(), UserInteractionHandler {
override fun onBackPressed(): Boolean {
return false
}
override val selectedItems: Set<History>
get() = setOf()
}

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/historyLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.mozilla.fenix.library.syncedhistory.SyncedHistoryFragment" />

View File

@ -4,7 +4,6 @@
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAccessibility="no"
@ -27,7 +26,7 @@
<View
android:id="@+id/bottom_spacer"
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_height="8dp"
android:visibility="gone"/>
<TextView
@ -36,6 +35,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="24dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="0dp"
android:textColor="?attr/textPrimary"

View File

@ -85,7 +85,11 @@
<action
android:id="@+id/action_global_historyFragment"
app:destination="@id/historyFragment" />
<action
android:id="@+id/action_global_history_search_dialog"
app:destination="@id/historySearchDialogFragment"
app:popUpTo="@id/historySearchDialogFragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_global_downloadsFragment"
app:destination="@id/downloadsFragment" />
@ -271,14 +275,27 @@
android:label="@string/library_history"
tools:layout="@layout/fragment_history">
<argument
android:name="isSyncedHistory"
android:defaultValue="false"
app:argType="boolean" />
<action
android:id="@+id/action_global_history_search_dialog"
app:destination="@id/historySearchDialogFragment"
app:popUpTo="@id/historySearchDialogFragment"
app:popUpToInclusive="true" />
android:id="@+id/action_synced_historyFragment"
app:destination="@id/syncedHistoryFragment" />
</fragment>
<fragment
android:id="@+id/syncedHistoryFragment"
android:name="org.mozilla.fenix.library.history.HistoryFragment"
android:label="@string/history_from_other_devices"
tools:layout="@layout/fragment_history">
<argument
android:name="isSyncedHistory"
android:defaultValue="true"
app:argType="boolean" />
<action
android:id="@+id/action_historyFragment_to_syncedHistoryFragment"
android:id="@+id/action_synced_historyFragment"
app:destination="@id/syncedHistoryFragment" />
</fragment>
@ -299,13 +316,6 @@
app:argType="org.mozilla.fenix.library.history.History[]" />
</fragment>
<fragment
android:id="@+id/syncedHistoryFragment"
android:name="org.mozilla.fenix.library.syncedhistory.SyncedHistoryFragment"
android:label="@string/history_from_other_devices"
tools:layout="@layout/fragment_synced_history">
</fragment>
<fragment
android:id="@+id/downloadsFragment"
android:name="org.mozilla.fenix.library.downloads.DownloadFragment"

View File

@ -25,10 +25,9 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.R
import org.mozilla.fenix.NavGraphDirections
import org.mozilla.fenix.components.AppStore
import org.mozilla.fenix.components.history.DefaultPagedHistoryProvider
import org.mozilla.fenix.ext.navigateSafe
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.utils.Settings
@ -144,9 +143,8 @@ class HistoryControllerTest {
controller.handleSearch()
verify {
navController.navigateSafe(
R.id.historyFragment,
HistoryFragmentDirections.actionGlobalHistorySearchDialog()
navController.navigate(
NavGraphDirections.actionGlobalHistorySearchDialog()
)
}
}