From f697183677e319bd93fc3de2e97f6a6437ea7478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakk=C4=B1=20Kaan=20=C3=87al=C4=B1=C5=9Fkan?= Date: Wed, 12 Aug 2020 15:14:08 +0300 Subject: [PATCH 1/2] For #12811: Add preference for show full url --- .../fenix/components/toolbar/BrowserToolbarView.kt | 7 ++++++- .../mozilla/fenix/settings/CustomizationFragment.kt | 7 +++++++ .../org/mozilla/fenix/tabtray/TabTrayViewHolder.kt | 12 ++++++++++++ .../main/java/org/mozilla/fenix/utils/Settings.kt | 5 +++++ app/src/main/res/values/preference_keys.xml | 1 + app/src/main/res/values/strings.xml | 4 ++++ app/src/main/res/xml/customization_preferences.xml | 5 +++++ 7 files changed, 40 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt index c84758807a76..bfdb5812c13d 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt @@ -134,7 +134,12 @@ class BrowserToolbarView( ThemeManager.resolveAttribute(R.attr.toolbarDivider, container.context) ) - display.urlFormatter = { url -> URLStringUtils.toDisplayUrl(url) } + display.urlFormatter = + if (context.settings().shouldStripUrl) { + url -> URLStringUtils.toDisplayUrl(url) + } else { + url -> url + } display.colors = display.colors.copy( text = primaryTextColor, diff --git a/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt index 3d586befd9c9..4686a04a799c 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt @@ -10,6 +10,7 @@ import android.os.Build.VERSION.SDK_INT import android.os.Bundle import androidx.appcompat.app.AppCompatDelegate import androidx.preference.PreferenceFragmentCompat +import androidx.preference.SwitchPreference import org.mozilla.fenix.R import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.toolbar.ToolbarPosition @@ -32,6 +33,12 @@ class CustomizationFragment : PreferenceFragmentCompat() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.customization_preferences, rootKey) + + requirePreference(R.string.pref_key_strip_url).apply { + isChecked = context.settings().shouldStripUrl + + onPreferenceChangeListener = SharedPreferenceUpdater() + } } override fun onResume() { diff --git a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayViewHolder.kt b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayViewHolder.kt index b2aba6fef164..1449b1058f39 100644 --- a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayViewHolder.kt @@ -36,6 +36,7 @@ import org.mozilla.fenix.ext.removeAndDisable import org.mozilla.fenix.ext.removeTouchDelegate import org.mozilla.fenix.ext.showAndEnable import org.mozilla.fenix.ext.toShortUrl +import org.mozilla.fenix.ext.settings import org.mozilla.fenix.utils.Do import kotlin.math.max @@ -163,6 +164,17 @@ class TabTrayViewHolder( urlView?.text = tab.url .toShortUrl(itemView.context.components.publicSuffixList) .take(MAX_URI_LENGTH) + + urlView?.apply { + text = + if (context.settings().shouldStripUrl) { + tab.url + .toShortUrl(itemView.context.components.publicSuffixList) + .take(MAX_URI_LENGTH) + } else { + tab.url.take(MAX_URI_LENGTH) + } + } } @VisibleForTesting diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index 8ab5be5ec6d6..48dae0762394 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -488,6 +488,11 @@ class Settings(private val appContext: Context) : PreferencesHolder { val toolbarPosition: ToolbarPosition get() = if (shouldUseBottomToolbar) ToolbarPosition.BOTTOM else ToolbarPosition.TOP + var shouldStripUrl by booleanPreference( + appContext.getPreferenceKey(R.string.pref_key_strip_url), + default = true + ) + /** * Check each active accessibility service to see if it can perform gestures, if any can, * then it is *likely* a switch service is enabled. We are assuming this to be the case based on #7486 diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index 317651afdf09..3fdca594509d 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -112,6 +112,7 @@ pref_key_toolbar_top pref_key_toolbar_bottom + pref_key_strip_url pref_key_light_theme diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3040ca5cd8b9..43752fc58163 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1259,6 +1259,10 @@ Username Password + + Strip HTTP/HTTPS/WWW from urls + + Enable to strip out HTTP/HTTPS/WWW from urls in toolbar and tab tray Re-enter your PIN diff --git a/app/src/main/res/xml/customization_preferences.xml b/app/src/main/res/xml/customization_preferences.xml index 19ab4c97f1a0..23434807b98b 100644 --- a/app/src/main/res/xml/customization_preferences.xml +++ b/app/src/main/res/xml/customization_preferences.xml @@ -43,5 +43,10 @@ + From 2ae67028d347a2bf92f7b473b271c4fb1a3e354d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakk=C4=B1=20Kaan=20=C3=87al=C4=B1=C5=9Fkan?= Date: Wed, 12 Aug 2020 15:31:57 +0300 Subject: [PATCH 2/2] forgot to remove unneeded shorturl code --- .../main/java/org/mozilla/fenix/tabtray/TabTrayViewHolder.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayViewHolder.kt b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayViewHolder.kt index 1449b1058f39..ee9abd086ec6 100644 --- a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayViewHolder.kt @@ -161,10 +161,6 @@ class TabTrayViewHolder( // is done in the toolbar and awesomebar: // https://github.com/mozilla-mobile/fenix/issues/1824 // https://github.com/mozilla-mobile/android-components/issues/6985 - urlView?.text = tab.url - .toShortUrl(itemView.context.components.publicSuffixList) - .take(MAX_URI_LENGTH) - urlView?.apply { text = if (context.settings().shouldStripUrl) {