Skip to content

Commit 89db56c

Browse files
committed
Extract all preferences usages to utilities class
1 parent e789d1e commit 89db56c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+963
-790
lines changed

app/src/main/java/com/drdisagree/colorblendr/data/common/Const.kt renamed to app/src/main/java/com/drdisagree/colorblendr/data/common/Constant.kt

Lines changed: 38 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.drdisagree.colorblendr.data.common
22

33
import com.drdisagree.colorblendr.BuildConfig
4-
import com.drdisagree.colorblendr.data.config.Prefs
5-
import com.drdisagree.colorblendr.data.database.appDatabase
6-
import com.drdisagree.colorblendr.data.repository.CustomStyleRepository
4+
import com.drdisagree.colorblendr.data.common.Utilities.modeSpecificThemesEnabled
5+
import com.drdisagree.colorblendr.data.enums.WorkMethod
76
import com.drdisagree.colorblendr.utils.SystemUtil
87
import com.google.gson.Gson
9-
import com.google.gson.reflect.TypeToken
108

11-
object Const {
9+
object Constant {
10+
1211
// Preferences file
1312
private const val OWN_PACKAGE_NAME = BuildConfig.APPLICATION_ID
1413
const val SHARED_PREFS = "${OWN_PACKAGE_NAME}_preferences"
@@ -29,6 +28,16 @@ object Const {
2928
const val SETTINGS_SEARCH = "com.google.android.settings.intelligence"
3029
const val PIXEL_LAUNCHER = "com.google.android.apps.nexuslauncher"
3130

31+
// Request codes
32+
const val SHIZUKU_PERMISSION_REQUEST_ID = 100
33+
34+
// Overlay constants
35+
const val FABRICATED_OVERLAY_SOURCE_PACKAGE = FRAMEWORK_PACKAGE
36+
const val FABRICATED_OVERLAY_NAME_SYSTEM = "${OWN_PACKAGE_NAME}_dynamic_theme"
37+
const val FABRICATED_OVERLAY_NAME_SYSTEMUI = "${OWN_PACKAGE_NAME}_dynamic_theme_system"
38+
const val FABRICATED_OVERLAY_NAME_APPS = "$OWN_PACKAGE_NAME.%s_dynamic_theme"
39+
const val THEME_CUSTOMIZATION_OVERLAY_PACKAGES = "theme_customization_overlay_packages"
40+
3241
// General preferences
3342
const val FIRST_RUN = "firstRun"
3443
const val THEMING_ENABLED = "themingEnabled"
@@ -39,26 +48,6 @@ object Const {
3948
const val DARKER_LAUNCHER_ICONS = "darkerLauncherIcons"
4049
const val SEMI_TRANSPARENT_LAUNCHER_ICONS = "semiTransparentLauncherIcons"
4150
const val FORCE_PITCH_BLACK_SETTINGS = "forcePitchBlackSettings"
42-
private val modeSpecificThemes: Boolean
43-
get() = Prefs.getBoolean(MODE_SPECIFIC_THEMES, false)
44-
val MONET_ACCENT_SATURATION: String
45-
get() = if (!modeSpecificThemes) {
46-
"monetAccentSaturationValue"
47-
} else {
48-
if (SystemUtil.isDarkMode) "monetAccentSaturationValue" else "monetAccentSaturationValueLight"
49-
}
50-
val MONET_BACKGROUND_SATURATION: String
51-
get() = if (!modeSpecificThemes) {
52-
"monetBackgroundSaturationValue"
53-
} else {
54-
if (SystemUtil.isDarkMode) "monetBackgroundSaturationValue" else "monetBackgroundSaturationValueLight"
55-
}
56-
val MONET_BACKGROUND_LIGHTNESS: String
57-
get() = if (!modeSpecificThemes) {
58-
"monetBackgroundLightnessValue"
59-
} else {
60-
if (SystemUtil.isDarkMode) "monetBackgroundLightnessValue" else "monetBackgroundLightnessValueLight"
61-
}
6251
const val MONET_ACCURATE_SHADES = "monetAccurateShades"
6352
const val MONET_PITCH_BLACK_THEME = "monetPitchBlackTheme"
6453
const val MONET_SEED_COLOR_ENABLED = "monetSeedColorEnabled"
@@ -68,29 +57,42 @@ object Const {
6857
const val MANUAL_OVERRIDE_COLORS = "manualOverrideColors"
6958
const val MONET_LAST_UPDATED = "monetLastUpdated"
7059
const val MONET_STYLE_ORIGINAL_NAME = "monetStyleOriginalName"
71-
const val FABRICATED_OVERLAY_SOURCE_PACKAGE = FRAMEWORK_PACKAGE
72-
const val FABRICATED_OVERLAY_NAME_SYSTEM = "${OWN_PACKAGE_NAME}_dynamic_theme"
73-
const val FABRICATED_OVERLAY_NAME_SYSTEMUI = "${OWN_PACKAGE_NAME}_dynamic_theme_system"
74-
const val FABRICATED_OVERLAY_NAME_APPS = "$OWN_PACKAGE_NAME.%s_dynamic_theme"
7560
const val WALLPAPER_COLOR_LIST = "wallpaperColorList"
76-
private const val FABRICATED_OVERLAY_FOR_APPS_STATE = "fabricatedOverlayForAppsState"
61+
const val FABRICATED_OVERLAY_FOR_APPS_STATE = "fabricatedOverlayForAppsState"
7762
const val SHOW_PER_APP_THEME_WARN = "showPerAppThemeWarn"
7863
const val TINT_TEXT_COLOR = "tintTextColor"
79-
const val SHIZUKU_PERMISSION_REQUEST_ID = 100
80-
const val THEME_CUSTOMIZATION_OVERLAY_PACKAGES = "theme_customization_overlay_packages"
8164
const val SHIZUKU_THEMING_ENABLED = "shizukuThemingEnabled"
8265
const val APP_LIST_FILTER_METHOD = "appListFilterMethod"
66+
val MONET_ACCENT_SATURATION: String
67+
get() = if (!modeSpecificThemesEnabled()) {
68+
"monetAccentSaturationValue"
69+
} else {
70+
if (SystemUtil.isDarkMode) "monetAccentSaturationValue"
71+
else "monetAccentSaturationValueLight"
72+
}
73+
val MONET_BACKGROUND_SATURATION: String
74+
get() = if (!modeSpecificThemesEnabled()) {
75+
"monetBackgroundSaturationValue"
76+
} else {
77+
if (SystemUtil.isDarkMode) "monetBackgroundSaturationValue"
78+
else "monetBackgroundSaturationValueLight"
79+
}
80+
val MONET_BACKGROUND_LIGHTNESS: String
81+
get() = if (!modeSpecificThemesEnabled()) {
82+
"monetBackgroundLightnessValue"
83+
} else {
84+
if (SystemUtil.isDarkMode) "monetBackgroundLightnessValue"
85+
else "monetBackgroundLightnessValueLight"
86+
}
8387

8488
@Deprecated("Use of shared preferences for saving custom styles is deprecated, use room database instead")
8589
const val SAVED_CUSTOM_MONET_STYLES = "savedCustomMonetStyles"
8690

87-
val customStyleRepository = CustomStyleRepository(appDatabase.customStyleDao())
88-
8991
// Service preferences
9092
val GSON: Gson = Gson()
91-
private const val PREF_WORKING_METHOD = "workingMethod"
93+
const val PREF_WORKING_METHOD = "workingMethod"
9294

93-
var EXCLUDED_PREFS_FROM_BACKUP: Set<String> = HashSet(
95+
val EXCLUDED_PREFS_FROM_BACKUP: Set<String> = HashSet(
9496
listOf(
9597
FIRST_RUN,
9698
PREF_WORKING_METHOD,
@@ -101,63 +103,5 @@ object Const {
101103
)
102104
)
103105

104-
fun saveSelectedFabricatedApps(selectedApps: HashMap<String, Boolean>) {
105-
Prefs.putString(FABRICATED_OVERLAY_FOR_APPS_STATE, GSON.toJson(selectedApps))
106-
}
107-
108-
val selectedFabricatedApps: HashMap<String, Boolean>
109-
get() {
110-
val selectedApps = Prefs.getString(
111-
FABRICATED_OVERLAY_FOR_APPS_STATE,
112-
null
113-
)
114-
if (selectedApps.isNullOrEmpty()) {
115-
return HashMap()
116-
}
117-
118-
return GSON.fromJson(
119-
selectedApps,
120-
object :
121-
TypeToken<HashMap<String?, Boolean?>?>() {
122-
}.type
123-
)
124-
}
125-
126106
var WORKING_METHOD: WorkMethod = WorkMethod.NULL
127-
128-
val workingMethod: WorkMethod
129-
get() = WorkMethod.fromString(
130-
Prefs.getString(
131-
PREF_WORKING_METHOD,
132-
WorkMethod.NULL.toString()
133-
)
134-
)
135-
136-
fun saveWorkingMethod(workMethod: WorkMethod) {
137-
Prefs.putString(PREF_WORKING_METHOD, workMethod.toString())
138-
}
139-
140-
// Working method of app
141-
enum class WorkMethod {
142-
NULL,
143-
ROOT,
144-
SHIZUKU;
145-
146-
companion object {
147-
fun fromString(str: String?): WorkMethod {
148-
return try {
149-
valueOf(str!!)
150-
} catch (e: Exception) {
151-
NULL
152-
}
153-
}
154-
}
155-
}
156-
157-
enum class AppType {
158-
SYSTEM,
159-
USER,
160-
LAUNCHABLE,
161-
ALL
162-
}
163107
}

0 commit comments

Comments
 (0)