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


7a6c5c7c pyrossh

1 year ago
fix share and theme
composeApp/src/androidMain/kotlin/dev/pyrossh/only_bible_app/Platform.android.kt CHANGED
@@ -1,8 +1,17 @@
1
1
  package dev.pyrossh.only_bible_app
2
2
 
3
+ import android.content.Intent
3
4
  import android.view.SoundEffectConstants
5
+ import androidx.activity.ComponentActivity
6
+ import androidx.activity.SystemBarStyle
7
+ import androidx.activity.enableEdgeToEdge
8
+ import androidx.compose.foundation.isSystemInDarkTheme
9
+ import androidx.compose.material3.ColorScheme
4
10
  import androidx.compose.runtime.Composable
11
+ import androidx.compose.runtime.LaunchedEffect
12
+ import androidx.compose.ui.graphics.toArgb
5
13
  import androidx.compose.ui.platform.LocalConfiguration
14
+ import androidx.compose.ui.platform.LocalContext
6
15
  import androidx.compose.ui.platform.LocalView
7
16
  import androidx.compose.ui.unit.Dp
8
17
  import androidx.compose.ui.unit.dp
@@ -11,6 +20,8 @@ import com.microsoft.cognitiveservices.speech.SpeechConfig
11
20
  import com.microsoft.cognitiveservices.speech.SpeechSynthesisEventArgs
12
21
  import com.microsoft.cognitiveservices.speech.SpeechSynthesizer
13
22
  import dev.pyrossh.only_bible_app.config.BuildKonfig
23
+ import theme.darkScheme
24
+ import theme.lightScheme
14
25
 
15
26
  @Composable
16
27
  actual fun getScreenWidth(): Dp = LocalConfiguration.current.screenWidthDp.dp
@@ -21,7 +32,59 @@ actual fun getScreenHeight(): Dp = LocalConfiguration.current.screenHeightDp.dp
21
32
  @Composable
22
33
  actual fun playClickSound() = LocalView.current.playSoundEffect(SoundEffectConstants.CLICK)
23
34
 
35
+ @Composable
24
- actual fun shareVerses(verses: List<Verse>) {
36
+ actual fun rememberShareVerses(): (verses: List<Verse>) -> Unit {
37
+ val context = LocalContext.current
38
+ return { verses ->
39
+ val versesThrough =
40
+ if (verses.size >= 3) "${verses.first().verseIndex + 1}-${verses.last().verseIndex + 1}" else verses.map { it.verseIndex + 1 }
41
+ .joinToString(",")
42
+ val title = "${verses[0].bookName} ${verses[0].chapterIndex + 1}:${versesThrough}"
43
+ val text = verses.joinToString("\n") {
44
+ it.text.replace("<span style=\"color:red;\">", "")
45
+ .replace("<em>", "")
46
+ .replace("</span>", "")
47
+ .replace("</em>", "")
48
+ }
49
+ val sendIntent = Intent().apply {
50
+ action = Intent.ACTION_SEND
51
+ putExtra(Intent.EXTRA_TEXT, "${title}\n${text}")
52
+ type = "text/plain"
53
+ }
54
+ val shareIntent = Intent.createChooser(sendIntent, null)
55
+ context.startActivity(shareIntent)
56
+ }
57
+ }
58
+
59
+ @Composable
60
+ actual fun onThemeChange(themeType: ThemeType) {
61
+ val isLight = isLightTheme(themeType, isSystemInDarkTheme())
62
+ val colorScheme = if (isLight) lightScheme else darkScheme
63
+ val context = LocalContext.current as ComponentActivity
64
+ LaunchedEffect(key1 = themeType) {
65
+ context.enableEdgeToEdge(
66
+ statusBarStyle = if (isLight) {
67
+ SystemBarStyle.light(
68
+ colorScheme.background.toArgb(),
69
+ colorScheme.onBackground.toArgb()
70
+ )
71
+ } else {
72
+ SystemBarStyle.dark(
73
+ colorScheme.background.toArgb(),
74
+ )
75
+ },
76
+ navigationBarStyle = if (isLight) {
77
+ SystemBarStyle.light(
78
+ colorScheme.background.toArgb(),
79
+ colorScheme.onBackground.toArgb()
80
+ )
81
+ } else {
82
+ SystemBarStyle.dark(
83
+ colorScheme.background.toArgb(),
84
+ )
85
+ }
86
+ )
87
+ }
25
88
  }
26
89
 
27
90
  actual object SpeechService {
composeApp/src/commonMain/kotlin/dev/pyrossh/only_bible_app/AppTheme.kt CHANGED
@@ -50,33 +50,9 @@ fun AppTheme(
50
50
  themeType: ThemeType,
51
51
  content: @Composable () -> Unit
52
52
  ) {
53
- // val context = LocalContext.current as ComponentActivity
54
53
  val isLight = isLightTheme(themeType, isSystemInDarkTheme())
55
54
  val colorScheme = if (isLight) lightScheme else darkScheme
56
- LaunchedEffect(key1 = themeType) {
55
+ onThemeChange(themeType)
57
- // context.enableEdgeToEdge(
58
- // statusBarStyle = if (isLight) {
59
- // SystemBarStyle.light(
60
- // colorScheme.background.toArgb(),
61
- // colorScheme.onBackground.toArgb()
62
- // )
63
- // } else {
64
- // SystemBarStyle.dark(
65
- // colorScheme.background.toArgb(),
66
- // )
67
- // },
68
- // navigationBarStyle = if (isLight) {
69
- // SystemBarStyle.light(
70
- // colorScheme.background.toArgb(),
71
- // colorScheme.onBackground.toArgb()
72
- // )
73
- // } else {
74
- // SystemBarStyle.dark(
75
- // colorScheme.background.toArgb(),
76
- // )
77
- // }
78
- // )
79
- }
80
56
  MaterialTheme(
81
57
  colorScheme = colorScheme,
82
58
  content = content
composeApp/src/commonMain/kotlin/dev/pyrossh/only_bible_app/Platform.kt CHANGED
@@ -1,5 +1,6 @@
1
1
  package dev.pyrossh.only_bible_app
2
2
 
3
+ import androidx.compose.material3.ColorScheme
3
4
  import androidx.compose.runtime.Composable
4
5
  import androidx.compose.ui.unit.Dp
5
6
  import dev.pyrossh.only_bible_app.domain.Verse
@@ -14,7 +15,11 @@ expect fun getScreenHeight(): Dp
14
15
  @Composable
15
16
  expect fun playClickSound()
16
17
 
18
+ @Composable
17
- expect fun shareVerses(verses: List<Verse>)
19
+ expect fun rememberShareVerses(): (verses: List<Verse>) -> Unit
20
+
21
+ @Composable
22
+ expect fun onThemeChange(themeType: ThemeType)
18
23
 
19
24
  expect object SpeechService {
20
25
  fun init(onStarted: () -> Unit, onEnded: () -> Unit)
composeApp/src/commonMain/kotlin/dev/pyrossh/only_bible_app/composables/VerseText.kt CHANGED
@@ -57,7 +57,7 @@ import kotlinx.coroutines.Dispatchers
57
57
  import kotlinx.coroutines.IO
58
58
  import kotlinx.coroutines.launch
59
59
  import dev.pyrossh.only_bible_app.lightHighlights
60
- import dev.pyrossh.only_bible_app.shareVerses
60
+ import dev.pyrossh.only_bible_app.rememberShareVerses
61
61
  import utils.LocalNavController
62
62
 
63
63
  @Composable
@@ -179,6 +179,7 @@ private fun Menu(
179
179
  val navController = LocalNavController.current
180
180
  val scope = rememberCoroutineScope()
181
181
  val selectedVerses by model.selectedVerses.collectAsState()
182
+ val shareVerses = rememberShareVerses()
182
183
  Popup(
183
184
  alignment = Alignment.TopCenter,
184
185
  offset = IntOffset(0, y = barYPosition),
@@ -263,7 +264,9 @@ private fun Menu(
263
264
  IconButton(onClick = {
264
265
  // view.playSoundEffect(SoundEffectConstants.CLICK)
265
266
  shareVerses(
266
- selectedVerses.sortedBy { it.verseIndex })
267
+ selectedVerses.sortedBy { it.verseIndex },
268
+ )
269
+ model.setSelectedVerses(listOf())
267
270
  }) {
268
271
  Icon(
269
272
  // modifier = Modifier.size(32.dp),
iosApp/Configuration/Config.xcconfig CHANGED
@@ -1,3 +1,3 @@
1
1
  TEAM_ID=
2
- BUNDLE_ID=example.one.Example1
2
+ BUNDLE_ID=dev.pyrossh.only_bible_app
3
- APP_NAME=Example1
3
+ APP_NAME=Only Bible App