Added separate TextView for link text Used UnderlineSpan to show text as link Split string private_browsing_placeholder, one for each TextView Set clickListener on TextView so it can be accessed via Talkbackmaster
parent
8c30200ced
commit
c7c752cabb
|
@ -6,8 +6,7 @@ package org.mozilla.fenix.home.sessioncontrol.viewholders
|
|||
|
||||
import android.text.SpannableString
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.text.style.ClickableSpan
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.text.style.UnderlineSpan
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.reactivex.Observer
|
||||
|
@ -24,26 +23,21 @@ class PrivateBrowsingDescriptionViewHolder(
|
|||
|
||||
init {
|
||||
val resources = view.context.resources
|
||||
// Format the description text to include a hyperlink
|
||||
val appName = resources.getString(R.string.app_name)
|
||||
view.private_session_description.text = resources.getString(R.string.private_browsing_placeholder, appName)
|
||||
val descriptionText = String
|
||||
.format(view.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?) {
|
||||
view.private_session_description.text = resources.getString(
|
||||
R.string.private_browsing_placeholder_description, appName
|
||||
)
|
||||
val commonMythsText = view.private_session_common_myths.text.toString()
|
||||
val textWithLink = SpannableString(commonMythsText).apply {
|
||||
setSpan(UnderlineSpan(), 0, commonMythsText.length, 0)
|
||||
}
|
||||
with(view.private_session_common_myths) {
|
||||
movementMethod = LinkMovementMethod.getInstance()
|
||||
text = textWithLink
|
||||
setOnClickListener {
|
||||
actionEmitter.onNext(TabAction.PrivateBrowsingLearnMore)
|
||||
}
|
||||
}
|
||||
val textWithLink = SpannableString(descriptionText).apply {
|
||||
setSpan(linkAction, linkStartIndex, descriptionText.length, 0)
|
||||
|
||||
val colorSpan = ForegroundColorSpan(view.private_session_description.currentTextColor)
|
||||
setSpan(colorSpan, linkStartIndex, descriptionText.length, 0)
|
||||
}
|
||||
|
||||
view.private_session_description.movementMethod = LinkMovementMethod.getInstance()
|
||||
view.private_session_description.text = textWithLink
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -7,16 +7,29 @@
|
|||
android:id="@+id/private_session_description_wrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:layout_margin="12dp"
|
||||
android:importantForAccessibility="no"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:id="@+id/private_session_description"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="none"
|
||||
android:padding="4dp"
|
||||
android:gravity="center_vertical"
|
||||
android:scrollHorizontally="false"
|
||||
tools:text="@string/private_browsing_placeholder"
|
||||
tools:text="@string/private_browsing_placeholder_description"
|
||||
android:textColor="?primaryText"
|
||||
android:textSize="14sp" />
|
||||
<TextView
|
||||
android:id="@+id/private_session_common_myths"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="4dp"
|
||||
android:ellipsize="none"
|
||||
android:gravity="center_vertical"
|
||||
android:scrollHorizontally="false"
|
||||
android:text="@string/private_browsing_common_myths"
|
||||
android:textColor="?primaryText"
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
|
|
|
@ -24,10 +24,12 @@
|
|||
<string name="private_browsing_title">You’re in a private session</string>
|
||||
<!-- Explanation for private browsing displayed to users on home view when they first enable private mode
|
||||
The first parameter is the name of the app defined in app_name (for example: Fenix) -->
|
||||
<string name="private_browsing_placeholder">
|
||||
<string name="private_browsing_placeholder_description">
|
||||
%1$s clears your search and browsing history when you quit the app or close all private 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 about private
|
||||
browsing
|
||||
easier to keep what you do online private from anyone else who uses this device.
|
||||
</string>
|
||||
<string name="private_browsing_common_myths">
|
||||
Common 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>
|
||||
|
|
Loading…
Reference in New Issue