You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iceraven-browser/app/src/main/java/org/mozilla/fenix/home/recentvisits/controller/RecentVisitsController.kt

140 lines
5.4 KiB
Kotlin

For #22534 - Show history highlights and groups in "Recently visited" (#22535) * For #22534 - Update homescreen section name to "Recently visited" * For #22534 - Show both history highlights and groups in Recently visited For now the metadata groups don't support scoring so as an interim solution we will show up to 9 items, evenly distributes, first favoring groups sorted by date then history highlights pre-sorted by default. Tapping a history highlight will switch to it's already open tab if available or create a new one in which to load it if needed. A "Remove" option will also be available for history highlights to remove it from the screen and also from history. Currently removing a group / highlight will not query new ones to again show up to 9 items, this will be implemented separately. * For #22534 - Rename and refactor historymetadata to recentvisits The updated feature supports more than history metadata so updating the overall naming scheme seems needed. To signal that this is a homescreen feature the entire package is moved to home * For #22534 - Update UI tests to account for the new items space on the screen Saw failures about not finding the collection section on screen. This is probably happening because w are now adding the recent visits to homescreen above the collections section pushing it off screen. Since the collections might be obstructed by the toolbar shown on top as a quick solution we'll scroll to the next homescreen section so that the collections will be shown above in their entirety. * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: Gabriel Luong <gabriel.luong@gmail.com> Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
3 years ago
/* 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.home.recentvisits.controller
import androidx.navigation.NavController
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import mozilla.components.browser.state.action.HistoryMetadataAction
For #22534 - Show history highlights and groups in "Recently visited" (#22535) * For #22534 - Update homescreen section name to "Recently visited" * For #22534 - Show both history highlights and groups in Recently visited For now the metadata groups don't support scoring so as an interim solution we will show up to 9 items, evenly distributes, first favoring groups sorted by date then history highlights pre-sorted by default. Tapping a history highlight will switch to it's already open tab if available or create a new one in which to load it if needed. A "Remove" option will also be available for history highlights to remove it from the screen and also from history. Currently removing a group / highlight will not query new ones to again show up to 9 items, this will be implemented separately. * For #22534 - Rename and refactor historymetadata to recentvisits The updated feature supports more than history metadata so updating the overall naming scheme seems needed. To signal that this is a homescreen feature the entire package is moved to home * For #22534 - Update UI tests to account for the new items space on the screen Saw failures about not finding the collection section on screen. This is probably happening because w are now adding the recent visits to homescreen above the collections section pushing it off screen. Since the collections might be obstructed by the toolbar shown on top as a quick solution we'll scroll to the next homescreen section so that the collections will be shown above in their entirety. * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: Gabriel Luong <gabriel.luong@gmail.com> Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
3 years ago
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.storage.HistoryMetadataStorage
import mozilla.components.feature.tabs.TabsUseCases.SelectOrAddUseCase
import mozilla.components.service.glean.private.NoExtras
import org.mozilla.fenix.GleanMetrics.RecentSearches
For #22534 - Show history highlights and groups in "Recently visited" (#22535) * For #22534 - Update homescreen section name to "Recently visited" * For #22534 - Show both history highlights and groups in Recently visited For now the metadata groups don't support scoring so as an interim solution we will show up to 9 items, evenly distributes, first favoring groups sorted by date then history highlights pre-sorted by default. Tapping a history highlight will switch to it's already open tab if available or create a new one in which to load it if needed. A "Remove" option will also be available for history highlights to remove it from the screen and also from history. Currently removing a group / highlight will not query new ones to again show up to 9 items, this will be implemented separately. * For #22534 - Rename and refactor historymetadata to recentvisits The updated feature supports more than history metadata so updating the overall naming scheme seems needed. To signal that this is a homescreen feature the entire package is moved to home * For #22534 - Update UI tests to account for the new items space on the screen Saw failures about not finding the collection section on screen. This is probably happening because w are now adding the recent visits to homescreen above the collections section pushing it off screen. Since the collections might be obstructed by the toolbar shown on top as a quick solution we'll scroll to the next homescreen section so that the collections will be shown above in their entirety. * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: Gabriel Luong <gabriel.luong@gmail.com> Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
3 years ago
import org.mozilla.fenix.R
import org.mozilla.fenix.components.AppStore
import org.mozilla.fenix.components.appstate.AppAction
For #22534 - Show history highlights and groups in "Recently visited" (#22535) * For #22534 - Update homescreen section name to "Recently visited" * For #22534 - Show both history highlights and groups in Recently visited For now the metadata groups don't support scoring so as an interim solution we will show up to 9 items, evenly distributes, first favoring groups sorted by date then history highlights pre-sorted by default. Tapping a history highlight will switch to it's already open tab if available or create a new one in which to load it if needed. A "Remove" option will also be available for history highlights to remove it from the screen and also from history. Currently removing a group / highlight will not query new ones to again show up to 9 items, this will be implemented separately. * For #22534 - Rename and refactor historymetadata to recentvisits The updated feature supports more than history metadata so updating the overall naming scheme seems needed. To signal that this is a homescreen feature the entire package is moved to home * For #22534 - Update UI tests to account for the new items space on the screen Saw failures about not finding the collection section on screen. This is probably happening because w are now adding the recent visits to homescreen above the collections section pushing it off screen. Since the collections might be obstructed by the toolbar shown on top as a quick solution we'll scroll to the next homescreen section so that the collections will be shown above in their entirety. * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: Gabriel Luong <gabriel.luong@gmail.com> Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
3 years ago
import org.mozilla.fenix.home.HomeFragmentDirections
import org.mozilla.fenix.home.recentvisits.RecentlyVisitedItem.RecentHistoryGroup
For #22534 - Show history highlights and groups in "Recently visited" (#22535) * For #22534 - Update homescreen section name to "Recently visited" * For #22534 - Show both history highlights and groups in Recently visited For now the metadata groups don't support scoring so as an interim solution we will show up to 9 items, evenly distributes, first favoring groups sorted by date then history highlights pre-sorted by default. Tapping a history highlight will switch to it's already open tab if available or create a new one in which to load it if needed. A "Remove" option will also be available for history highlights to remove it from the screen and also from history. Currently removing a group / highlight will not query new ones to again show up to 9 items, this will be implemented separately. * For #22534 - Rename and refactor historymetadata to recentvisits The updated feature supports more than history metadata so updating the overall naming scheme seems needed. To signal that this is a homescreen feature the entire package is moved to home * For #22534 - Update UI tests to account for the new items space on the screen Saw failures about not finding the collection section on screen. This is probably happening because w are now adding the recent visits to homescreen above the collections section pushing it off screen. Since the collections might be obstructed by the toolbar shown on top as a quick solution we'll scroll to the next homescreen section so that the collections will be shown above in their entirety. * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: Gabriel Luong <gabriel.luong@gmail.com> Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
3 years ago
import org.mozilla.fenix.home.recentvisits.RecentlyVisitedItem.RecentHistoryHighlight
import org.mozilla.fenix.library.history.toHistoryMetadata
For #22534 - Show history highlights and groups in "Recently visited" (#22535) * For #22534 - Update homescreen section name to "Recently visited" * For #22534 - Show both history highlights and groups in Recently visited For now the metadata groups don't support scoring so as an interim solution we will show up to 9 items, evenly distributes, first favoring groups sorted by date then history highlights pre-sorted by default. Tapping a history highlight will switch to it's already open tab if available or create a new one in which to load it if needed. A "Remove" option will also be available for history highlights to remove it from the screen and also from history. Currently removing a group / highlight will not query new ones to again show up to 9 items, this will be implemented separately. * For #22534 - Rename and refactor historymetadata to recentvisits The updated feature supports more than history metadata so updating the overall naming scheme seems needed. To signal that this is a homescreen feature the entire package is moved to home * For #22534 - Update UI tests to account for the new items space on the screen Saw failures about not finding the collection section on screen. This is probably happening because w are now adding the recent visits to homescreen above the collections section pushing it off screen. Since the collections might be obstructed by the toolbar shown on top as a quick solution we'll scroll to the next homescreen section so that the collections will be shown above in their entirety. * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: Gabriel Luong <gabriel.luong@gmail.com> Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
3 years ago
/**
* All possible updates following user interactions with the "Recent visits" section from the Home screen.
*/
interface RecentVisitsController {
/**
* Callback for when the "Show all" link is clicked.
*/
fun handleHistoryShowAllClicked()
/**
* Callback for when the user clicks on a specific [RecentHistoryGroup].
*
* @param recentHistoryGroup The just clicked [RecentHistoryGroup].
*/
fun handleRecentHistoryGroupClicked(recentHistoryGroup: RecentHistoryGroup)
/**
* Callback for when the user removes a certain [RecentHistoryGroup].
*
* @param groupTitle Title of the [RecentHistoryGroup] to remove.
*/
fun handleRemoveRecentHistoryGroup(groupTitle: String)
For #22534 - Show history highlights and groups in "Recently visited" (#22535) * For #22534 - Update homescreen section name to "Recently visited" * For #22534 - Show both history highlights and groups in Recently visited For now the metadata groups don't support scoring so as an interim solution we will show up to 9 items, evenly distributes, first favoring groups sorted by date then history highlights pre-sorted by default. Tapping a history highlight will switch to it's already open tab if available or create a new one in which to load it if needed. A "Remove" option will also be available for history highlights to remove it from the screen and also from history. Currently removing a group / highlight will not query new ones to again show up to 9 items, this will be implemented separately. * For #22534 - Rename and refactor historymetadata to recentvisits The updated feature supports more than history metadata so updating the overall naming scheme seems needed. To signal that this is a homescreen feature the entire package is moved to home * For #22534 - Update UI tests to account for the new items space on the screen Saw failures about not finding the collection section on screen. This is probably happening because w are now adding the recent visits to homescreen above the collections section pushing it off screen. Since the collections might be obstructed by the toolbar shown on top as a quick solution we'll scroll to the next homescreen section so that the collections will be shown above in their entirety. * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: Gabriel Luong <gabriel.luong@gmail.com> Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
3 years ago
/**
* Callback for when the user clicks on a specific [RecentHistoryHighlight].
*
* @param recentHistoryHighlight The just clicked [RecentHistoryHighlight].
*/
fun handleRecentHistoryHighlightClicked(recentHistoryHighlight: RecentHistoryHighlight)
/**
* Callback for when the user removes a certain [RecentHistoryHighlight].
*
* @param highlightUrl Url of the [RecentHistoryHighlight] to remove.
*/
fun handleRemoveRecentHistoryHighlight(highlightUrl: String)
}
/**
* The default implementation of [RecentVisitsController].
*/
class DefaultRecentVisitsController(
private val store: BrowserStore,
private val appStore: AppStore,
For #22534 - Show history highlights and groups in "Recently visited" (#22535) * For #22534 - Update homescreen section name to "Recently visited" * For #22534 - Show both history highlights and groups in Recently visited For now the metadata groups don't support scoring so as an interim solution we will show up to 9 items, evenly distributes, first favoring groups sorted by date then history highlights pre-sorted by default. Tapping a history highlight will switch to it's already open tab if available or create a new one in which to load it if needed. A "Remove" option will also be available for history highlights to remove it from the screen and also from history. Currently removing a group / highlight will not query new ones to again show up to 9 items, this will be implemented separately. * For #22534 - Rename and refactor historymetadata to recentvisits The updated feature supports more than history metadata so updating the overall naming scheme seems needed. To signal that this is a homescreen feature the entire package is moved to home * For #22534 - Update UI tests to account for the new items space on the screen Saw failures about not finding the collection section on screen. This is probably happening because w are now adding the recent visits to homescreen above the collections section pushing it off screen. Since the collections might be obstructed by the toolbar shown on top as a quick solution we'll scroll to the next homescreen section so that the collections will be shown above in their entirety. * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: Gabriel Luong <gabriel.luong@gmail.com> Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
3 years ago
private val selectOrAddTabUseCase: SelectOrAddUseCase,
private val navController: NavController,
private val storage: HistoryMetadataStorage,
private val scope: CoroutineScope,
) : RecentVisitsController {
/**
* Shows the history fragment.
*/
override fun handleHistoryShowAllClicked() {
navController.navigate(
HomeFragmentDirections.actionGlobalHistoryFragment(),
For #22534 - Show history highlights and groups in "Recently visited" (#22535) * For #22534 - Update homescreen section name to "Recently visited" * For #22534 - Show both history highlights and groups in Recently visited For now the metadata groups don't support scoring so as an interim solution we will show up to 9 items, evenly distributes, first favoring groups sorted by date then history highlights pre-sorted by default. Tapping a history highlight will switch to it's already open tab if available or create a new one in which to load it if needed. A "Remove" option will also be available for history highlights to remove it from the screen and also from history. Currently removing a group / highlight will not query new ones to again show up to 9 items, this will be implemented separately. * For #22534 - Rename and refactor historymetadata to recentvisits The updated feature supports more than history metadata so updating the overall naming scheme seems needed. To signal that this is a homescreen feature the entire package is moved to home * For #22534 - Update UI tests to account for the new items space on the screen Saw failures about not finding the collection section on screen. This is probably happening because w are now adding the recent visits to homescreen above the collections section pushing it off screen. Since the collections might be obstructed by the toolbar shown on top as a quick solution we'll scroll to the next homescreen section so that the collections will be shown above in their entirety. * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: Gabriel Luong <gabriel.luong@gmail.com> Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
3 years ago
)
}
/**
* Navigates to the history metadata group fragment to display the group.
*
* @param recentHistoryGroup The [RecentHistoryGroup] to which to navigate to.
*/
override fun handleRecentHistoryGroupClicked(recentHistoryGroup: RecentHistoryGroup) {
navController.navigate(
HomeFragmentDirections.actionGlobalHistoryMetadataGroup(
title = recentHistoryGroup.title,
historyMetadataItems = recentHistoryGroup.historyMetadata
.mapIndexed { index, item -> item.toHistoryMetadata(index) }.toTypedArray(),
),
)
}
/**
* Removes a [RecentHistoryGroup] with the given title from the homescreen.
*
* @param groupTitle The title of the [RecentHistoryGroup] to be removed.
*/
override fun handleRemoveRecentHistoryGroup(groupTitle: String) {
// We want to update the UI right away in response to user action without waiting for the IO.
// First, dispatch actions that will clean up search groups in the two stores that have
// metadata-related state.
store.dispatch(HistoryMetadataAction.DisbandSearchGroupAction(searchTerm = groupTitle))
appStore.dispatch(AppAction.DisbandSearchGroupAction(searchTerm = groupTitle))
// Then, perform the expensive IO work of removing search groups from storage.
scope.launch {
storage.deleteHistoryMetadata(groupTitle)
}
RecentSearches.groupDeleted.record(NoExtras())
}
For #22534 - Show history highlights and groups in "Recently visited" (#22535) * For #22534 - Update homescreen section name to "Recently visited" * For #22534 - Show both history highlights and groups in Recently visited For now the metadata groups don't support scoring so as an interim solution we will show up to 9 items, evenly distributes, first favoring groups sorted by date then history highlights pre-sorted by default. Tapping a history highlight will switch to it's already open tab if available or create a new one in which to load it if needed. A "Remove" option will also be available for history highlights to remove it from the screen and also from history. Currently removing a group / highlight will not query new ones to again show up to 9 items, this will be implemented separately. * For #22534 - Rename and refactor historymetadata to recentvisits The updated feature supports more than history metadata so updating the overall naming scheme seems needed. To signal that this is a homescreen feature the entire package is moved to home * For #22534 - Update UI tests to account for the new items space on the screen Saw failures about not finding the collection section on screen. This is probably happening because w are now adding the recent visits to homescreen above the collections section pushing it off screen. Since the collections might be obstructed by the toolbar shown on top as a quick solution we'll scroll to the next homescreen section so that the collections will be shown above in their entirety. * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: Gabriel Luong <gabriel.luong@gmail.com> Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
3 years ago
/**
* Switch to an already open tab for [recentHistoryHighlight] if one exists or
* create a new tab in which to load this item's URL.
*
* @param recentHistoryHighlight the just clicked [RecentHistoryHighlight] to open in browser.
*/
override fun handleRecentHistoryHighlightClicked(recentHistoryHighlight: RecentHistoryHighlight) {
selectOrAddTabUseCase.invoke(recentHistoryHighlight.url)
navController.navigate(R.id.browserFragment)
}
/**
* Removes a [RecentHistoryHighlight] with the given title from the homescreen.
*
* @param highlightUrl The title of the [RecentHistoryHighlight] to be removed.
*/
override fun handleRemoveRecentHistoryHighlight(highlightUrl: String) {
appStore.dispatch(AppAction.RemoveRecentHistoryHighlight(highlightUrl))
For #22534 - Show history highlights and groups in "Recently visited" (#22535) * For #22534 - Update homescreen section name to "Recently visited" * For #22534 - Show both history highlights and groups in Recently visited For now the metadata groups don't support scoring so as an interim solution we will show up to 9 items, evenly distributes, first favoring groups sorted by date then history highlights pre-sorted by default. Tapping a history highlight will switch to it's already open tab if available or create a new one in which to load it if needed. A "Remove" option will also be available for history highlights to remove it from the screen and also from history. Currently removing a group / highlight will not query new ones to again show up to 9 items, this will be implemented separately. * For #22534 - Rename and refactor historymetadata to recentvisits The updated feature supports more than history metadata so updating the overall naming scheme seems needed. To signal that this is a homescreen feature the entire package is moved to home * For #22534 - Update UI tests to account for the new items space on the screen Saw failures about not finding the collection section on screen. This is probably happening because w are now adding the recent visits to homescreen above the collections section pushing it off screen. Since the collections might be obstructed by the toolbar shown on top as a quick solution we'll scroll to the next homescreen section so that the collections will be shown above in their entirety. * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> * Update app/src/main/java/org/mozilla/fenix/home/recentvisits/RecentVisitsFeature.kt Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: Gabriel Luong <gabriel.luong@gmail.com> Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
3 years ago
scope.launch {
storage.deleteHistoryMetadataForUrl(highlightUrl)
}
}
}