2019-02-15 17:31:03 +00:00
|
|
|
/* 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.fenix
|
|
|
|
|
2019-05-02 15:59:13 +00:00
|
|
|
import org.mozilla.fenix.utils.Settings
|
2019-02-15 17:31:03 +00:00
|
|
|
|
|
|
|
interface BrowsingModeManager {
|
|
|
|
enum class Mode {
|
|
|
|
Normal, Private
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var temporaryModeStorage: BrowsingModeManager.Mode? = null
|
|
|
|
class DefaultBrowsingModeManager(private val homeActivity: HomeActivity) : BrowsingModeManager {
|
|
|
|
val isPrivate: Boolean
|
|
|
|
get() = mode == BrowsingModeManager.Mode.Private
|
|
|
|
var mode: BrowsingModeManager.Mode
|
|
|
|
get() = temporaryModeStorage!!
|
|
|
|
set(value) {
|
|
|
|
temporaryModeStorage = value
|
|
|
|
setPreference()
|
2019-05-02 15:59:13 +00:00
|
|
|
updateTheme(value)
|
2019-02-15 17:31:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun updateTheme(mode: BrowsingModeManager.Mode) {
|
|
|
|
homeActivity.themeManager.apply {
|
|
|
|
val newTheme = when (mode) {
|
2019-04-02 00:53:37 +00:00
|
|
|
BrowsingModeManager.Mode.Normal -> ThemeManager.Theme.Normal
|
2019-02-15 17:31:03 +00:00
|
|
|
BrowsingModeManager.Mode.Private -> ThemeManager.Theme.Private
|
|
|
|
}
|
|
|
|
setTheme(newTheme)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun setPreference() {
|
2019-05-02 15:59:13 +00:00
|
|
|
Settings.getInstance(homeActivity).setPrivateMode(isPrivate)
|
2019-02-15 17:31:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
init {
|
|
|
|
if (temporaryModeStorage == null) {
|
2019-05-02 15:59:13 +00:00
|
|
|
mode = when (Settings.getInstance(homeActivity).usePrivateMode) {
|
2019-02-15 17:31:03 +00:00
|
|
|
true -> BrowsingModeManager.Mode.Private
|
|
|
|
false -> BrowsingModeManager.Mode.Normal
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|