1
0
Fork 0
fenix/app/src/main/java/org/mozilla/fenix/browser/browsingmode/BrowsingModeManager.kt

51 lines
1.4 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/. */
2019-08-21 17:33:59 +02:00
package org.mozilla.fenix.browser.browsingmode
import org.mozilla.fenix.utils.Settings
2019-08-07 22:02:08 +02:00
/**
* Enum that represents whether or not private browsing is active.
*/
enum class BrowsingMode {
Normal, Private;
/**
* Returns true if the [BrowsingMode] is [Private]
*/
val isPrivate get() = this == Private
companion object {
/**
* Convert a boolean into a [BrowsingMode].
* True corresponds to [Private] and false corresponds to [Normal].
*/
fun fromBoolean(isPrivate: Boolean) = if (isPrivate) Private else Normal
}
2019-05-31 00:49:58 +02:00
}
2019-08-07 22:02:08 +02:00
interface BrowsingModeManager {
var mode: BrowsingMode
}
2019-05-31 00:49:58 +02:00
class DefaultBrowsingModeManager(
2019-08-07 22:02:08 +02:00
private val settings: Settings,
private val modeDidChange: (BrowsingMode) -> Unit
) : BrowsingModeManager {
2019-08-07 22:02:08 +02:00
override var mode: BrowsingMode
get() = BrowsingMode.fromBoolean(settings.usePrivateMode)
set(value) {
settings.usePrivateMode = value.isPrivate
2019-08-07 22:02:08 +02:00
modeDidChange(value)
}
2019-05-31 00:49:58 +02:00
}
class CustomTabBrowsingModeManager : BrowsingModeManager {
2019-08-07 22:02:08 +02:00
override var mode
get() = BrowsingMode.Normal
set(_) { /* no-op */ }
}