~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.
4a154f5b
—
pyrossh 1 year ago
improve code
app/src/main/java/dev/pyrossh/onlyBible/AppViewModel.kt
CHANGED
|
@@ -22,7 +22,6 @@ import dev.pyrossh.onlyBible.domain.Bible
|
|
|
22
22
|
import dev.pyrossh.onlyBible.domain.Verse
|
|
23
23
|
import dev.pyrossh.onlyBible.domain.bibles
|
|
24
24
|
import dev.pyrossh.onlyBible.domain.chapterSizes
|
|
25
|
-
import dev.pyrossh.onlyBible.domain.engTitles
|
|
26
25
|
import kotlinx.coroutines.Dispatchers
|
|
27
26
|
import kotlinx.coroutines.FlowPreview
|
|
28
27
|
import kotlinx.coroutines.flow.MutableStateFlow
|
|
@@ -44,11 +43,11 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {
|
|
|
44
43
|
"centralindia"
|
|
45
44
|
)
|
|
46
45
|
)
|
|
47
|
-
val started = { _: Any, _: SpeechSynthesisEventArgs ->
|
|
46
|
+
private val started = { _: Any, _: SpeechSynthesisEventArgs ->
|
|
48
|
-
|
|
47
|
+
isAudioPlaying = true
|
|
49
48
|
}
|
|
50
|
-
val completed = { _: Any, _: SpeechSynthesisEventArgs ->
|
|
49
|
+
private val completed = { _: Any, _: SpeechSynthesisEventArgs ->
|
|
51
|
-
|
|
50
|
+
isAudioPlaying = false
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
init {
|
|
@@ -63,9 +62,9 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {
|
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
var isLoading by mutableStateOf(true)
|
|
66
|
-
var
|
|
65
|
+
var isAudioPlaying by mutableStateOf(false)
|
|
67
66
|
val verses = MutableStateFlow(listOf<Verse>())
|
|
68
|
-
val bookNames = MutableStateFlow(
|
|
67
|
+
val bookNames = MutableStateFlow(listOf<String>())
|
|
69
68
|
var showBottomSheet by mutableStateOf(false)
|
|
70
69
|
private val highlightedVerses = MutableStateFlow(JSONObject())
|
|
71
70
|
|
|
@@ -185,6 +184,7 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {
|
|
|
185
184
|
val heading = arr[4]
|
|
186
185
|
val verseText = arr.subList(5, arr.size).joinToString("|")
|
|
187
186
|
Verse(
|
|
187
|
+
id = "${book}:${chapter}:${verseNo}",
|
|
188
188
|
bookIndex = book,
|
|
189
189
|
bookName = bookName,
|
|
190
190
|
chapterIndex = chapter,
|
|
@@ -229,15 +229,15 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {
|
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
fun getHighlightForVerse(v: Verse): Int? {
|
|
232
|
-
if (highlightedVerses.value.has(v.
|
|
232
|
+
if (highlightedVerses.value.has(v.id))
|
|
233
|
-
return highlightedVerses.value.getInt(v.
|
|
233
|
+
return highlightedVerses.value.getInt(v.id)
|
|
234
234
|
return null
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
fun addHighlightedVerses(verses: List<Verse>, colorIndex: Int) {
|
|
238
238
|
verses.forEach { v ->
|
|
239
239
|
highlightedVerses.value.put(
|
|
240
|
-
v.
|
|
240
|
+
v.id,
|
|
241
241
|
colorIndex
|
|
242
242
|
)
|
|
243
243
|
}
|
|
@@ -245,18 +245,20 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {
|
|
|
245
245
|
|
|
246
246
|
fun removeHighlightedVerses(verses: List<Verse>) {
|
|
247
247
|
verses.forEach { v ->
|
|
248
|
-
highlightedVerses.value.remove(v.
|
|
248
|
+
highlightedVerses.value.remove(v.id)
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
fun playAudio(text: String) {
|
|
253
|
-
speechService.StartSpeakingSsml(
|
|
253
|
+
speechService.StartSpeakingSsml(
|
|
254
|
+
"""
|
|
254
255
|
<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="en-US">
|
|
255
256
|
<voice name="${bible.voiceName}">
|
|
256
257
|
$text
|
|
257
258
|
</voice>
|
|
258
259
|
</speak>
|
|
259
|
-
"""
|
|
260
|
+
"""
|
|
261
|
+
)
|
|
260
262
|
}
|
|
261
263
|
}
|
|
262
264
|
|
app/src/main/java/dev/pyrossh/onlyBible/composables/VerseText.kt
CHANGED
|
@@ -218,7 +218,7 @@ private fun Menu(
|
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
IconButton(onClick = {
|
|
221
|
-
if (model.
|
|
221
|
+
if (model.isAudioPlaying) {
|
|
222
222
|
model.speechService.StopSpeakingAsync()
|
|
223
223
|
} else {
|
|
224
224
|
scope.launch(Dispatchers.IO) {
|
|
@@ -230,7 +230,7 @@ private fun Menu(
|
|
|
230
230
|
}) {
|
|
231
231
|
Icon(
|
|
232
232
|
// modifier = Modifier.size(36.dp),
|
|
233
|
-
imageVector = if (model.
|
|
233
|
+
imageVector = if (model.isAudioPlaying)
|
|
234
234
|
Icons.Outlined.PauseCircle
|
|
235
235
|
else
|
|
236
236
|
Icons.Outlined.PlayCircle,
|
app/src/main/java/dev/pyrossh/onlyBible/domain/Verse.kt
CHANGED
|
@@ -172,13 +172,11 @@ val chapterSizes = listOf(
|
|
|
172
172
|
@Serializable
|
|
173
173
|
@Parcelize
|
|
174
174
|
data class Verse(
|
|
175
|
+
val id: String,
|
|
175
176
|
val bookIndex: Int,
|
|
176
177
|
val bookName: String,
|
|
177
178
|
val chapterIndex: Int,
|
|
178
179
|
val verseIndex: Int,
|
|
179
180
|
val heading: String,
|
|
180
181
|
val text: String,
|
|
181
|
-
) : Parcelable
|
|
182
|
+
) : Parcelable
|
|
182
|
-
|
|
183
|
-
fun key() = "${bookIndex}:${chapterIndex}:${verseIndex}"
|
|
184
|
-
}
|