Upstream changes (#23)
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.meloda.app.fast.datastore
|
||||
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.os.PowerManager
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
|
||||
fun isUsingDarkMode(
|
||||
resources: Resources,
|
||||
powerManager: PowerManager,
|
||||
): Boolean {
|
||||
val nightThemeMode: Int = SettingsController.getInt(
|
||||
SettingsKeys.KEY_APPEARANCE_DARK_THEME,
|
||||
SettingsKeys.DEFAULT_VALUE_APPEARANCE_DARK_THEME
|
||||
)
|
||||
|
||||
val appForceDarkMode = nightThemeMode == AppCompatDelegate.MODE_NIGHT_YES
|
||||
val appBatterySaver = nightThemeMode == AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY
|
||||
|
||||
val systemUiNightMode = resources.configuration.uiMode
|
||||
|
||||
val isSystemBatterySaver = powerManager.isPowerSaveMode
|
||||
val isSystemUsingDarkTheme =
|
||||
systemUiNightMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
|
||||
|
||||
return appForceDarkMode || (appBatterySaver && isSystemBatterySaver) || (!appBatterySaver && isSystemUsingDarkTheme && nightThemeMode == AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||
}
|
||||
|
||||
fun isUsingDynamicColors(): Boolean = SettingsController.getBoolean(
|
||||
SettingsKeys.KEY_USE_DYNAMIC_COLORS,
|
||||
SettingsKeys.DEFAULT_VALUE_USE_DYNAMIC_COLORS
|
||||
)
|
||||
|
||||
fun isUsingAmoledBackground(): Boolean = SettingsController.getBoolean(
|
||||
SettingsKeys.KEY_APPEARANCE_AMOLED_THEME,
|
||||
SettingsKeys.DEFAULT_VALUE_APPEARANCE_AMOLED_THEME
|
||||
)
|
||||
|
||||
fun selectedColorScheme(): Int = SettingsController.getInt(
|
||||
SettingsKeys.KEY_APPEARANCE_COLOR_SCHEME,
|
||||
SettingsKeys.DEFAULT_VALUE_APPEARANCE_COLOR_SCHEME
|
||||
)
|
||||
|
||||
fun isUsingBlur(): Boolean = SettingsController.getBoolean(
|
||||
SettingsKeys.KEY_APPEARANCE_BLUR,
|
||||
SettingsKeys.DEFAULT_VALUE_KEY_APPEARANCE_BLUR
|
||||
)
|
||||
|
||||
fun isDebugSettingsShown(): Boolean = SettingsController.getBoolean(
|
||||
SettingsKeys.KEY_SHOW_DEBUG_CATEGORY,
|
||||
false
|
||||
)
|
||||
|
||||
fun isMultiline(): Boolean = SettingsController.getBoolean(
|
||||
SettingsKeys.KEY_APPEARANCE_MULTILINE,
|
||||
SettingsKeys.DEFAULT_VALUE_MULTILINE
|
||||
)
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.meloda.app.fast.datastore
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
object SettingsController {
|
||||
|
||||
private var preferences: SharedPreferences by Delegates.notNull()
|
||||
|
||||
fun init(preferences: SharedPreferences) {
|
||||
this.preferences = preferences
|
||||
}
|
||||
|
||||
fun edit(
|
||||
commit: Boolean = false,
|
||||
action: SharedPreferences.Editor.() -> Unit
|
||||
) {
|
||||
preferences.edit(commit, action)
|
||||
}
|
||||
|
||||
fun getString(key: String, defaultValue: String?): String? {
|
||||
return preferences.getString(key, defaultValue)
|
||||
}
|
||||
|
||||
fun getBoolean(key: String, defaultValue: Boolean): Boolean {
|
||||
return preferences.getBoolean(key, defaultValue)
|
||||
}
|
||||
|
||||
fun getInt(key: String, defaultValue: Int): Int {
|
||||
return preferences.getInt(key, defaultValue)
|
||||
}
|
||||
|
||||
fun getLong(key: String, defaultValue: Long): Long {
|
||||
return preferences.getLong(key, defaultValue)
|
||||
}
|
||||
|
||||
fun getFloat(key: String, defaultValue: Float): Float {
|
||||
return preferences.getFloat(key, defaultValue)
|
||||
}
|
||||
|
||||
fun <T> put(key: String, newValue: T?) {
|
||||
preferences.edit {
|
||||
when (newValue) {
|
||||
is String -> putString(key, newValue)
|
||||
is Boolean -> putBoolean(key, newValue)
|
||||
is Int -> putInt(key, newValue)
|
||||
is Long -> putLong(key, newValue)
|
||||
is Float -> putFloat(key, newValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.meloda.app.fast.datastore
|
||||
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
|
||||
object SettingsKeys {
|
||||
const val KEY_ACCOUNT = "account"
|
||||
const val KEY_ACCOUNT_LOGOUT = "account_logout"
|
||||
|
||||
const val KEY_GENERAL = "general"
|
||||
const val KEY_USE_CONTACT_NAMES = "general_use_contact_names"
|
||||
const val DEFAULT_VALUE_USE_CONTACT_NAMES = false
|
||||
const val KEY_SHOW_EMOJI_BUTTON = "general_show_emoji_button"
|
||||
const val DEFAULT_VALUE_KEY_SHOW_EMOJI_BUTTON = false
|
||||
|
||||
const val KEY_APPEARANCE = "appearance"
|
||||
const val KEY_APPEARANCE_MULTILINE = "appearance_multiline"
|
||||
const val DEFAULT_VALUE_MULTILINE = true
|
||||
const val KEY_APPEARANCE_DARK_THEME = "appearance_appearance_dark_theme"
|
||||
const val DEFAULT_VALUE_APPEARANCE_DARK_THEME = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
const val KEY_APPEARANCE_AMOLED_THEME = "appearance_amoled_theme"
|
||||
const val DEFAULT_VALUE_APPEARANCE_AMOLED_THEME = false
|
||||
const val KEY_USE_DYNAMIC_COLORS = "appearance_use_dynamic_colors"
|
||||
const val DEFAULT_VALUE_USE_DYNAMIC_COLORS = false
|
||||
const val KEY_APPEARANCE_COLOR_SCHEME = "appearance_color_scheme"
|
||||
const val DEFAULT_VALUE_APPEARANCE_COLOR_SCHEME = 0
|
||||
const val KEY_APPEARANCE_LANGUAGE = "appearance_language"
|
||||
const val KEY_APPEARANCE_BLUR = "appearance_blur"
|
||||
const val DEFAULT_VALUE_KEY_APPEARANCE_BLUR = false
|
||||
|
||||
const val KEY_FEATURES_HIDE_KEYBOARD_ON_SCROLL = "features_hide_keyboard_on_scroll"
|
||||
const val KEY_FEATURES_FAST_TEXT = "features_fast_text"
|
||||
const val DEFAULT_VALUE_FEATURES_FAST_TEXT = "¯\\_(ツ)_/¯"
|
||||
const val KEY_FEATURES_LONG_POLL_IN_BACKGROUND = "features_lp_background"
|
||||
const val DEFAULT_VALUE_FEATURES_LONG_POLL_IN_BACKGROUND = false
|
||||
|
||||
const val KEY_VISIBILITY_SEND_ONLINE_STATUS = "visibility_send_online_status"
|
||||
const val DEFAULT_VALUE_KEY_VISIBILITY_SEND_ONLINE_STATUS = false
|
||||
|
||||
const val KEY_DEBUG_PERFORM_CRASH = "debug_perform_crash"
|
||||
const val KEY_DEBUG_SHOW_CRASH_ALERT = "debug_show_crash_alert"
|
||||
const val KEY_DEBUG_HIDE_DEBUG_LIST = "debug_hide_debug_list"
|
||||
const val KEY_SHOW_EXACT_TIME_ON_TIME_STAMP = "wip_show_exact_time_on_time_stamp"
|
||||
const val KEY_SHOW_NAME_IN_BUBBLES = "debug_show_title_in_bubbles"
|
||||
const val KEY_SHOW_DATE_UNDER_BUBBLES = "debug_show_date_under_bubbles"
|
||||
const val KEY_ENABLE_ANIMATIONS_IN_MESSAGES = "debug_enable_animations_in_messages"
|
||||
|
||||
const val KEY_SHOW_DEBUG_CATEGORY = "show_debug_category"
|
||||
|
||||
const val ID_DMITRY = 37610580
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package com.meloda.app.fast.datastore
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.os.PowerManager
|
||||
import com.meloda.app.fast.datastore.model.ThemeConfig
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
|
||||
interface UserSettings {
|
||||
val theme: StateFlow<ThemeConfig>
|
||||
val longPollBackground: StateFlow<Boolean>
|
||||
val online: StateFlow<Boolean>
|
||||
val debugSettingsEnabled: StateFlow<Boolean>
|
||||
val useContactNames: StateFlow<Boolean>
|
||||
|
||||
fun updateUsingDarkTheme()
|
||||
fun useDarkThemeChanged(use: Boolean)
|
||||
fun useAmoledThemeChanged(use: Boolean)
|
||||
fun useDynamicColorsChanged(use: Boolean)
|
||||
fun useBlurChanged(use: Boolean)
|
||||
fun useMultiline(use: Boolean)
|
||||
fun setLongPollBackground(background: Boolean)
|
||||
fun setOnline(use: Boolean)
|
||||
fun enableDebugSettings(enable: Boolean)
|
||||
fun onUseContactNamesChanged(use: Boolean)
|
||||
}
|
||||
|
||||
class UserSettingsImpl(
|
||||
private val resources: Resources,
|
||||
private val powerManager: PowerManager
|
||||
) : UserSettings {
|
||||
|
||||
override val theme = MutableStateFlow(
|
||||
ThemeConfig(
|
||||
usingDarkStyle = isUsingDarkMode(resources, powerManager),
|
||||
usingDynamicColors = isUsingDynamicColors(),
|
||||
selectedColorScheme = selectedColorScheme(),
|
||||
usingAmoledBackground = isUsingAmoledBackground(),
|
||||
usingBlur = isUsingBlur(),
|
||||
multiline = isMultiline()
|
||||
)
|
||||
)
|
||||
|
||||
override val longPollBackground = MutableStateFlow(
|
||||
SettingsController.getBoolean(
|
||||
SettingsKeys.KEY_FEATURES_LONG_POLL_IN_BACKGROUND,
|
||||
SettingsKeys.DEFAULT_VALUE_FEATURES_LONG_POLL_IN_BACKGROUND
|
||||
)
|
||||
)
|
||||
override val online = MutableStateFlow(
|
||||
SettingsController.getBoolean(
|
||||
SettingsKeys.KEY_VISIBILITY_SEND_ONLINE_STATUS,
|
||||
SettingsKeys.DEFAULT_VALUE_KEY_VISIBILITY_SEND_ONLINE_STATUS
|
||||
)
|
||||
)
|
||||
|
||||
override val debugSettingsEnabled = MutableStateFlow(
|
||||
SettingsController.getBoolean(
|
||||
SettingsKeys.KEY_SHOW_DEBUG_CATEGORY,
|
||||
false
|
||||
)
|
||||
)
|
||||
|
||||
override val useContactNames = MutableStateFlow(
|
||||
SettingsController.getBoolean(
|
||||
SettingsKeys.KEY_USE_CONTACT_NAMES,
|
||||
SettingsKeys.DEFAULT_VALUE_USE_CONTACT_NAMES
|
||||
)
|
||||
)
|
||||
|
||||
override fun updateUsingDarkTheme() {
|
||||
useDarkThemeChanged(
|
||||
isUsingDarkMode(
|
||||
resources = resources,
|
||||
powerManager = powerManager,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun useDarkThemeChanged(use: Boolean) {
|
||||
theme.value = theme.value.copy(
|
||||
usingDarkStyle = use
|
||||
)
|
||||
}
|
||||
|
||||
override fun useAmoledThemeChanged(use: Boolean) {
|
||||
theme.value = theme.value.copy(
|
||||
usingAmoledBackground = use
|
||||
)
|
||||
}
|
||||
|
||||
override fun useDynamicColorsChanged(use: Boolean) {
|
||||
theme.value = theme.value.copy(usingDynamicColors = use)
|
||||
}
|
||||
|
||||
override fun useBlurChanged(use: Boolean) {
|
||||
theme.value = theme.value.copy(usingBlur = use)
|
||||
}
|
||||
|
||||
override fun useMultiline(use: Boolean) {
|
||||
theme.value = theme.value.copy(multiline = use)
|
||||
}
|
||||
|
||||
override fun setLongPollBackground(background: Boolean) {
|
||||
longPollBackground.value = background
|
||||
}
|
||||
|
||||
override fun setOnline(use: Boolean) {
|
||||
online.value = use
|
||||
}
|
||||
|
||||
override fun enableDebugSettings(enable: Boolean) {
|
||||
debugSettingsEnabled.update { enable }
|
||||
}
|
||||
|
||||
override fun onUseContactNamesChanged(use: Boolean) {
|
||||
useContactNames.update { use }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.meloda.app.fast.datastore.di
|
||||
|
||||
import com.meloda.app.fast.datastore.UserSettings
|
||||
import com.meloda.app.fast.datastore.UserSettingsImpl
|
||||
import org.koin.core.module.dsl.singleOf
|
||||
import org.koin.dsl.bind
|
||||
import org.koin.dsl.module
|
||||
|
||||
val dataStoreModule = module {
|
||||
singleOf(::UserSettingsImpl) bind UserSettings::class
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.meloda.app.fast.datastore.model
|
||||
|
||||
data class ThemeConfig(
|
||||
val usingDarkStyle: Boolean,
|
||||
val usingDynamicColors: Boolean,
|
||||
val selectedColorScheme: Int,
|
||||
val usingAmoledBackground: Boolean,
|
||||
val usingBlur: Boolean,
|
||||
val multiline: Boolean,
|
||||
val bubblesWithPinch: Boolean = true
|
||||
)
|
||||
Reference in New Issue
Block a user