~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.


54c747b5 pyrossh

1 year ago
fix navigation
app/src/main/java/dev/pyrossh/onlyBible/AppHost.kt CHANGED
@@ -5,11 +5,10 @@ import androidx.compose.animation.ExitTransition
5
5
  import androidx.compose.animation.core.tween
6
6
  import androidx.compose.runtime.Composable
7
7
  import androidx.compose.runtime.CompositionLocalProvider
8
- import androidx.navigation.NavType
9
8
  import androidx.navigation.compose.NavHost
10
9
  import androidx.navigation.compose.composable
11
10
  import androidx.navigation.compose.rememberNavController
12
- import androidx.navigation.navArgument
11
+ import androidx.navigation.toRoute
13
12
  import dev.pyrossh.onlyBible.utils.LocalNavController
14
13
 
15
14
  @Composable
@@ -21,13 +20,17 @@ fun AppHost(
21
20
  CompositionLocalProvider(LocalNavController provides navController) {
22
21
  NavHost(
23
22
  navController = navController,
24
- startDestination = "{bookId}:{chapterId}:{verseId}"
23
+ startDestination = ChapterScreenProps(
24
+ model.bookIndex,
25
+ model.chapterIndex,
26
+ model.verseIndex
27
+ )
25
28
  ) {
26
- composable(
29
+ composable<ChapterScreenProps>(
27
30
  enterTransition = {
28
- // val props = this.targetState.toRoute<ChapterScreenProps>()
31
+ val props = this.targetState.toRoute<ChapterScreenProps>()
29
32
  slideIntoContainer(
30
- Dir.valueOf(Dir.Left.name).slideDirection(),
33
+ Dir.valueOf(props.dir).slideDirection(),
31
34
  tween(400),
32
35
  )
33
36
  },
@@ -38,24 +41,19 @@ fun AppHost(
38
41
  EnterTransition.None
39
42
  },
40
43
  popExitTransition = {
41
- // val props = this.targetState.toRoute<ChapterScreenProps>()
44
+ val props = this.targetState.toRoute<ChapterScreenProps>()
42
45
  slideOutOfContainer(
43
- Dir.valueOf(Dir.Left.name).reverse().slideDirection(),
46
+ Dir.valueOf(props.dir).reverse().slideDirection(),
44
47
  tween(400),
45
48
  )
46
- },
49
+ }
47
- route = "{bookId}:{chapterId}:{verseId}",
48
- arguments = listOf(
49
- navArgument("bookId") { type = NavType.IntType },
50
- navArgument("chapterId") { type = NavType.IntType },
51
- navArgument("verseId") { type = NavType.IntType },
52
- ),
53
50
  ) {
51
+ val props = it.toRoute<ChapterScreenProps>()
54
52
  ChapterScreen(
55
53
  model = model,
56
- bookIndex = it.arguments?.getInt("bookId") ?: 0,
54
+ bookIndex = props.bookIndex,
57
- chapterIndex = it.arguments?.getInt("chapterId") ?: 0,
55
+ chapterIndex = props.chapterIndex,
58
- verseIndex = it.arguments?.getInt("verseId") ?: 0,
56
+ verseIndex = props.verseIndex,
59
57
  )
60
58
  }
61
59
  }
app/src/main/java/dev/pyrossh/onlyBible/ChapterScreen.kt CHANGED
@@ -54,6 +54,14 @@ import kotlinx.coroutines.Dispatchers
54
54
  import kotlinx.coroutines.launch
55
55
  import kotlinx.serialization.Serializable
56
56
 
57
+ @Serializable
58
+ data class ChapterScreenProps(
59
+ val bookIndex: Int,
60
+ val chapterIndex: Int,
61
+ val verseIndex: Int,
62
+ val dir: String = Dir.Left.name,
63
+ )
64
+
57
65
  enum class Dir {
58
66
  Left, Right;
59
67
 
@@ -233,12 +241,24 @@ fun ChapterScreen(
233
241
  detectSwipe(
234
242
  onSwipeLeft = {
235
243
  val pair = getForwardPair(bookIndex, chapterIndex)
236
- navController.navigate("${pair.first}:${pair.second}:0")
244
+ navController.navigate(
245
+ ChapterScreenProps(
246
+ bookIndex = pair.first,
247
+ chapterIndex = pair.second,
248
+ verseIndex = 0,
249
+ )
250
+ )
237
251
  },
238
252
  onSwipeRight = {
239
253
  val pair = getBackwardPair(bookIndex, chapterIndex)
240
- navController.navigate("${pair.first}:${pair.second}:0")
254
+ navController.navigate(
255
+ ChapterScreenProps(
256
+ bookIndex = pair.first,
257
+ chapterIndex = pair.second,
258
+ verseIndex = 0,
241
- // Dir.Right.name,
259
+ dir = Dir.Right.name,
260
+ )
261
+ )
242
262
  },
243
263
  )
244
264
  }
app/src/main/java/dev/pyrossh/onlyBible/composables/ChapterSelector.kt CHANGED
@@ -36,6 +36,7 @@ import androidx.compose.ui.platform.LocalView
36
36
  import androidx.compose.ui.text.font.FontWeight
37
37
  import androidx.compose.ui.unit.dp
38
38
  import androidx.compose.ui.window.Dialog
39
+ import dev.pyrossh.onlyBible.ChapterScreenProps
39
40
  import dev.pyrossh.onlyBible.domain.Bible
40
41
  import dev.pyrossh.onlyBible.domain.chapterSizes
41
42
  import dev.pyrossh.onlyBible.domain.engTitles
@@ -149,7 +150,13 @@ fun ChapterSelector(
149
150
  onClick = {
150
151
  view.playSoundEffect(SoundEffectConstants.CLICK)
151
152
  onClose()
152
- navController.navigate("${bookIndex}:${c}:0")
153
+ navController.navigate(
154
+ ChapterScreenProps(
155
+ bookIndex = bookIndex,
156
+ chapterIndex = c,
157
+ verseIndex = 0,
158
+ )
159
+ )
153
160
  }
154
161
  ) {
155
162
  Text(
app/src/main/java/dev/pyrossh/onlyBible/composables/VerseHeading.kt CHANGED
@@ -18,6 +18,7 @@ import androidx.compose.ui.text.font.FontWeight
18
18
  import androidx.compose.ui.text.fromHtml
19
19
  import androidx.compose.ui.unit.dp
20
20
  import androidx.compose.ui.unit.sp
21
+ import dev.pyrossh.onlyBible.ChapterScreenProps
21
22
  import dev.pyrossh.onlyBible.FontType
22
23
  import dev.pyrossh.onlyBible.utils.LocalNavController
23
24
 
@@ -50,7 +51,13 @@ fun VerseHeading(
50
51
  view.playSoundEffect(SoundEffectConstants.CLICK)
51
52
  val url = (it as LinkAnnotation.Url).url
52
53
  val parts = url.split(":")
53
- navController.navigate("${parts[0]}:${parts[1]}:${parts[2]}")
54
+ navController.navigate(
55
+ ChapterScreenProps(
56
+ bookIndex = parts[0].toInt(),
57
+ chapterIndex = parts[1].toInt(),
58
+ verseIndex = parts[2].toInt(),
59
+ )
60
+ )
54
61
  },
55
62
  ),
56
63
  )
app/src/main/java/dev/pyrossh/onlyBible/composables/VerseText.kt CHANGED
@@ -55,6 +55,7 @@ import androidx.compose.ui.unit.dp
55
55
  import androidx.compose.ui.unit.sp
56
56
  import androidx.compose.ui.window.Popup
57
57
  import dev.pyrossh.onlyBible.AppViewModel
58
+ import dev.pyrossh.onlyBible.ChapterScreenProps
58
59
  import dev.pyrossh.onlyBible.FontType
59
60
  import dev.pyrossh.onlyBible.darkHighlights
60
61
  import dev.pyrossh.onlyBible.domain.Verse
@@ -281,7 +282,13 @@ private fun Menu(
281
282
  if (highlightWord != null) {
282
283
  IconButton(onClick = {
283
284
  view.playSoundEffect(SoundEffectConstants.CLICK)
285
+ navController.navigate(
286
+ ChapterScreenProps(
287
+ bookIndex = verse.bookIndex,
284
- navController.navigate("${verse.bookIndex}:${verse.chapterIndex}:${verse.verseIndex}")
288
+ chapterIndex = verse.chapterIndex,
289
+ verseIndex = verse.verseIndex,
290
+ )
291
+ )
285
292
  }) {
286
293
  Icon(
287
294
  // modifier = Modifier.size(32.dp),
gradle/libs.versions.toml CHANGED
@@ -1,34 +1,27 @@
1
1
  [versions]
2
2
  agp = "8.3.0"
3
3
  speechClientSdk = "1.34.0"
4
- foundation = "1.6.8"
5
4
  kotlin = "2.0.0"
6
5
  kotlinxCoroutinesCore = "1.9.0-RC"
7
6
  kotlinxSerialization = "1.7.0"
8
7
  junit = "4.13.2"
9
8
  junitVersion = "1.2.1"
10
9
  activityCompose = "1.9.1"
11
- navigationCompose = "2.8.0-beta06"
10
+ navigationCompose = "2.8.0-alpha08"
12
11
  lifecycleRuntimeKtx = "2.8.4"
13
- lifecycleViewmodelCompose = "2.8.4"
12
+ lifecycleViewmodelCompose = "2.8.4" # 2.8.0
14
- material3 = "1.2.1"
15
- materialIconsExtended = "1.6.8"
16
13
  composePlugin = "1.6.11"
17
14
  secretsGradlePlugin = "2.0.1"
18
15
 
19
16
  [libraries]
20
17
  #androidx-lifecycle-viewmodel-compose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "viewmodel" }
21
- #androidx-navigation-compose = { module = "org.jetbrains.androidx.navigation:navigation-compose", version.ref = "navigationCompose" }
18
+ androidx-navigation-compose = { module = "org.jetbrains.androidx.navigation:navigation-compose", version.ref = "navigationCompose" }
22
- androidx-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "foundation" }
23
19
  androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycleViewmodelCompose" }
24
- androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigationCompose" }
25
20
  speech-client-sdk = { module = "com.microsoft.cognitiveservices.speech:client-sdk", version.ref = "speechClientSdk" }
26
21
  junit = { group = "junit", name = "junit", version.ref = "junit" }
27
22
  androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
28
23
  androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
29
24
  androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
30
- androidx-material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "materialIconsExtended" }
31
- androidx-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "material3" }
32
25
  kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinxCoroutinesCore" }
33
26
  kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerialization" }
34
27
  secrets-gradle-plugin = { module = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin", version.ref = "secretsGradlePlugin" }