Skip to content

Commit

Permalink
Merge remote-tracking branch 'hakkikaancaliskan/strip-url-pref' into …
Browse files Browse the repository at this point in the history
…fork
  • Loading branch information
interfect committed Aug 18, 2020
2 parents e8c354f + 2ae6702 commit 10c43fd
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,6 +33,12 @@ class CustomizationFragment : PreferenceFragmentCompat() {

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.customization_preferences, rootKey)

requirePreference<SwitchPreference>(R.string.pref_key_strip_url).apply {
isChecked = context.settings().shouldStripUrl

onPreferenceChangeListener = SharedPreferenceUpdater()
}
}

override fun onResume() {
Expand Down
14 changes: 11 additions & 3 deletions app/src/main/java/org/mozilla/fenix/tabtray/TabTrayViewHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -160,9 +161,16 @@ 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) {
tab.url
.toShortUrl(itemView.context.components.publicSuffixList)
.take(MAX_URI_LENGTH)
} else {
tab.url.take(MAX_URI_LENGTH)
}
}
}

@VisibleForTesting
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/org/mozilla/fenix/utils/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/preference_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<!-- Toolbar Settings -->
<string name="pref_key_toolbar_top" translatable="false">pref_key_toolbar_top</string>
<string name="pref_key_toolbar_bottom" translatable="false">pref_key_toolbar_bottom</string>
<string name="pref_key_strip_url" translatable="false">pref_key_strip_url</string>

<!-- Theme Settings -->
<string name="pref_key_light_theme" translatable="false">pref_key_light_theme</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,10 @@
<string name="preferences_passwords_saved_logins_username">Username</string>
<!-- The header for the password for a login -->
<string name="preferences_passwords_saved_logins_password">Password</string>
<!-- Title for strip url preference in customization settings -->
<string name="preferences_strip_url_title">Strip HTTP/HTTPS/WWW from urls</string>
<!-- Description for strip url preference in customization settings -->
<string name="preferences_strip_url_description">Enable to strip out HTTP/HTTPS/WWW from urls in toolbar and tab tray</string>
<!-- Message displayed in security prompt to reenter a secret pin to access saved logins -->
<string name="preferences_passwords_saved_logins_enter_pin">Re-enter your PIN</string>
<!-- Message displayed in security prompt to access saved logins -->
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/xml/customization_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@
<org.mozilla.fenix.settings.RadioButtonPreference
android:key="@string/pref_key_toolbar_bottom"
android:title="@string/preference_bottom_toolbar" />
<SwitchPreference
android:defaultValue="true"
android:key="@string/pref_key_strip_url"
android:summary="@string/preferences_strip_url_description"
android:title="@string/preferences_strip_url_title" />
</androidx.preference.PreferenceCategory>
</androidx.preference.PreferenceScreen>

0 comments on commit 10c43fd

Please sign in to comment.