~repos /only-bible-app
git clone https://pyrossh.dev/repos/only-bible-app.git
The only bible app you will ever need. No ads. No in-app purchases. No distractions.
d3ff524e
—
pyrossh 1 year ago
fix settings
app/build.gradle.kts
CHANGED
|
@@ -49,6 +49,7 @@ kotlin {
|
|
|
49
49
|
implementation(compose.materialIconsExtended)
|
|
50
50
|
implementation(compose.ui)
|
|
51
51
|
implementation(compose.components.resources)
|
|
52
|
+
implementation(libs.multiplatform.settings)
|
|
52
53
|
implementation(libs.androidx.activity.compose)
|
|
53
54
|
implementation(libs.androidx.navigation.compose)
|
|
54
55
|
implementation(libs.androidx.lifecycle.viewmodel.compose)
|
app/src/androidMain/kotlin/Platform.android.kt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
import android.os.Build
|
|
2
3
|
|
|
3
4
|
class AndroidPlatform : Platform {
|
app/src/main/java/dev/pyrossh/onlyBible/AppViewModel.kt
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
package dev.pyrossh.onlyBible
|
|
2
2
|
|
|
3
|
-
import android.content.SharedPreferences
|
|
4
3
|
import androidx.compose.runtime.getValue
|
|
5
4
|
import androidx.compose.runtime.mutableIntStateOf
|
|
6
5
|
import androidx.compose.runtime.mutableStateOf
|
|
@@ -10,6 +9,7 @@ import androidx.lifecycle.viewModelScope
|
|
|
10
9
|
import com.microsoft.cognitiveservices.speech.SpeechConfig
|
|
11
10
|
import com.microsoft.cognitiveservices.speech.SpeechSynthesisEventArgs
|
|
12
11
|
import com.microsoft.cognitiveservices.speech.SpeechSynthesizer
|
|
12
|
+
import com.russhwolf.settings.Settings
|
|
13
13
|
import dev.pyrossh.onlyBible.domain.Bible
|
|
14
14
|
import dev.pyrossh.onlyBible.domain.Verse
|
|
15
15
|
import dev.pyrossh.onlyBible.domain.bibles
|
|
@@ -99,25 +99,26 @@ class AppViewModel : ViewModel() {
|
|
|
99
99
|
selectedVerses.value = listOf()
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
fun loadData(
|
|
102
|
+
fun loadData(s: Settings) {
|
|
103
103
|
viewModelScope.launch(Dispatchers.IO) {
|
|
104
104
|
viewModelScope.launch(Dispatchers.Main) {
|
|
105
105
|
isLoading = true
|
|
106
106
|
}
|
|
107
|
-
val bibleFileName =
|
|
107
|
+
val bibleFileName = s.getString("bible", "en_kjv") ?: "en_kjv"
|
|
108
|
-
bookIndex =
|
|
108
|
+
bookIndex = s.getInt("bookIndex", 0)
|
|
109
|
-
chapterIndex =
|
|
109
|
+
chapterIndex = s.getInt("chapterIndex", 0)
|
|
110
|
-
verseIndex =
|
|
110
|
+
verseIndex = s.getInt("verseIndex", 0)
|
|
111
111
|
fontType = FontType.valueOf(
|
|
112
|
-
|
|
112
|
+
s.getString("fontType", FontType.Sans.name) ?: FontType.Sans.name
|
|
113
113
|
)
|
|
114
|
-
fontSizeDelta =
|
|
114
|
+
fontSizeDelta = s.getInt("fontSizeDelta", 0)
|
|
115
|
-
fontBoldEnabled =
|
|
115
|
+
fontBoldEnabled = s.getBoolean("fontBoldEnabled", false)
|
|
116
|
-
lineSpacingDelta =
|
|
116
|
+
lineSpacingDelta = s.getInt("lineSpacingDelta", 0)
|
|
117
117
|
themeType = ThemeType.valueOf(
|
|
118
|
-
|
|
118
|
+
s.getString("themeType", ThemeType.Auto.name) ?: ThemeType.Auto.name
|
|
119
119
|
)
|
|
120
|
+
highlightedVerses.value =
|
|
120
|
-
|
|
121
|
+
JSONObject(s.getString("highlightedVerses", "{}") ?: "{}")
|
|
121
122
|
val localBible = bibles.find { it.filename() == bibleFileName } ?: bibles.first()
|
|
122
123
|
loadBible(localBible)
|
|
123
124
|
viewModelScope.launch(Dispatchers.Main) {
|
|
@@ -159,22 +160,18 @@ class AppViewModel : ViewModel() {
|
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
162
|
|
|
162
|
-
fun saveData(
|
|
163
|
+
fun saveData(s: Settings) {
|
|
163
164
|
viewModelScope.launch(Dispatchers.IO) {
|
|
164
|
-
with(prefs.edit()) {
|
|
165
|
-
|
|
165
|
+
s.putString("bible", bible.filename())
|
|
166
|
-
|
|
166
|
+
s.putInt("bookIndex", bookIndex)
|
|
167
|
-
|
|
167
|
+
s.putInt("chapterIndex", chapterIndex)
|
|
168
|
-
|
|
168
|
+
s.putInt("verseIndex", verseIndex)
|
|
169
|
-
|
|
169
|
+
s.putString("fontType", fontType.name)
|
|
170
|
-
|
|
170
|
+
s.putInt("fontSizeDelta", fontSizeDelta)
|
|
171
|
-
|
|
171
|
+
s.putBoolean("fontBoldEnabled", fontBoldEnabled)
|
|
172
|
-
|
|
172
|
+
s.putInt("lineSpacingDelta", lineSpacingDelta)
|
|
173
|
-
|
|
173
|
+
s.putString("themeType", themeType.name)
|
|
174
|
-
|
|
174
|
+
s.putString("highlightedVerses", highlightedVerses.value.toString())
|
|
175
|
-
apply()
|
|
176
|
-
commit()
|
|
177
|
-
}
|
|
178
175
|
}
|
|
179
176
|
}
|
|
180
177
|
|
app/src/main/java/dev/pyrossh/onlyBible/MainActivity.kt
CHANGED
|
@@ -6,19 +6,23 @@ import androidx.activity.compose.setContent
|
|
|
6
6
|
import androidx.activity.enableEdgeToEdge
|
|
7
7
|
import androidx.activity.viewModels
|
|
8
8
|
import androidx.lifecycle.lifecycleScope
|
|
9
|
+
import com.russhwolf.settings.SharedPreferencesSettings
|
|
9
10
|
import kotlinx.coroutines.launch
|
|
10
11
|
|
|
11
12
|
class MainActivity : ComponentActivity() {
|
|
12
13
|
|
|
13
14
|
private val model by viewModels<AppViewModel>()
|
|
15
|
+
private val settings by lazy {
|
|
16
|
+
val prefs = applicationContext.getSharedPreferences("data", MODE_PRIVATE)
|
|
17
|
+
SharedPreferencesSettings(prefs)
|
|
18
|
+
}
|
|
14
19
|
|
|
15
20
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
16
21
|
super.onCreate(savedInstanceState)
|
|
17
22
|
enableEdgeToEdge()
|
|
18
23
|
if (savedInstanceState == null) {
|
|
19
24
|
lifecycleScope.launch {
|
|
20
|
-
val prefs = applicationContext.getSharedPreferences("data", MODE_PRIVATE)
|
|
21
|
-
model.loadData(
|
|
25
|
+
model.loadData(settings)
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
28
|
setContent {
|
|
@@ -31,8 +35,7 @@ class MainActivity : ComponentActivity() {
|
|
|
31
35
|
override fun onSaveInstanceState(outState: Bundle) {
|
|
32
36
|
super.onSaveInstanceState(outState)
|
|
33
37
|
lifecycleScope.launch {
|
|
34
|
-
val prefs = applicationContext.getSharedPreferences("data", MODE_PRIVATE)
|
|
35
|
-
model.saveData(
|
|
38
|
+
model.saveData(settings)
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
}
|
gradle/libs.versions.toml
CHANGED
|
@@ -10,6 +10,7 @@ activityCompose = "1.9.1"
|
|
|
10
10
|
navigationCompose = "2.8.0-alpha08"
|
|
11
11
|
lifecycleRuntimeKtx = "2.8.4"
|
|
12
12
|
lifecycleViewmodelCompose = "2.8.4" # 2.8.0
|
|
13
|
+
multiplatformSettings = "1.1.1"
|
|
13
14
|
composePlugin = "1.6.11"
|
|
14
15
|
secretsGradlePlugin = "2.0.1"
|
|
15
16
|
|
|
@@ -17,6 +18,7 @@ secretsGradlePlugin = "2.0.1"
|
|
|
17
18
|
#androidx-lifecycle-viewmodel-compose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "viewmodel" }
|
|
18
19
|
androidx-navigation-compose = { module = "org.jetbrains.androidx.navigation:navigation-compose", version.ref = "navigationCompose" }
|
|
19
20
|
androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycleViewmodelCompose" }
|
|
21
|
+
multiplatform-settings = { module = "com.russhwolf:multiplatform-settings", version.ref = "multiplatformSettings" }
|
|
20
22
|
speech-client-sdk = { module = "com.microsoft.cognitiveservices.speech:client-sdk", version.ref = "speechClientSdk" }
|
|
21
23
|
junit = { group = "junit", name = "junit", version.ref = "junit" }
|
|
22
24
|
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
|