Skip to content

Commit

Permalink
For mozilla-mobile#347: Adds private session explainer
Browse files Browse the repository at this point in the history
  • Loading branch information
sblatz committed Feb 13, 2019
1 parent 46791f0 commit 5c870c8
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 7 deletions.
20 changes: 18 additions & 2 deletions app/src/main/java/org/mozilla/fenix/BrowsingModeManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package org.mozilla.fenix

import android.preference.PreferenceManager

interface BrowsingModeManager {
enum class Mode {
Normal, Private
Expand All @@ -19,15 +21,29 @@ class DefaultBrowsingModeManager(private val homeActivity: HomeActivity) : Brows
set(value) {
temporaryModeStorage = value
updateTheme(value)
setPreference()
}

private fun updateTheme(value: BrowsingModeManager.Mode) {
private fun updateTheme(mode: BrowsingModeManager.Mode) {
homeActivity.themeManager.apply {
val newTheme = when (value) {
val newTheme = when (mode) {
BrowsingModeManager.Mode.Normal -> ThemeManager.Theme.Light
BrowsingModeManager.Mode.Private -> ThemeManager.Theme.Private
}
setTheme(newTheme)
}
}

private fun setPreference() {
PreferenceManager.getDefaultSharedPreferences(homeActivity)
.edit().putBoolean(homeActivity.getString(R.string.pref_key_private_mode), isPrivate).apply()
}

/*
mode = when(PreferenceManager.getDefaultSharedPreferences(homeActivity)
.getBoolean(homeActivity.getString(R.string.pref_key_private_mode), false)) {
true -> BrowsingModeManager.Mode.Private
false -> BrowsingModeManager.Mode.Normal
}
*/
}
2 changes: 1 addition & 1 deletion app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class HomeFragment : Fragment() {
): View? {
val view = inflater.inflate(R.layout.fragment_home, container, false)
TabsComponent(view.homeLayout, bus, TabsState(requireComponents.core.sessionManager.sessions))
SessionsComponent(view.homeLayout, bus)
SessionsComponent(view.homeLayout, bus, (activity as HomeActivity).browsingModeManager.isPrivate)
layoutComponents(view)
ActionBusFactory.get(this).logMergedObservables()
val activity = activity as HomeActivity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ import androidx.recyclerview.widget.RecyclerView
import org.mozilla.fenix.R

class SessionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
var isPrivate = false

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false)

return when (viewType) {
HeaderViewHolder.LAYOUT_ID -> HeaderViewHolder(view)
EmptyListViewHolder.LAYOUT_ID -> EmptyListViewHolder(view)
PrivateEmptyListViewHolder.LAYOUT_ID -> PrivateEmptyListViewHolder(view)
else -> EmptyListViewHolder(view)
}
}

override fun getItemViewType(position: Int) = when (position) {
0 -> HeaderViewHolder.LAYOUT_ID
1 -> EmptyListViewHolder.LAYOUT_ID
1 -> if (isPrivate) PrivateEmptyListViewHolder.LAYOUT_ID else EmptyListViewHolder.LAYOUT_ID
else -> -1
}

Expand All @@ -44,6 +47,12 @@ class SessionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
}
}

private class PrivateEmptyListViewHolder(private val view: View) : RecyclerView.ViewHolder(view) {
companion object {
const val LAYOUT_ID = R.layout.session_list_empty_private
}
}

private class EmptyListViewHolder(private val view: View) : RecyclerView.ViewHolder(view) {
companion object {
const val LAYOUT_ID = R.layout.session_list_empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.mozilla.fenix.mvi.ViewState
class SessionsComponent(
private val container: ViewGroup,
bus: ActionBusFactory,
private val isPrivate: Boolean,
override var initialState: SessionsState = SessionsState(emptyList())
) :
UIComponent<SessionsState, SessionsAction, SessionsChange>(
Expand All @@ -28,19 +29,19 @@ class SessionsComponent(
}
}

override fun initView() = SessionsUIView(container, actionEmitter, changesObservable)
override fun initView() = SessionsUIView(container, actionEmitter, isPrivate, changesObservable)

init {
render(reducer)
}
}

data class SessionsState(val sessions: List<Session>) : ViewState
data class SessionsState(val sessions: List<Session>, val isPrivate: Boolean = false) : ViewState

sealed class SessionsAction : Action {
object Select : SessionsAction()
}

sealed class SessionsChange : Change {
object Changed : SessionsChange()
data class Changed(val isPrivate: Boolean) : SessionsChange()
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.mozilla.fenix.mvi.UIView
class SessionsUIView(
container: ViewGroup,
actionEmitter: Observer<SessionsAction>,
isPrivate: Boolean,
changesObservable: Observable<SessionsChange>
) :
UIView<SessionsState, SessionsAction, SessionsChange>(container, actionEmitter, changesObservable) {
Expand All @@ -30,6 +31,7 @@ class SessionsUIView(
init {
view.apply {
layoutManager = LinearLayoutManager(container.context)
sessionsAdapter.isPrivate = isPrivate
adapter = sessionsAdapter
}
}
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/res/layout/session_list_empty_private.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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:id="@+id/no_sessions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/session_list_empty_bg"
android:padding="16dp">


<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="23dp"
android:ellipsize="none"
android:gravity="center_vertical"
android:scrollHorizontally="false"
android:text="@string/private_browsing_explanation"
android:textColor="@color/session_list_empty_fg"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 5c870c8

Please sign in to comment.