This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
For #19916 - Add last viewed tab to home screen #19944
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* 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.ext | ||
|
||
import mozilla.components.browser.state.selector.selectedTab | ||
import mozilla.components.browser.state.state.BrowserState | ||
import mozilla.components.browser.state.state.TabSessionState | ||
|
||
/** | ||
* Returns the currently selected tab if there's one as a list. | ||
* | ||
* @return A list of the currently selected tab or an empty list. | ||
*/ | ||
fun BrowserState.asRecentTabs(): List<TabSessionState> { | ||
val tab = selectedTab | ||
|
||
return if (tab != null && !tab.content.private) { | ||
listOfNotNull(tab) | ||
} else { | ||
emptyList() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
app/src/main/java/org/mozilla/fenix/home/recenttabs/controller/RecentTabController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* 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.recenttabs.controller | ||
|
||
import androidx.navigation.NavController | ||
import mozilla.components.feature.tabs.TabsUseCases.SelectTabUseCase | ||
import org.mozilla.fenix.R | ||
import org.mozilla.fenix.ext.nav | ||
import org.mozilla.fenix.ext.navigateBlockingForAsyncNavGraph | ||
import org.mozilla.fenix.home.HomeFragmentDirections | ||
import org.mozilla.fenix.home.recenttabs.interactor.RecentTabInteractor | ||
|
||
/** | ||
* An interface that handles the view manipulation of the recent tabs in the Home screen. | ||
*/ | ||
interface RecentTabController { | ||
|
||
/** | ||
* @see [RecentTabInteractor.onRecentTabClicked] | ||
*/ | ||
fun handleRecentTabClicked(tabId: String) | ||
|
||
/** | ||
* @see [RecentTabInteractor.onRecentTabShowAllClicked] | ||
*/ | ||
fun handleRecentTabShowAllClicked() | ||
} | ||
|
||
/** | ||
* The default implementation of [RecentTabController]. | ||
* | ||
* @param selectTabUseCase [SelectTabUseCase] used selecting a tab. | ||
* @param navController [NavController] used for navigation. | ||
*/ | ||
class DefaultRecentTabsController( | ||
private val selectTabUseCase: SelectTabUseCase, | ||
private val navController: NavController | ||
) : RecentTabController { | ||
|
||
override fun handleRecentTabClicked(tabId: String) { | ||
selectTabUseCase.invoke(tabId) | ||
navController.navigateBlockingForAsyncNavGraph(R.id.browserFragment) | ||
} | ||
|
||
override fun handleRecentTabShowAllClicked() { | ||
navController.nav( | ||
R.id.homeFragment, | ||
HomeFragmentDirections.actionGlobalTabsTrayFragment() | ||
) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/org/mozilla/fenix/home/recenttabs/interactor/RecentTabInteractor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* 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.recenttabs.interactor | ||
|
||
/** | ||
* Interface for recent tab related actions in the Home screen. | ||
*/ | ||
interface RecentTabInteractor { | ||
/** | ||
* Opens the given tab. Called when a user clicks on a recent tab. | ||
* | ||
* @param tabId The ID of the tab to open. | ||
*/ | ||
fun onRecentTabClicked(tabId: String) | ||
|
||
/** | ||
* Show the tabs tray. Called when a user clicks on the "Show all" button besides the recent | ||
* tabs. | ||
*/ | ||
fun onRecentTabShowAllClicked() | ||
} |
36 changes: 36 additions & 0 deletions
36
app/src/main/java/org/mozilla/fenix/home/recenttabs/view/RecentTabViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* 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.recenttabs.view | ||
|
||
import android.view.View | ||
import kotlinx.android.synthetic.main.recent_tabs_list_row.* | ||
import mozilla.components.browser.state.state.TabSessionState | ||
import org.mozilla.fenix.R | ||
import org.mozilla.fenix.home.recenttabs.interactor.RecentTabInteractor | ||
import org.mozilla.fenix.utils.view.ViewHolder | ||
|
||
/** | ||
* View holder for a recent tab item. | ||
* | ||
* @param interactor [RecentTabInteractor] which will have delegated to all user interactions. | ||
*/ | ||
class RecentTabViewHolder( | ||
view: View, | ||
private val interactor: RecentTabInteractor | ||
) : ViewHolder(view) { | ||
|
||
fun bindTab(tab: TabSessionState) { | ||
recent_tab_title.text = tab.content.title | ||
recent_tab_icon.setImageBitmap(tab.content.icon) | ||
|
||
itemView.setOnClickListener { | ||
interactor.onRecentTabClicked(tab.id) | ||
} | ||
} | ||
|
||
companion object { | ||
const val LAYOUT_ID = R.layout.recent_tabs_list_row | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/org/mozilla/fenix/home/recenttabs/view/RecentTabsHeaderViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* 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.recenttabs.view | ||
|
||
import android.view.View | ||
import kotlinx.android.synthetic.main.recent_tabs_header.* | ||
import org.mozilla.fenix.R | ||
import org.mozilla.fenix.home.recenttabs.interactor.RecentTabInteractor | ||
import org.mozilla.fenix.utils.view.ViewHolder | ||
|
||
/** | ||
* View holder for the recent tabs header and "Show all" button. | ||
* | ||
* @param interactor [RecentTabInteractor] which will have delegated to all user interactions. | ||
*/ | ||
class RecentTabsHeaderViewHolder( | ||
view: View, | ||
private val interactor: RecentTabInteractor | ||
) : ViewHolder(view) { | ||
|
||
init { | ||
show_all_button.setOnClickListener { | ||
interactor.onRecentTabShowAllClicked() | ||
} | ||
} | ||
|
||
companion object { | ||
const val LAYOUT_ID = R.layout.recent_tabs_header | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
app/src/main/java/org/mozilla/fenix/home/sessioncontrol/RecentTabsListFeature.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* 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.sessioncontrol | ||
|
||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.flow.map | ||
import mozilla.components.browser.state.selector.normalTabs | ||
import mozilla.components.browser.state.state.BrowserState | ||
import mozilla.components.browser.state.store.BrowserStore | ||
import mozilla.components.lib.state.helpers.AbstractBinding | ||
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged | ||
import org.mozilla.fenix.home.HomeFragmentAction | ||
import org.mozilla.fenix.home.HomeFragmentStore | ||
|
||
/** | ||
* View-bound feature that dispatches recent tab changes to the [HomeFragmentStore] when the | ||
* [BrowserStore] is updated. | ||
*/ | ||
@OptIn(ExperimentalCoroutinesApi::class) | ||
class RecentTabsListFeature( | ||
private val browserStore: BrowserStore, | ||
private val homeStore: HomeFragmentStore | ||
) : AbstractBinding<BrowserState>(browserStore) { | ||
|
||
override suspend fun onState(flow: Flow<BrowserState>) { | ||
flow.map { it.selectedTabId } | ||
.ifChanged() | ||
.collect { selectedTabId -> | ||
// Attempt to get the selected normal tab since here may not be a selected tab or | ||
// the selected tab may be a private tab. | ||
val selectedTab = browserStore.state.normalTabs.firstOrNull { | ||
it.id == selectedTabId | ||
} | ||
val recentTabsList = if (selectedTab != null) { | ||
listOf(selectedTab) | ||
} else { | ||
emptyList() | ||
} | ||
|
||
homeStore.dispatch(HomeFragmentAction.RecentTabsChange(recentTabsList)) | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Probably meant for this (and it's test) to be in
org.mozilla.fenix.home.recenttab
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do this as a fast follow to not lose the green CI