Skip to content

Commit d18ad18

Browse files
Remove: Custom Themes, Accent Color Toggle,
1 parent 7fe9aa7 commit d18ad18

File tree

12 files changed

+128
-601
lines changed

12 files changed

+128
-601
lines changed

app/src/main/java/com/github/droidworksstudio/mlauncher/MainActivity.kt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import android.view.KeyEvent
1414
import android.view.View
1515
import android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
1616
import androidx.appcompat.app.AppCompatActivity
17-
import androidx.appcompat.app.AppCompatDelegate
1817
import androidx.lifecycle.ViewModelProvider
1918
import androidx.navigation.NavController
2019
import androidx.navigation.Navigation
2120
import com.github.droidworksstudio.common.showLongToast
2221
import com.github.droidworksstudio.mlauncher.data.Constants
22+
import com.github.droidworksstudio.mlauncher.data.Migration
2323
import com.github.droidworksstudio.mlauncher.data.Prefs
2424
import com.github.droidworksstudio.mlauncher.databinding.ActivityMainBinding
2525
import com.github.droidworksstudio.mlauncher.helper.hasUsagePermission
@@ -32,6 +32,7 @@ import java.io.InputStreamReader
3232
class MainActivity : AppCompatActivity() {
3333

3434
private lateinit var prefs: Prefs
35+
private lateinit var migration: Migration
3536
private lateinit var navController: NavController
3637
private lateinit var viewModel: MainViewModel
3738
private lateinit var binding: ActivityMainBinding
@@ -95,19 +96,14 @@ class MainActivity : AppCompatActivity() {
9596

9697
override fun onCreate(savedInstanceState: Bundle?) {
9798
prefs = Prefs(this)
98-
val themeMode = when (prefs.appTheme) {
99-
Constants.Theme.Light -> AppCompatDelegate.MODE_NIGHT_NO
100-
Constants.Theme.Dark -> AppCompatDelegate.MODE_NIGHT_YES
101-
Constants.Theme.System -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
102-
}
103-
AppCompatDelegate.setDefaultNightMode(themeMode)
99+
migration = Migration(this)
104100

105101
super.onCreate(savedInstanceState)
106102
binding = ActivityMainBinding.inflate(layoutInflater)
107103
val view = binding.root
108104
setContentView(view)
109-
110105
setLanguage()
106+
migration.migratePreferencesOnVersionUpdate(prefs)
111107

112108
navController = Navigation.findNavController(this, R.id.nav_host_fragment)
113109
viewModel = ViewModelProvider(this)[MainViewModel::class.java]
@@ -125,7 +121,7 @@ class MainActivity : AppCompatActivity() {
125121

126122
// Get the version and info of any app by passing app name. (maybe later used for Pro features if I want top release them for the play store)
127123
// pm = packageManager
128-
// val getAppVersionAndHash = AppDetailsHelper.getAppVersionAndHash(this, "app.olauncher.debug", pm)
124+
// val getAppVersionAndHash = AppDetailsHelper.getAppVersionAndHash(this, "app.mlauncher.debug", pm)
129125
// Log.d("isPremiumInstalled", getAppVersionAndHash.toString())
130126

131127
if (prefs.recentAppsDisplayed || prefs.appUsageStats) {
@@ -145,7 +141,6 @@ class MainActivity : AppCompatActivity() {
145141

146142
@Deprecated("Deprecated in Java")
147143
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
148-
@Suppress("DEPRECATION")
149144
super.onActivityResult(requestCode, resultCode, data)
150145

151146
if (resultCode != RESULT_OK) {

app/src/main/java/com/github/droidworksstudio/mlauncher/data/Constants.kt

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -298,63 +298,18 @@ object Constants {
298298
}
299299
}
300300

301-
enum class DarkColors : EnumOption {
302-
System,
303-
Dracula,
304-
Arc,
305-
Nokto,
306-
Breeze,
307-
Catppuccino,
308-
Nordic,
309-
Yaru;
310-
311-
@Composable
312-
override fun string(): String {
313-
return when (this) {
314-
System -> stringResource(R.string.lang_system)
315-
Dracula -> stringResource(R.string.dracula)
316-
Arc -> stringResource(R.string.arc)
317-
Nokto -> stringResource(R.string.nokto)
318-
Breeze -> stringResource(R.string.breeze)
319-
Catppuccino -> stringResource(R.string.catppuccino)
320-
Nordic -> stringResource(R.string.nordic)
321-
Yaru -> stringResource(R.string.yaru)
322-
}
323-
}
324-
}
325-
326-
enum class LightColors : EnumOption {
327-
System,
328-
Adwaita,
329-
Catppuccino,
330-
Nordic;
331-
332-
@Composable
333-
override fun string(): String {
334-
return when (this) {
335-
System -> stringResource(R.string.lang_system)
336-
Adwaita -> stringResource(R.string.adwaita)
337-
Catppuccino -> stringResource(R.string.catppuccino)
338-
Nordic -> stringResource(R.string.nordic)
339-
}
340-
}
341-
}
342-
343301
enum class Fonts : EnumOption {
344302
System,
345303
Bitter,
346304
Dotness,
347305
DroidSans,
348-
349-
// GreatVibes,
306+
GreatVibes,
350307
Lato,
351-
352-
// Lobster,
308+
Lobster,
353309
Merriweather,
354310
Montserrat,
355311
OpenSans,
356-
357-
// Pacifico,
312+
Pacifico,
358313
Quicksand,
359314
Raleway,
360315
Roboto,
@@ -366,13 +321,13 @@ object Constants {
366321
Bitter -> ResourcesCompat.getFont(context, R.font.bitter)
367322
Dotness -> ResourcesCompat.getFont(context, R.font.dotness)
368323
DroidSans -> ResourcesCompat.getFont(context, R.font.open_sans)
369-
// GreatVibes -> ResourcesCompat.getFont(context, R.font.great_vibes)
324+
GreatVibes -> ResourcesCompat.getFont(context, R.font.great_vibes)
370325
Lato -> ResourcesCompat.getFont(context, R.font.lato)
371-
// Lobster -> ResourcesCompat.getFont(context, R.font.lobster)
326+
Lobster -> ResourcesCompat.getFont(context, R.font.lobster)
372327
Merriweather -> ResourcesCompat.getFont(context, R.font.merriweather)
373328
Montserrat -> ResourcesCompat.getFont(context, R.font.montserrat)
374329
OpenSans -> ResourcesCompat.getFont(context, R.font.open_sans)
375-
// Pacifico -> ResourcesCompat.getFont(context, R.font.pacifico)
330+
Pacifico -> ResourcesCompat.getFont(context, R.font.pacifico)
376331
Quicksand -> ResourcesCompat.getFont(context, R.font.quicksand)
377332
Raleway -> ResourcesCompat.getFont(context, R.font.raleway)
378333
Roboto -> ResourcesCompat.getFont(context, R.font.roboto)
@@ -387,13 +342,13 @@ object Constants {
387342
Bitter -> stringResource(R.string.settings_font_bitter)
388343
Dotness -> stringResource(R.string.settings_font_dotness)
389344
DroidSans -> stringResource(R.string.settings_font_droidsans)
390-
// GreatVibes -> stringResource(R.string.settings_font_greatvibes)
345+
GreatVibes -> stringResource(R.string.settings_font_greatvibes)
391346
Lato -> stringResource(R.string.settings_font_lato)
392-
// Lobster -> stringResource(R.string.settings_font_lobster)
347+
Lobster -> stringResource(R.string.settings_font_lobster)
393348
Merriweather -> stringResource(R.string.settings_font_merriweather)
394349
Montserrat -> stringResource(R.string.settings_font_montserrat)
395350
OpenSans -> stringResource(R.string.settings_font_opensans)
396-
// Pacifico -> stringResource(R.string.settings_font_pacifico)
351+
Pacifico -> stringResource(R.string.settings_font_pacifico)
397352
Quicksand -> stringResource(R.string.settings_font_quicksand)
398353
Raleway -> stringResource(R.string.settings_font_raleway)
399354
Roboto -> stringResource(R.string.settings_font_roboto)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.github.droidworksstudio.mlauncher.data
2+
3+
import android.content.Context
4+
import com.github.droidworksstudio.mlauncher.BuildConfig
5+
6+
class Migration(val context: Context) {
7+
fun migratePreferencesOnVersionUpdate(prefs: Prefs) {
8+
val currentVersionCode = BuildConfig.VERSION_CODE
9+
val savedVersionCode = prefs.appVersion
10+
11+
// Define a map of version code -> preferences to clear
12+
val versionCleanupMap = mapOf(
13+
171 to listOf(
14+
"APP_DARK_COLORS",
15+
"APP_LIGHT_COLORS",
16+
"HOME_FOLLOW_ACCENT"
17+
), // Version 171 Removes these from Prefs
18+
// Add more versions and preferences to remove here
19+
)
20+
21+
// Iterate over the versions and clear the relevant preferences
22+
for ((version, keys) in versionCleanupMap) {
23+
// Only clear preferences for versions between savedVersionCode and currentVersionCode
24+
if (version in (savedVersionCode + 1)..currentVersionCode) {
25+
// Remove the preferences for this version
26+
keys.forEach { key ->
27+
prefs.remove(key)
28+
}
29+
}
30+
}
31+
32+
// Update the stored version code after cleanup
33+
prefs.appVersion = currentVersionCode
34+
}
35+
}

app/src/main/java/com/github/droidworksstudio/mlauncher/data/Prefs.kt

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import com.github.droidworksstudio.mlauncher.helper.getUserHandleFromString
99
import com.google.gson.Gson
1010
import com.google.gson.reflect.TypeToken
1111

12-
private const val APP_LANGUAGE = "app_language"
1312
private const val PREFS_FILENAME = "com.github.droidworksstudio.mlauncher"
1413

14+
private const val APP_VERSION = "APP_VERSION"
1515
private const val FIRST_OPEN = "FIRST_OPEN"
1616
private const val FIRST_SETTINGS_OPEN = "FIRST_SETTINGS_OPEN"
1717
private const val LOCK_MODE = "LOCK_MODE"
@@ -26,7 +26,6 @@ private const val FILTER_STRENGTH = "FILTER_STRENGTH"
2626
private const val HOME_ALIGNMENT = "HOME_ALIGNMENT"
2727
private const val HOME_ALIGNMENT_BOTTOM = "HOME_ALIGNMENT_BOTTOM"
2828
private const val HOME_CLICK_AREA = "HOME_CLICK_AREA"
29-
private const val HOME_FOLLOW_ACCENT = "HOME_FOLLOW_ACCENT"
3029
private const val DRAWER_ALIGNMENT = "DRAWER_ALIGNMENT"
3130
private const val TIME_ALIGNMENT = "TIME_ALIGNMENT"
3231
private const val STATUS_BAR = "STATUS_BAR"
@@ -53,20 +52,16 @@ private const val DOUBLE_TAP_ACTION = "DOUBLE_TAP_ACTION"
5352
private const val HIDDEN_APPS = "HIDDEN_APPS"
5453
private const val HIDDEN_APPS_DISPLAYED = "HIDDEN_APPS_DISPLAYED"
5554
private const val SEARCH_ENGINE = "SEARCH_ENGINE"
56-
5755
private const val LAUNCHER_FONT = "LAUNCHER_FONT"
58-
5956
private const val APP_NAME = "APP_NAME"
6057
private const val APP_PACKAGE = "APP_PACKAGE"
6158
private const val APP_USER = "APP_USER"
6259
private const val APP_ALIAS = "APP_ALIAS"
6360
private const val APP_ACTIVITY = "APP_ACTIVITY"
6461
private const val APP_USAGE_STATS = "APP_USAGE_STATS"
6562
private const val APP_OPACITY = "APP_OPACITY"
66-
private const val APP_DARK_COLORS = "APP_DARK_COLORS"
67-
private const val APP_LIGHT_COLORS = "APP_LIGHT_COLORS"
63+
private const val APP_LANGUAGE = "APP_LANGUAGE"
6864
private const val APP_THEME = "APP_THEME"
69-
7065
private const val SHORT_SWIPE_UP = "SHORT_SWIPE_UP"
7166
private const val SHORT_SWIPE_DOWN = "SHORT_SWIPE_DOWN"
7267
private const val SHORT_SWIPE_LEFT = "SHORT_SWIPE_LEFT"
@@ -80,7 +75,6 @@ private const val CLICK_USAGE = "CLICK_USAGE"
8075
private const val CLICK_DATE = "CLICK_DATE"
8176
private const val DOUBLE_TAP = "DOUBLE_TAP"
8277
private const val ALL_APPS_TEXT = "ALL_APPS_TEXT"
83-
8478
private const val APP_SIZE_TEXT = "APP_SIZE_TEXT"
8579
private const val CLOCK_SIZE_TEXT = "CLOCK_SIZE_TEXT"
8680
private const val DATE_SIZE_TEXT = "DATE_SIZE_TEXT"
@@ -126,6 +120,10 @@ class Prefs(val context: Context) {
126120
editor.apply()
127121
}
128122

123+
var appVersion: Int
124+
get() = prefs.getInt(APP_VERSION, -1)
125+
set(value) = prefs.edit().putInt(APP_VERSION, value).apply()
126+
129127
var firstOpen: Boolean
130128
get() = prefs.getBoolean(FIRST_OPEN, true)
131129
set(value) = prefs.edit().putBoolean(FIRST_OPEN, value).apply()
@@ -256,10 +254,6 @@ class Prefs(val context: Context) {
256254
get() = prefs.getBoolean(ALL_APPS_TEXT, true)
257255
set(value) = prefs.edit().putBoolean(ALL_APPS_TEXT, value).apply()
258256

259-
var followAccentColors: Boolean
260-
get() = prefs.getBoolean(HOME_FOLLOW_ACCENT, false)
261-
set(value) = prefs.edit().putBoolean(HOME_FOLLOW_ACCENT, value).apply()
262-
263257
var shortSwipeUpAction: Constants.Action
264258
get() = loadAction(SWIPE_UP_ACTION, Constants.Action.ShowAppList)
265259
set(value) = storeAction(SWIPE_UP_ACTION, value)
@@ -332,30 +326,6 @@ class Prefs(val context: Context) {
332326
}
333327
set(value) = prefs.edit().putString(APP_THEME, value.name).apply()
334328

335-
var appDarkColors: Constants.DarkColors
336-
get() {
337-
return try {
338-
Constants.DarkColors.valueOf(
339-
prefs.getString(APP_DARK_COLORS, Constants.DarkColors.System.name).toString()
340-
)
341-
} catch (_: Exception) {
342-
Constants.DarkColors.System
343-
}
344-
}
345-
set(value) = prefs.edit().putString(APP_DARK_COLORS, value.name).apply()
346-
347-
var appLightColors: Constants.LightColors
348-
get() {
349-
return try {
350-
Constants.LightColors.valueOf(
351-
prefs.getString(APP_LIGHT_COLORS, Constants.LightColors.System.name).toString()
352-
)
353-
} catch (_: Exception) {
354-
Constants.LightColors.System
355-
}
356-
}
357-
set(value) = prefs.edit().putString(APP_LIGHT_COLORS, value.name).apply()
358-
359329
var language: Constants.Language
360330
get() {
361331
return try {
@@ -583,6 +553,10 @@ class Prefs(val context: Context) {
583553
prefs.edit().putString(appPackage, appAlias).apply()
584554
}
585555

556+
fun remove(prefName: String) {
557+
prefs.edit().remove(prefName).apply()
558+
}
559+
586560
fun clear() {
587561
prefs.edit().clear().apply()
588562
}

0 commit comments

Comments
 (0)