Skip to content

Commit d11d89d

Browse files
authored
fix(datastore): migrating away from jetpack compose (#347)
1 parent a5fc4f2 commit d11d89d

28 files changed

+667
-1080
lines changed

gradle/libs.versions.toml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ buildTools = "34.0.0"
1010
agp = "8.6.0"
1111
androidXCore = "1.6.0"
1212
androidXLifecycle = "2.8.7"
13-
compose = "1.7.7"
14-
composeCompiler = "1.5.10"
15-
composeMaterial3 = "1.3.1"
1613
detekt = "1.19.0"
1714
kotlin = "1.9.22"
1815
ktlint-plugin = "11.1.0"
@@ -56,14 +53,6 @@ androidx-preference = { module = "androidx.preference:preference-ktx", version =
5653
androidx-recyclerview = { module = "androidx.recyclerview:recyclerview", version = "1.2.1" }
5754
androidx-swiperefreshlayout = { module = "androidx.swiperefreshlayout:swiperefreshlayout", version = "1.1.0" }
5855

59-
compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" }
60-
compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "composeMaterial3" }
61-
compose-runtime = { module = "androidx.compose.runtime:runtime", version.ref = "compose" }
62-
compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" }
63-
compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
64-
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }
65-
constraintlayout-compose = { module = "androidx.constraintlayout:constraintlayout-compose", version = "1.0.1" }
66-
6756
datastore-preferences = { module = "androidx.datastore:datastore-preferences", version = "1.0.0" }
6857

6958
google-material = { module = "com.google.android.material:material", version = "1.6.1" }

pluto-plugins/plugins/datastore/lib/build.gradle.kts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plugins {
44
alias(libs.plugins.android.library)
55
alias(libs.plugins.kotlin.android)
66
alias(libs.plugins.maven.publish)
7+
alias(libs.plugins.ksp)
78
}
89

910
val version = Versioning.loadVersioningData()
@@ -15,17 +16,12 @@ android {
1516
namespace = "com.pluto.plugins.datastore.pref"
1617
resourcePrefix = "pluto_dts___"
1718

18-
composeOptions {
19-
kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get()
20-
}
21-
2219
compileSdk = libs.versions.compileSdk.get().toInt()
2320
buildToolsVersion = libs.versions.buildTools.get()
2421

2522
buildFeatures {
2623
buildConfig = true
2724
viewBinding = true
28-
compose = true
2925
}
3026

3127
defaultConfig {
@@ -102,13 +98,8 @@ dependencies {
10298
implementation(project(":pluto-plugins:base:lib"))
10399

104100
implementation(libs.androidx.core)
105-
implementation(libs.compose.material3)
106-
implementation(libs.compose.foundation)
107-
implementation(libs.compose.runtime)
108-
implementation(libs.compose.ui)
109-
implementation(libs.compose.ui.tooling)
110-
implementation(libs.compose.ui.tooling.preview)
111-
implementation(libs.constraintlayout.compose)
112-
113101
implementation(libs.datastore.preferences)
102+
103+
implementation(libs.moshi)
104+
ksp(libs.moshi.codegen)
114105
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.pluto.plugins.datastore.pref
2+
3+
import androidx.fragment.app.Fragment
4+
5+
internal class BaseFragment : Fragment(R.layout.pluto_dts___fragment_base)

pluto-plugins/plugins/datastore/lib/src/main/java/com/pluto/plugins/datastore/pref/PlutoDatastorePreferencesPlugin.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import androidx.fragment.app.Fragment
44
import com.pluto.plugin.DeveloperDetails
55
import com.pluto.plugin.Plugin
66
import com.pluto.plugin.PluginConfiguration
7-
import com.pluto.plugins.datastore.pref.internal.BaseFragment
87

98
class PlutoDatastorePreferencesPlugin() : Plugin(ID) {
109

pluto-plugins/plugins/datastore/lib/src/main/java/com/pluto/plugins/datastore/pref/PlutoDatastoreWatcher.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.pluto.plugins.datastore.pref
22

3+
import androidx.annotation.Keep
34
import androidx.datastore.core.DataStore
45
import androidx.datastore.preferences.core.Preferences
6+
import com.pluto.utilities.selector.SelectorOption
57
import kotlinx.coroutines.flow.MutableStateFlow
68
import kotlinx.coroutines.flow.update
79

@@ -27,6 +29,13 @@ object PlutoDatastoreWatcher {
2729
}
2830
}
2931
}
32+
33+
internal fun getSource(name: String): PreferenceHolder {
34+
return sources.value.toList().first { it.name == name }
35+
}
3036
}
3137

32-
internal data class PreferenceHolder(val name: String, val preferences: DataStore<Preferences>)
38+
@Keep
39+
internal data class PreferenceHolder(val name: String, val preferences: DataStore<Preferences>) : SelectorOption() {
40+
override fun displayText(): CharSequence = name
41+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.pluto.plugins.datastore.pref
2+
3+
internal object Session {
4+
var searchText: String? = null
5+
}

pluto-plugins/plugins/datastore/lib/src/main/java/com/pluto/plugins/datastore/pref/internal/BaseFragment.kt

Lines changed: 0 additions & 78 deletions
This file was deleted.

pluto-plugins/plugins/datastore/lib/src/main/java/com/pluto/plugins/datastore/pref/internal/BaseViewModel.kt

Lines changed: 0 additions & 98 deletions
This file was deleted.

pluto-plugins/plugins/datastore/lib/src/main/java/com/pluto/plugins/datastore/pref/internal/DataModels.kt

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.pluto.plugins.datastore.pref.internal
2+
3+
import android.content.Context
4+
import com.pluto.plugins.datastore.pref.PlutoDatastoreWatcher
5+
import com.pluto.plugins.datastore.pref.PreferenceHolder
6+
import com.pluto.utilities.list.ListItem
7+
import com.pluto.utilities.views.keyvalue.KeyValuePairEditMetaData
8+
import com.squareup.moshi.JsonAdapter
9+
import com.squareup.moshi.Moshi
10+
import com.squareup.moshi.Types
11+
12+
@SuppressWarnings("UseDataClass")
13+
internal class DatastorePrefUtils(context: Context) {
14+
15+
private val preferences: Preferences = Preferences(context)
16+
private val moshi: Moshi = Moshi.Builder().build()
17+
private val moshiAdapter: JsonAdapter<List<String>?> = moshi.adapter(Types.newParameterizedType(List::class.java, String::class.java))
18+
19+
internal var selectedPreferenceFiles: List<PreferenceHolder> = arrayListOf()
20+
get() {
21+
return preferences.selectedPreferenceFiles?.let {
22+
moshiAdapter.fromJson(it)?.map { label -> PlutoDatastoreWatcher.getSource(label) }
23+
} ?: run {
24+
selectedPreferenceFiles = PlutoDatastoreWatcher.sources.value.toList()
25+
selectedPreferenceFiles
26+
}
27+
}
28+
set(value) {
29+
preferences.selectedPreferenceFiles = moshiAdapter.toJson(value.map { it.name })
30+
field = value
31+
}
32+
}
33+
34+
internal data class DatastorePrefKeyValuePair(
35+
val key: String,
36+
val value: Any?,
37+
val prefLabel: String?
38+
) : ListItem(), KeyValuePairEditMetaData

0 commit comments

Comments
 (0)