forked from mozilla-mobile/focus-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue mozilla-mobile#5935: Introduce setting for HTTPS-Only mode
- Loading branch information
Showing
6 changed files
with
67 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
app/src/main/java/org/mozilla/focus/settings/HttpsOnlyModePreference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* 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/. */ | ||
|
||
package org.mozilla.focus.settings | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import mozilla.components.concept.engine.Engine | ||
import org.mozilla.focus.R | ||
import org.mozilla.focus.ext.components | ||
|
||
/** | ||
* Preference for HTTPS-Only mode. | ||
*/ | ||
class HttpsOnlyModePreference( | ||
context: Context, | ||
attrs: AttributeSet? | ||
) : LearnMoreSwitchPreference(context, attrs) { | ||
// TODO: Replace with actual link | ||
override fun getLearnMoreUrl() = "https://support.mozilla.org/en-US/kb/https-only-prefs" | ||
|
||
init { | ||
setOnPreferenceChangeListener { _, newValue -> | ||
val enableHttpsOnly = newValue as Boolean | ||
context.components.engine.settings.httpsOnlyMode = if (enableHttpsOnly) { | ||
Engine.HttpsOnlyMode.ENABLED | ||
} else { | ||
Engine.HttpsOnlyMode.DISABLED | ||
} | ||
true | ||
} | ||
} | ||
|
||
override fun getDescription(): String { | ||
val appName = context.getString(R.string.app_name) | ||
return context.getString(R.string.preference_https_only_summary, appName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters