2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-15 18:12:54 +00:00
This commit is contained in:
Sawyer Blatz 2019-02-28 11:41:58 -08:00 committed by Jeff Boek
parent d3299beb5a
commit 9c136469b8
7 changed files with 50 additions and 5 deletions

View File

@ -70,6 +70,7 @@ class HomeFragment : Fragment() {
tabsComponent = TabsComponent( tabsComponent = TabsComponent(
view.homeContainer, view.homeContainer,
bus, bus,
(activity as HomeActivity).browsingModeManager.isPrivate,
TabsState(sessionManager.sessions.map { it.toSessionViewState(it == sessionManager.selectedSession) }) TabsState(sessionManager.sessions.map { it.toSessionViewState(it == sessionManager.selectedSession) })
) )
sessionsComponent = SessionsComponent(view.homeContainer, bus) sessionsComponent = SessionsComponent(view.homeContainer, bus)
@ -168,6 +169,7 @@ class HomeFragment : Fragment() {
(activity as AppCompatActivity).supportActionBar?.hide() (activity as AppCompatActivity).supportActionBar?.hide()
} }
@SuppressWarnings("ComplexMethod")
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
if (isAdded) { if (isAdded) {
@ -188,6 +190,9 @@ class HomeFragment : Fragment() {
requireComponents.core.sessionManager.remove(session) requireComponents.core.sessionManager.remove(session)
} }
} }
is TabsAction.CloseAll -> {
requireComponents.useCases.tabsUseCases.removeAllTabsOfType.invoke(it.private)
}
} }
} }

View File

@ -17,6 +17,7 @@ import org.mozilla.fenix.mvi.ViewState
class TabsComponent( class TabsComponent(
private val container: ViewGroup, private val container: ViewGroup,
bus: ActionBusFactory, bus: ActionBusFactory,
private val isPrivate: Boolean,
override var initialState: TabsState = TabsState(listOf()) override var initialState: TabsState = TabsState(listOf())
) : ) :
UIComponent<TabsState, TabsAction, TabsChange>( UIComponent<TabsState, TabsAction, TabsChange>(
@ -30,7 +31,7 @@ class TabsComponent(
} }
} }
override fun initView() = TabsUIView(container, actionEmitter, changesObservable) override fun initView() = TabsUIView(container, actionEmitter, changesObservable, isPrivate)
val tabList: RecyclerView val tabList: RecyclerView
get() = uiView.view.tabs_list as RecyclerView get() = uiView.view.tabs_list as RecyclerView
@ -48,6 +49,7 @@ fun Session.toSessionViewState(selected: Boolean): SessionViewState {
sealed class TabsAction : Action { sealed class TabsAction : Action {
object Archive : TabsAction() object Archive : TabsAction()
data class CloseAll(val private: Boolean) : TabsAction()
data class Select(val sessionId: String) : TabsAction() data class Select(val sessionId: String) : TabsAction()
data class Close(val sessionId: String) : TabsAction() data class Close(val sessionId: String) : TabsAction()
} }

View File

@ -27,7 +27,8 @@ import org.mozilla.fenix.mvi.UIView
class TabsUIView( class TabsUIView(
container: ViewGroup, container: ViewGroup,
actionEmitter: Observer<TabsAction>, actionEmitter: Observer<TabsAction>,
changesObservable: Observable<TabsChange> changesObservable: Observable<TabsChange>,
private val isPrivate: Boolean
) : ) :
UIView<TabsState, TabsAction, TabsChange>(container, actionEmitter, changesObservable) { UIView<TabsState, TabsAction, TabsChange>(container, actionEmitter, changesObservable) {
@ -65,6 +66,10 @@ class TabsUIView(
this.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null) this.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
} }
delete_session_button.setOnClickListener {
actionEmitter.onNext(TabsAction.CloseAll(true))
}
save_session_button.setOnClickListener { save_session_button.setOnClickListener {
actionEmitter.onNext(TabsAction.Archive) actionEmitter.onNext(TabsAction.Archive)
} }
@ -73,10 +78,11 @@ class TabsUIView(
override fun updateView() = Consumer<TabsState> { override fun updateView() = Consumer<TabsState> {
tabsAdapter.sessions = it.sessions tabsAdapter.sessions = it.sessions
val sessionButton = if (isPrivate) view.delete_session_button else view.save_session_button
(if (it.sessions.isEmpty()) View.GONE else View.VISIBLE).also { visibility -> (if (it.sessions.isEmpty()) View.GONE else View.VISIBLE).also { visibility ->
view.tabs_header.visibility = visibility view.tabs_header.visibility = visibility
view.save_session_button.visibility = visibility sessionButton.visibility = visibility
} }
} }

View File

@ -1,3 +1,7 @@
<!-- 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/. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android" <vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp" android:width="24dp"
android:height="24dp" android:height="24dp"

View File

@ -81,4 +81,31 @@
android:focusable="false" android:focusable="false"
android:layout_gravity="center" /> android:layout_gravity="center" />
</FrameLayout> </FrameLayout>
<FrameLayout
android:id="@+id/delete_session_button"
android:foreground="?android:attr/selectableItemBackground"
android:background="@drawable/button_background"
android:backgroundTint="@color/delete_session_button_background"
android:layout_margin="16dp"
android:padding="6dp"
android:clickable="true"
android:focusable="true"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/delete_session_button_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/session_delete"
android:textColor="@color/color_primary_dark"
android:drawableStart="@drawable/ic_delete"
android:drawablePadding="8dp"
android:textSize="16sp"
android:gravity="center"
android:clickable="false"
android:focusable="false"
android:layout_gravity="center" />
</FrameLayout>
</merge> </merge>

View File

@ -34,6 +34,7 @@
<color name="session_list_empty_fg">#544CD9</color> <color name="session_list_empty_fg">#544CD9</color>
<color name="session_list_header">#6D6D6E</color> <color name="session_list_header">#6D6D6E</color>
<color name="session_list_private_header">#4a4671</color> <color name="session_list_private_header">#4a4671</color>
<color name="delete_session_button_background">#e5e5ea</color>
<color name="private_browsing_primary">#ad3bff</color> <color name="private_browsing_primary">#ad3bff</color>
<color name="private_browsing_top_gradient">#242251</color> <color name="private_browsing_top_gradient">#242251</color>

View File

@ -23,8 +23,6 @@
Private Sessions tabs. While this doesn\'t make you anonymous to websites or your internet service provider, Private Sessions tabs. While this doesn\'t make you anonymous to websites or your internet service provider,
it makes it easier to keep what you do online private from anyone else who uses this device.\n\nCommon myths it makes it easier to keep what you do online private from anyone else who uses this device.\n\nCommon myths
about private browsing</string> about private browsing</string>
<!-- Delete session button to erase your history in a private session -->
<string name="private_browsing_delete_session">Delete Session</string>
<!-- Browser Fragment --> <!-- Browser Fragment -->
<!-- Content description (not visible, for screen readers etc.): Navigate home --> <!-- Content description (not visible, for screen readers etc.): Navigate home -->
@ -172,6 +170,8 @@ people before profit. Our mission: keep the Internet open and accessible to all.
<!-- Text for the button to save a session --> <!-- Text for the button to save a session -->
<string name="session_save">Save Session</string> <string name="session_save">Save Session</string>
<!-- Text for the button to delete a session -->
<string name="session_delete">Delete Session</string>
<!-- Text for the button to delete a single session --> <!-- Text for the button to delete a single session -->
<string name="session_item_delete">Delete</string> <string name="session_item_delete">Delete</string>