Skip to content

Commit 3529c5c

Browse files
committed
Restore Base preferences
Signed-off-by: saulhdev <[email protected]>
1 parent b6bbda8 commit 3529c5c

File tree

13 files changed

+499
-52
lines changed

13 files changed

+499
-52
lines changed

gradle/libs.versions.toml

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
[versions]
2-
activity = "1.10.0"
2+
activity = "1.10.1"
33
agp = "8.10.0-alpha08"
44
alwan = "1.0.1"
55
androidx-animation = "1.0.0"
6-
androidx-annotation = "1.7.1"
6+
androidx-annotation = "1.9.1"
77
androidx-core = "1.15.0"
88
androidx-runner = "1.6.2"
99
androidx-rules = "1.6.1"
1010
androidx-test = "1.2.1"
1111
biometric = "1.2.0-alpha05"
1212
coil = "2.7.0"
13-
compose-bom = "2025.01.00"
13+
compose-bom = "2025.03.00"
1414
compose-accompanist = "0.36.0"
1515
coroutines = "1.9.0"
16-
constraint-layout = "2.2.0"
17-
coordinator-layout = "1.2.0"
18-
datastore = "1.1.2"
16+
constraint-layout = "2.2.1"
17+
coordinator-layout = "1.3.0"
18+
datastore = "1.1.3"
1919
dagger = "2.55"
2020
dynamic-animation = "1.1.0-alpha03"
2121
fuzzywuzzy = "1.4.0"
2222
hoko-blur = "1.5.3"
2323
immutables = "0.3.8"
2424
kotlin = "2.1.0"
25-
koin = "3.5.6"
26-
koin-ksp = "1.3.1"
25+
koin-bom = "4.1.0-Beta5"
26+
koin-compiler = "1.3.1"
2727
ksp = "2.1.0-1.0.29"
2828
lifecycle = "2.8.7"
2929
lifecycle-ext = "2.2.0"
@@ -55,37 +55,62 @@ uiautomator = "2.3.0"
5555
support-runner = "1.0.2"
5656
support-rules = "1.0.2"
5757
support-uiautomator = "2.1.3"
58-
annotation-jvm = "1.9.1"
5958

6059
[libraries]
6160
gradle = { module = "com.android.tools.build:gradle", version.ref = "agp" }
6261
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
6362
ksp = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
64-
preference = { module = "androidx.preference:preference-ktx", version.ref = "preference" }
65-
activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activity" }
6663
collections-immutable = { module = "org.jetbrains.kotlinx:kotlinx-collections-immutable", version.ref = "immutables" }
6764

6865
androidx-animation = { group = "androidx.core", name = "core-animation", version.ref = "androidx-animation" }
69-
androidx-annotation-jvm = { group = "androidx.annotation", name = "annotation-jvm", version.ref = "annotation-jvm" }
66+
androidx-dynamic-animation = { group = "androidx.dynamicanimation", name = "dynamicanimation", version.ref = "dynamic-animation" }
67+
androidx-annotation = { module = "androidx.annotation:annotation", version.ref = "androidx-annotation" }
7068
androidx-biometric = { module = "androidx.biometric:biometric", version.ref = "biometric" }
71-
androidx-constraint-layout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraint-layout" }
72-
androidx-coordinator-layout = { group = "androidx.coordinatorlayout", name = "coordinatorlayout", version.ref = "coordinator-layout" }
7369
androidx-core = { group = "androidx.core", name = "core-ktx", version.ref = "androidx-core" }
74-
androidx-dynamic-animation = { group = "androidx.dynamicanimation", name = "dynamicanimation", version.ref = "dynamic-animation" }
7570
androidx-palette = { group = "androidx.palette", name = "palette-ktx", version.ref = "palette" }
71+
androidx-constraint-layout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraint-layout" }
72+
androidx-coordinator-layout = { group = "androidx.coordinatorlayout", name = "coordinatorlayout", version.ref = "coordinator-layout" }
7673
androidx-recyclerview = { group = "androidx.recyclerview", name = "recyclerview", version.ref = "recycler-view" }
77-
androidx-annotation = { module = "androidx.annotation:annotation", version.ref = "androidx-annotation" }
74+
75+
preference = { module = "androidx.preference:preference-ktx", version.ref = "preference" }
76+
datastore-preferences = { module = "androidx.datastore:datastore-preferences", version.ref = "datastore" }
77+
78+
compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "compose-bom" }
79+
compose-activity = { module = "androidx.activity:activity-compose", version.ref = "activity" }
80+
compose-runtime = { module = "androidx.compose.runtime:runtime" }
81+
compose-ui = { group = "androidx.compose.ui", name = "ui" }
82+
compose-foundation = { module = "androidx.compose.foundation:foundation" }
83+
compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
84+
compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
85+
compose-navigation = { module = "androidx.navigation:navigation-compose", version.ref = "navigation" }
86+
87+
compose-material3 = { module = "androidx.compose.material3:material3" }
88+
compose-adaptive = { module = "androidx.compose.material3.adaptive:adaptive" }
89+
compose-adaptive-layout = { module = "androidx.compose.material3.adaptive:adaptive-layout", version.ref = "adaptive-layout" }
90+
compose-adaptive-navigation = { module = "androidx.compose.material3.adaptive:adaptive-navigation" }
91+
92+
lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycle" }
93+
lifecycle-common = { module = "androidx.lifecycle:lifecycle-common-java8", version.ref = "lifecycle" }
94+
lifecycle-livedata = { module = "androidx.lifecycle:lifecycle-livedata-ktx", version.ref = "lifecycle" }
95+
lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "lifecycle" }
96+
lifecycle-extensions = { module = "androidx.lifecycle:lifecycle-extensions", version.ref = "lifecycle-ext" }
97+
98+
room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
99+
room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }
100+
room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
101+
78102
androidx-test-junit = { module = "androidx.test.ext:junit", version.ref = "androidx-test" }
79103
androidx-test-runner = { module = "androidx.test:runner", version.ref = "androidx-runner" }
80104
androidx-test-rules = { module = "androidx.test:rules", version.ref = "androidx-rules" }
81105

82106
material = { module = "com.google.android.material:material", version.ref = "material" }
107+
material-kolor = { module = "com.materialkolor:material-kolor", version.ref = "material-kolor" }
108+
83109
coil-compose = { group = "io.coil-kt", name = "coil-compose", version.ref = "coil" }
84110
serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "serialization" }
85-
datastore-preferences = { module = "androidx.datastore:datastore-preferences", version.ref = "datastore" }
86111
slice = { module = "androidx.slice:slice-core", version.ref = "slice" }
87112
protobuf-javalite = { module = "com.google.protobuf:protobuf-javalite", version.ref = "protobuf-lib" }
88-
113+
compose-reorderable = { module = "sh.calvin.reorderable:reorderable", version.ref = "reorderable" }
89114
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
90115
owm = { module = "com.github.KwabenBerko:OpenWeatherMap-Android-Library", version.ref = "owm" }
91116
simple-storage = { module = "com.anggrayudi:storage", version.ref = "simple-storage" }
@@ -98,37 +123,20 @@ fuzzywuzzy = { module = "me.xdrop:fuzzywuzzy", version.ref = "fuzzywuzzy" }
98123
dagger-hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "dagger" }
99124
dagger-hilt-compiler = { module = "com.google.dagger:hilt-compiler", version.ref = "dagger" }
100125

101-
lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycle" }
102-
lifecycle-common = { module = "androidx.lifecycle:lifecycle-common-java8", version.ref = "lifecycle" }
103-
lifecycle-livedata = { module = "androidx.lifecycle:lifecycle-livedata-ktx", version.ref = "lifecycle" }
104-
lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "lifecycle" }
105-
lifecycle-extensions = { module = "androidx.lifecycle:lifecycle-extensions", version.ref = "lifecycle-ext" }
106-
107126
coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "coroutines" }
108127

109-
koin-android = { group = "io.insert-koin", name = "koin-android", version.ref = "koin" }
110-
koin-workmanager = { group = "io.insert-koin", name = "koin-androidx-workmanager", version.ref = "koin" }
111-
koin-annotations = { group = "io.insert-koin", name = "koin-annotations", version.ref = "koin-ksp" }
112-
koin-compiler = { group = "io.insert-koin", name = "koin-ksp-compiler", version.ref = "koin-ksp" }
113-
114-
room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
115-
room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }
116-
room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
128+
koin-bom = { group = "io.insert-koin", name = "koin-bom", version.ref = "koin-bom" }
129+
koin-android = { group = "io.insert-koin", name = "koin-android" }
130+
koin-core = { group = "io.insert-koin", name = "koin-core" }
131+
koin-core-viewmodel = { group = "io.insert-koin", name = "koin-core-viewmodel" }
132+
koin-compose = { group = "io.insert-koin", name = "koin-compose" }
133+
koin-androidx-compose = { group = "io.insert-koin", name = "koin-androidx-compose" }
134+
koin-androidx-startup = { group = "io.insert-koin", name = "koin-androidx-startup" }
135+
koin-androidx-navigation = { group = "io.insert-koin", name = "koin-androidx-navigation" }
136+
koin-androidx-workmanager = { group = "io.insert-koin", name = "koin-androidx-workmanager" }
137+
koin-ksp-compiler = { group = "io.insert-koin", name = "koin-ksp-compiler", version.ref = "koin-compiler" }
117138

118-
compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "compose-bom" }
119-
compose-runtime = { module = "androidx.compose.runtime:runtime" }
120-
compose-ui = { group = "androidx.compose.ui", name = "ui" }
121-
compose-foundation = { module = "androidx.compose.foundation:foundation" }
122-
compose-material3 = { module = "androidx.compose.material3:material3" }
123-
compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
124-
compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
125-
compose-navigation = { module = "androidx.navigation:navigation-compose", version.ref = "navigation" }
126-
compose-reorderable = { module = "sh.calvin.reorderable:reorderable", version.ref = "reorderable" }
127-
compose-adaptive = { module = "androidx.compose.material3.adaptive:adaptive" }
128-
compose-adaptive-layout = { module = "androidx.compose.material3.adaptive:adaptive-layout", version.ref = "adaptive-layout" }
129-
compose-adaptive-navigation = { module = "androidx.compose.material3.adaptive:adaptive-navigation" }
130139
accompanist-drawablepainter = { module = "com.google.accompanist:accompanist-drawablepainter", version.ref = "compose-accompanist" }
131-
material-kolor = { module = "com.materialkolor:material-kolor", version.ref = "material-kolor" }
132140

133141
junit = { module = "junit:junit", version.ref = "junit" }
134142
junit5 = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit5" }

neo_launcher/src/com/neoapps/launcher/NeoLauncher.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,23 @@
1717

1818
package com.neoapps.launcher
1919

20+
import android.content.Context
21+
import android.content.ContextWrapper
2022
import com.android.launcher3.Launcher
23+
import com.android.launcher3.LauncherAppState
24+
import com.neoapps.launcher.preferences.NeoPrefs
25+
import com.neoapps.launcher.util.CoreUtils
26+
2127

2228
class NeoLauncher: Launcher() {
29+
val prefs: NeoPrefs by lazy { CoreUtils.getNeoPrefs() }
30+
31+
companion object {
32+
@JvmStatic
33+
fun getLauncher(context: Context): NeoLauncher {
34+
return context as? NeoLauncher
35+
?: (context as ContextWrapper).baseContext as? NeoLauncher
36+
?: LauncherAppState.getInstance(context).launcher as NeoLauncher
37+
}
38+
}
2339
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* This file is part of Neo Launcher
3+
* Copyright (c) 2021 Neo Launcher Team
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
*/
17+
18+
package com.neoapps.launcher.iconpack
19+
20+
data class IconEntry(
21+
val packPackageName: String,
22+
val name: String,
23+
val type: IconType
24+
) {
25+
fun resolveDynamicCalendar(day: Int): IconEntry {
26+
if (type != IconType.Calendar) throw IllegalStateException("type is not calendar")
27+
return IconEntry(packPackageName, "$name${day + 1}", IconType.Normal)
28+
}
29+
}
30+
31+
enum class IconType {
32+
Normal, Calendar
33+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
* This file is part of Neo Launcher
3+
* Copyright (c) 2023 Neo Launcher Team
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
*/
17+
18+
package com.neoapps.launcher.preferences
19+
20+
import androidx.annotation.StringRes
21+
import androidx.compose.runtime.Composable
22+
import androidx.compose.runtime.State
23+
import androidx.compose.runtime.collectAsState
24+
import androidx.datastore.core.DataStore
25+
import androidx.datastore.preferences.core.Preferences
26+
import androidx.datastore.preferences.core.edit
27+
import com.neoapps.launcher.navigation.NavRoute
28+
import com.neoapps.launcher.theme.AccentColorOption
29+
import com.neoapps.launcher.util.runOnMainThread
30+
import kotlinx.coroutines.Dispatchers
31+
import kotlinx.coroutines.flow.Flow
32+
import kotlinx.coroutines.flow.firstOrNull
33+
import kotlinx.coroutines.flow.map
34+
import kotlinx.coroutines.runBlocking
35+
36+
open class BooleanPref(
37+
@StringRes titleId: Int,
38+
@StringRes summaryId: Int = -1,
39+
dataStore: DataStore<Preferences>,
40+
key: Preferences.Key<Boolean>,
41+
defaultValue: Boolean = false,
42+
onChange: (Boolean) -> Unit = {}
43+
) : BasePreference<Boolean>(titleId, summaryId, dataStore, key, defaultValue, onChange)
44+
45+
open class IntSelectionPref(
46+
@StringRes titleId: Int,
47+
@StringRes summaryId: Int = -1,
48+
dataStore: DataStore<Preferences>,
49+
key: Preferences.Key<Int>,
50+
val defaultValue: Int = 0,
51+
val entries: Map<Int, Int>,
52+
onChange: (Int) -> Unit = {}
53+
) : BasePreference<Int>(titleId, summaryId, dataStore, key, defaultValue, onChange)
54+
55+
open class LongMultiSelectionPref(
56+
@StringRes titleId: Int,
57+
@StringRes summaryId: Int = -1,
58+
private val dataStore: DataStore<Preferences>,
59+
private val key: Preferences.Key<Set<String>>,
60+
val defaultValue: Set<Long> = emptySet(),
61+
val entries: () -> Map<Long, String>,
62+
onChange: (Set<Long>) -> Unit = { }
63+
) : BasePreference<Set<String>>(
64+
titleId,
65+
summaryId,
66+
dataStore,
67+
key,
68+
defaultValue.mapTo(mutableSetOf()) { it.toString() },
69+
{ set -> onChange(set.mapTo(mutableSetOf()) { it.toLong() }) }
70+
) {
71+
private val valueList = arrayListOf<String>()
72+
73+
init {
74+
runBlocking(Dispatchers.IO) {
75+
valueList.addAll(getValue())
76+
}
77+
}
78+
79+
fun getAll(): List<Long> = valueList.map { it.toLong() }
80+
81+
fun setAll(value: List<Long>) {
82+
valueList.clear()
83+
valueList.addAll(value.map { it.toString() })
84+
return runBlocking(Dispatchers.IO) {
85+
saveChanges()
86+
}
87+
}
88+
89+
private suspend fun saveChanges() {
90+
dataStore.edit { it[key] = valueList.toSet() }
91+
}
92+
}
93+
94+
open class ColorIntPref(
95+
@StringRes titleId: Int,
96+
@StringRes summaryId: Int = -1,
97+
dataStore: DataStore<Preferences>,
98+
val defaultValue: String = "system_accent",
99+
key: Preferences.Key<String>,
100+
val navRoute: NavRoute,
101+
onChange: (String) -> Unit = {}
102+
) : BasePreference<String>(titleId, summaryId, dataStore, key, defaultValue, onChange) {
103+
104+
fun getColor(): Int {
105+
return runBlocking(Dispatchers.IO) {
106+
AccentColorOption.fromString(getValue()).accentColor
107+
}
108+
}
109+
110+
@Composable
111+
fun getColorFromState(): Int {
112+
return AccentColorOption.fromString(getState().value).accentColor
113+
}
114+
}
115+
116+
open class StringSetPref(
117+
@StringRes titleId: Int,
118+
@StringRes summaryId: Int = -1,
119+
dataStore: DataStore<Preferences>,
120+
key: Preferences.Key<Set<String>>,
121+
val navRoute: NavRoute,
122+
val defaultValue: Set<String> = emptySet(),
123+
onChange: (Set<String>) -> Unit = {}
124+
) : BasePreference<Set<String>>(titleId, summaryId, dataStore, key, defaultValue, onChange)
125+
126+
abstract class BasePreference<T : Any>(
127+
@StringRes var titleId: Int,
128+
@StringRes var summaryId: Int = -1,
129+
private val dataStore: DataStore<Preferences>,
130+
private val key: Preferences.Key<T>,
131+
private val defaultValue: T,
132+
val onChange: (T) -> Unit
133+
) {
134+
fun getValue(): T {
135+
return runBlocking(Dispatchers.IO) {
136+
get().firstOrNull() ?: defaultValue
137+
}
138+
}
139+
140+
@Composable
141+
fun getState(): State<T> {
142+
return get().collectAsState(initial = defaultValue)
143+
}
144+
145+
fun setValue(value: T) {
146+
return runBlocking(Dispatchers.IO) {
147+
set(value)
148+
}
149+
}
150+
151+
open fun get(): Flow<T> {
152+
return dataStore.data.map { prefs -> prefs[key] ?: defaultValue }
153+
}
154+
155+
protected open suspend fun set(value: T) {
156+
if (getValue() == value) return
157+
dataStore.edit { prefs -> prefs[key] = value }
158+
runOnMainThread {
159+
onChange(value)
160+
}
161+
}
162+
}

0 commit comments

Comments
 (0)