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 14, 2019
1 parent abffa1d commit d225204
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 16 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 @@ -4,46 +4,82 @@

package org.mozilla.fenix.home.sessions

import android.content.Context
import android.text.SpannableString
import android.text.style.ClickableSpan
import android.text.style.ForegroundColorSpan
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import org.mozilla.fenix.R
import org.mozilla.fenix.app

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

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
}

override fun getItemCount(): Int = 2

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is HeaderViewHolder) {
holder.headerText.text = "Today"
when (holder) {
is HeaderViewHolder -> if (isPrivate) {
holder.headerText.text = "Private Session"
} else {
holder.headerText.text = "Today"
}
is PrivateEmptyListViewHolder -> {
// Format the description text to include a hyperlink
val descriptionText = String.format(holder.description.text.toString(), System.getProperty("line.separator"))
val linkStartIndex = descriptionText.indexOf("\n\n") + 2
val linkAction = object : ClickableSpan() {
override fun onClick(widget: View?) {
//TODO Go to SUMO page
}
}
val textWithLink = SpannableString(descriptionText).apply {
setSpan(linkAction, linkStartIndex, descriptionText.length, 0)

val colorSpan = ForegroundColorSpan(holder.description.currentTextColor)
setSpan(colorSpan, linkStartIndex, descriptionText.length, 0)
}
holder.description.text = textWithLink
}
}
}

private class HeaderViewHolder(private val view: View) : RecyclerView.ViewHolder(view) {
val headerText = view.findViewById<TextView>(R.id.header_text)

companion object {
const val LAYOUT_ID = R.layout.session_list_header
}
}

private class PrivateEmptyListViewHolder(private val view: View) : RecyclerView.ViewHolder(view) {
val description = view.findViewById<TextView>(R.id.session_description)
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,8 @@ class SessionsUIView(
init {
view.apply {
layoutManager = LinearLayoutManager(container.context)
sessionsAdapter.isPrivate = isPrivate
sessionsAdapter.context = context
adapter = sessionsAdapter
}
}
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/session_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="@color/photonGrey40" />
<corners
android:bottomLeftRadius="7dp"
android:bottomRightRadius="7dp" />
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/session_border.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dp"
android:color="?attr/sessionBorderColor"/>

<padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp"/>

<corners android:radius="8dp"/>
</shape>
24 changes: 24 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,24 @@
<?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/private_no_sessions"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/session_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:ellipsize="none"
android:gravity="center_vertical"
android:scrollHorizontally="false"
android:text="@string/private_browsing_explanation"
android:textColor="@color/off_white"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 2 additions & 2 deletions app/src/main/res/layout/session_list_header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/header_text"
android:layout_marginBottom="8dp"
android:textSize="12dp"
android:textColor="@color/session_list_header"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"
android:textColor="?attr/toolbarTextColor"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</TextView>
4 changes: 3 additions & 1 deletion app/src/main/res/layout/tab_list_header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
android:layout_height="wrap_content"
android:text="@string/tabs_header_title"
android:textSize="24sp"
android:textColor="@android:color/black"
android:textColor="?attr/toolbarTextColor"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<ImageView
android:id="@+id/add_tab_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:tint="?attr/toolbarTextColor"
android:src="@drawable/ic_add_black_24dp"
android:baselineAlignBottom="true"
app:layout_constraintBaseline_toBaselineOf="@id/header_text"
Expand All @@ -33,6 +34,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:tint="?attr/toolbarTextColor"
android:src="@drawable/ic_menu"
android:baselineAlignBottom="true"
app:layout_constraintBaseline_toBaselineOf="@id/header_text"
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/res/layout/tab_list_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
android:layout_marginBottom="8dp"
android:padding="10dp"
android:elevation="5dp"
app:cardCornerRadius="10dp">
app:cardCornerRadius="10dp"
android:clipChildren="true">

<androidx.constraintlayout.widget.ConstraintLayout
android:background="@drawable/session_border"
android:id="@+id/item_tab"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down Expand Up @@ -50,7 +52,11 @@

<ImageView android:layout_width="0dp"
android:layout_height="100dp"
android:src="@color/photonBlue40"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp"

android:background="@drawable/session_background"
app:layout_constraintTop_toBottomOf="@id/text_url"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<attr name="toolbarTextColor" format="reference"/>
<attr name="navigationBarColorHome" format="reference"/>
<attr name="homeDividerColor" format="reference" />
<attr name="sessionBorderColor" format="reference"/>

<!-- Search fragment -->
<attr name="searchBackground" format="reference"/>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<color name="off_white">#f9f9fa</color>
<color name="url_box_view">#E9E9ED</color>
<color name="icons">#20233E</color>
<color name="session_border_color">#2f26c1</color>

<color name="session_list_empty_bg">#1A665BFD</color>
<color name="session_list_empty_fg">#544CD9</color>
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
<!-- Explanation for private browsing displayed to users on home view when they first enable private mode -->
<string name="private_browsing_explanation">Fenix clears your search and browsing history when you close all
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.</string>
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>
<!-- Delete session button to erase your history in a private session -->
<string name="private_browsing_delete_session">Delete Session</string>

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<item name="toolbarWrapperBackground">@drawable/home_search_background_light</item>
<item name="toolbarTextColor">@color/search_text</item>
<item name="homeDividerColor">@color/photonGrey30</item>
<item name="sessionBorderColor">@color/session_border_color</item>

<!-- Search fragment colors -->
<item name="searchBackground">@color/off_white</item>
Expand Down Expand Up @@ -64,6 +65,7 @@
<item name="toolbarWrapperBackground">@drawable/home_search_background_private</item>
<item name="toolbarTextColor">@color/off_white</item>
<item name="homeDividerColor">@color/search_private_background</item>
<item name="sessionBorderColor">@color/private_browsing_primary</item>

<!-- Search fragment colors -->
<item name="searchBackground">@color/private_browsing_bottom_gradient</item>
Expand Down

0 comments on commit d225204

Please sign in to comment.