forked from mozilla-mobile/fenix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For mozilla-mobile#19916 - Add last viewed tab to home screen
Co-authored-by: Jonathan Almeida <jalmeida@mozilla.com>
- Loading branch information
1 parent
2ebc71f
commit ea4dca0
Showing
12 changed files
with
251 additions
and
8 deletions.
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
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
33 changes: 33 additions & 0 deletions
33
app/src/main/java/org/mozilla/fenix/home/sessioncontrol/RecentTabsListBinding.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,33 @@ | ||
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.selectedTab | ||
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 | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
class RecentTabsListBinding( | ||
browserStore: BrowserStore, | ||
private val homeStore: HomeFragmentStore, | ||
): AbstractBinding<BrowserState>(browserStore) { | ||
override suspend fun onState(flow: Flow<BrowserState>) { | ||
flow.map { it.selectedTab } | ||
.ifChanged() | ||
.collect { selectedTab -> | ||
val recentTabsList = if (selectedTab != null) { | ||
listOf(selectedTab) | ||
} else { | ||
emptyList() | ||
} | ||
|
||
homeStore.dispatch(HomeFragmentAction.RecentTabsChange(recentTabsList)) | ||
} | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
.../java/org/mozilla/fenix/home/sessioncontrol/viewholders/recenttabs/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,28 @@ | ||
package org.mozilla.fenix.home.sessioncontrol.viewholders.recenttabs | ||
|
||
import android.view.View | ||
import androidx.recyclerview.widget.RecyclerView | ||
import kotlinx.android.synthetic.main.recent_tabs_list_row.view.* | ||
import mozilla.components.browser.state.state.TabSessionState | ||
import mozilla.components.support.base.log.logger.Logger | ||
import org.mozilla.fenix.R | ||
|
||
class RecentTabViewHolder ( | ||
private val view: View | ||
) : RecyclerView.ViewHolder(view) { | ||
fun bindTab(tab: TabSessionState) { | ||
view.recent_tab_title.text = tab.content.title | ||
view.recent_tab_icon.setImageBitmap(tab.content.icon) | ||
view.setOnClickListener { | ||
|
||
Logger.info("TEST recent tab clicked: $tab") | ||
// TODO in interactor | ||
// components.useCases.selectTab(tab) | ||
// navGraph().navigate(browserId) | ||
} | ||
} | ||
|
||
companion object { | ||
const val LAYOUT_ID = R.layout.recent_tabs_list_row | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...rg/mozilla/fenix/home/sessioncontrol/viewholders/recenttabs/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,17 @@ | ||
/* 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.viewholders.recenttabs | ||
|
||
import android.view.View | ||
import androidx.recyclerview.widget.RecyclerView | ||
import org.mozilla.fenix.R | ||
|
||
class RecentTabsHeaderViewHolder( | ||
view: View | ||
) : RecyclerView.ViewHolder(view) { | ||
companion object { | ||
const val LAYOUT_ID = R.layout.recent_tabs_header | ||
} | ||
} |
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,33 @@ | ||
<?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/. --> | ||
<androidx.constraintlayout.widget.ConstraintLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" > | ||
|
||
<androidx.appcompat.widget.AppCompatTextView | ||
style="@style/Header20TextStyle" | ||
android:id="@+id/header" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/home_screen_recent_tabs_header" | ||
android:maxLines="2" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<com.google.android.material.button.MaterialButton | ||
android:id="@+id/showAllButton" | ||
style="@style/Button12TextStyle" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:background="?android:attr/selectableItemBackground" | ||
android:text="@string/home_screen_recent_tabs_header" | ||
android:textColor="@color/photonDarkGrey05" | ||
android:gravity="center" | ||
android:textAlignment="gravity" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintBottom_toBottomOf="@id/header" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |
Oops, something went wrong.