~repos /only-bible-app

#kotlin#android#ios

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.


25068e9d pyrossh

1 year ago
fix highlighting
.gitignore CHANGED
@@ -22,7 +22,6 @@ node_modules
22
22
  bsb_usfm
23
23
  xcuserdata
24
24
  !src/**/build/
25
- .idea
26
25
  captures
27
26
  *.xcodeproj/*
28
27
  !*.xcodeproj/project.pbxproj
@@ -30,3 +29,4 @@ captures
30
29
  !*.xcodeproj/project.xcworkspace/
31
30
  !*.xcworkspace/contents.xcworkspacedata
32
31
  **/xcshareddata/WorkspaceSettings.xcsettings
32
+ composeApp/Build
composeApp/src/commonMain/kotlin/dev/pyrossh/only_bible_app/AppViewModel.kt CHANGED
@@ -1,4 +1,5 @@
1
1
  package dev.pyrossh.only_bible_app
2
+
2
3
  import androidx.compose.runtime.getValue
3
4
  import androidx.compose.runtime.mutableIntStateOf
4
5
  import androidx.compose.runtime.mutableStateOf
@@ -21,7 +22,9 @@ import kotlinx.coroutines.flow.debounce
21
22
  import kotlinx.coroutines.flow.stateIn
22
23
  import kotlinx.coroutines.launch
23
24
  import kotlinx.serialization.json.Json
25
+ import kotlinx.serialization.json.JsonElement
24
26
  import kotlinx.serialization.json.JsonObject
27
+ import kotlinx.serialization.json.JsonPrimitive
25
28
  import kotlinx.serialization.json.int
26
29
  import kotlinx.serialization.json.jsonObject
27
30
  import kotlinx.serialization.json.jsonPrimitive
@@ -176,14 +179,15 @@ class AppViewModel : ViewModel() {
176
179
  }
177
180
 
178
181
  fun addHighlightedVerses(verses: List<Verse>, colorIndex: Int) {
179
- verses.forEach { v ->
180
- highlightedVerses.value + (v.id to colorIndex)
182
+ highlightedVerses.value = JsonObject(
183
+ highlightedVerses.value + verses.associateBy({ it.id },
184
+ { JsonPrimitive(colorIndex) })
181
- }
185
+ )
182
186
  }
183
187
 
184
188
  fun removeHighlightedVerses(verses: List<Verse>) {
185
- verses.forEach { v ->
186
- highlightedVerses.value - v.id
189
+ highlightedVerses.value = JsonObject(
190
+ highlightedVerses.value.filterKeys { !verses.map { v -> v.id }.contains(it) }
187
- }
191
+ )
188
192
  }
189
193
  }
composeApp/src/commonMain/kotlin/dev/pyrossh/only_bible_app/composables/VerseText.kt CHANGED
@@ -141,7 +141,7 @@ fun VerseText(
141
141
  ) {
142
142
  append("${verse.verseIndex + 1} ")
143
143
  }
144
- append(verse.text)
144
+ append(text)
145
145
  // append(
146
146
  // AnnotatedString.Companion.fromHtml(
147
147
  // htmlString = text,
composeApp/src/commonMain/kotlin/dev/pyrossh/only_bible_app/screens/ChapterScreen.kt CHANGED
@@ -48,7 +48,7 @@ import kotlinx.coroutines.IO
48
48
  import kotlinx.coroutines.launch
49
49
  import kotlinx.serialization.Serializable
50
50
  import utils.LocalNavController
51
- import utils.detectSwipe
51
+ import dev.pyrossh.only_bible_app.utils.detectSwipe
52
52
  import utils.getBackwardPair
53
53
  import utils.getForwardPair
54
54
 
composeApp/src/commonMain/kotlin/dev/pyrossh/only_bible_app/utils/SimpleParser.kt ADDED
@@ -0,0 +1,38 @@
1
+ package dev.pyrossh.only_bible_app.utils
2
+
3
+ class SimpleParser(val input: CharSequence) {
4
+ var cursor: Int = 0
5
+
6
+ private fun step(): Char {
7
+ return input[cursor++]
8
+ }
9
+
10
+ private fun peek(): Char {
11
+ return input[cursor]
12
+ }
13
+
14
+ private fun skip() {
15
+ cursor++
16
+ }
17
+
18
+ private fun hasNext(): Boolean {
19
+ return cursor < input.length
20
+ }
21
+
22
+ fun read(predicate: (Char) -> Boolean): String {
23
+ val result = StringBuilder()
24
+ while (predicate(peek())) {
25
+ result.append(step())
26
+ }
27
+ return result.toString()
28
+ }
29
+
30
+ fun read(pattern: CharSequence): String {
31
+ val result = StringBuilder()
32
+ var patternCursor = 0
33
+ while (peek() == pattern[patternCursor++]) {
34
+ result.append(skip())
35
+ }
36
+ return result.toString()
37
+ }
38
+ }
composeApp/src/commonMain/kotlin/dev/pyrossh/only_bible_app/utils/Swipe.kt CHANGED
@@ -1,4 +1,4 @@
1
- package utils
1
+ package dev.pyrossh.only_bible_app.utils
2
2
 
3
3
  import androidx.compose.foundation.gestures.detectDragGestures
4
4
  import androidx.compose.runtime.MutableIntState