Fixes #672 - Moves private browsing description out of sessions
parent
57a0d97114
commit
000d5a2e54
|
@ -7,6 +7,9 @@ package org.mozilla.fenix.home
|
|||
import android.content.res.Resources
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.os.Bundle
|
||||
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
|
||||
|
@ -68,6 +71,8 @@ class HomeFragment : Fragment() {
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
setupHomeMenu()
|
||||
setupPrivateBrowsingDescription()
|
||||
updatePrivateSessionDescriptionVisibility()
|
||||
|
||||
sessionsComponent.view.visibility = if ((activity as HomeActivity).browsingModeManager.isPrivate)
|
||||
View.GONE else View.VISIBLE
|
||||
|
@ -206,31 +211,66 @@ class HomeFragment : Fragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun setupPrivateBrowsingDescription() {
|
||||
// Format the description text to include a hyperlink
|
||||
val descriptionText = String
|
||||
.format(private_session_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(private_session_description.currentTextColor)
|
||||
setSpan(colorSpan, linkStartIndex, descriptionText.length, 0)
|
||||
}
|
||||
private_session_description.text = textWithLink
|
||||
}
|
||||
|
||||
private fun updatePrivateSessionDescriptionVisibility() {
|
||||
val isPrivate = (activity as HomeActivity).browsingModeManager.isPrivate
|
||||
val hasNoTabs = requireComponents.core.sessionManager.all.none { it.private }
|
||||
|
||||
private_session_description_wrapper.visibility = if (isPrivate && hasNoTabs) {
|
||||
View.VISIBLE
|
||||
} else {
|
||||
View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
private fun subscribeToSessions(): SessionManager.Observer {
|
||||
val observer = object : SessionManager.Observer {
|
||||
override fun onSessionAdded(session: Session) {
|
||||
super.onSessionAdded(session)
|
||||
emitSessionChanges()
|
||||
updatePrivateSessionDescriptionVisibility()
|
||||
}
|
||||
|
||||
override fun onSessionRemoved(session: Session) {
|
||||
super.onSessionRemoved(session)
|
||||
emitSessionChanges()
|
||||
updatePrivateSessionDescriptionVisibility()
|
||||
}
|
||||
|
||||
override fun onSessionSelected(session: Session) {
|
||||
super.onSessionSelected(session)
|
||||
emitSessionChanges()
|
||||
updatePrivateSessionDescriptionVisibility()
|
||||
}
|
||||
|
||||
override fun onSessionsRestored() {
|
||||
super.onSessionsRestored()
|
||||
emitSessionChanges()
|
||||
updatePrivateSessionDescriptionVisibility()
|
||||
}
|
||||
|
||||
override fun onAllSessionsRemoved() {
|
||||
super.onAllSessionsRemoved()
|
||||
emitSessionChanges()
|
||||
updatePrivateSessionDescriptionVisibility()
|
||||
}
|
||||
}
|
||||
requireComponents.core.sessionManager.register(observer)
|
||||
|
|
|
@ -5,9 +5,6 @@
|
|||
package org.mozilla.fenix.home.sessions
|
||||
|
||||
import android.graphics.PorterDuff
|
||||
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
|
||||
|
@ -62,7 +59,6 @@ class SessionsAdapter(
|
|||
HeaderViewHolder.LAYOUT_ID -> HeaderViewHolder(view)
|
||||
EmptyListViewHolder.LAYOUT_ID -> EmptyListViewHolder(view)
|
||||
SessionItemViewHolder.LAYOUT_ID -> SessionItemViewHolder(view, actionEmitter)
|
||||
PrivateEmptyListViewHolder.LAYOUT_ID -> PrivateEmptyListViewHolder(view)
|
||||
else -> EmptyListViewHolder(view)
|
||||
}
|
||||
}
|
||||
|
@ -82,24 +78,6 @@ class SessionsAdapter(
|
|||
when (holder) {
|
||||
is HeaderViewHolder -> holder.headerText.text = "Today"
|
||||
is SessionItemViewHolder -> holder.bind(state.items[position - 1])
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,13 +88,6 @@ class SessionsAdapter(
|
|||
}
|
||||
}
|
||||
|
||||
private class PrivateEmptyListViewHolder(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 SessionItemViewHolder(
|
||||
view: View,
|
||||
private val actionEmitter: Observer<SessionsAction>,
|
||||
|
|
|
@ -102,7 +102,33 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:descendantFocusability="blocksDescendants"/>
|
||||
android:descendantFocusability="blocksDescendants">
|
||||
<LinearLayout
|
||||
android:id="@+id/private_session_description_wrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"
|
||||
android:textColor="?attr/toolbarTextColor"
|
||||
android:text="@string/private_browsing_title"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:id="@+id/private_session_description"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="none"
|
||||
android:gravity="center_vertical"
|
||||
android:scrollHorizontally="false"
|
||||
android:text="@string/private_browsing_explanation"
|
||||
android:textColor="@color/off_white"
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
</androidx.constraintlayout.motion.widget.MotionLayout>
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
<?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>
|
Loading…
Reference in New Issue