2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-15 18:12:54 +00:00
iceraven-browser/app/src/main/java/org/mozilla/fenix/BrowsingModeManager.kt

50 lines
1.5 KiB
Kotlin
Raw Normal View History

/* 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
import org.mozilla.fenix.utils.Settings
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()
updateTheme(value)
}
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
BrowsingModeManager.Mode.Private -> ThemeManager.Theme.Private
}
setTheme(newTheme)
}
}
private fun setPreference() {
Settings.getInstance(homeActivity).setPrivateMode(isPrivate)
}
init {
if (temporaryModeStorage == null) {
mode = when (Settings.getInstance(homeActivity).usePrivateMode) {
true -> BrowsingModeManager.Mode.Private
false -> BrowsingModeManager.Mode.Normal
}
}
}
}