~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.
218eaa0a
—
Peter John 1 year ago
add share verses
app/src/main/java/dev/pyrossh/onlyBible/ChapterScreen.kt
CHANGED
|
@@ -14,6 +14,7 @@ import androidx.compose.foundation.rememberScrollState
|
|
|
14
14
|
import androidx.compose.foundation.verticalScroll
|
|
15
15
|
import androidx.compose.material.icons.Icons
|
|
16
16
|
import androidx.compose.material.icons.outlined.MoreVert
|
|
17
|
+
import androidx.compose.material.icons.outlined.Share
|
|
17
18
|
import androidx.compose.material3.Icon
|
|
18
19
|
import androidx.compose.material3.IconButton
|
|
19
20
|
import androidx.compose.material3.MaterialTheme
|
|
@@ -35,6 +36,7 @@ import androidx.compose.ui.graphics.Color
|
|
|
35
36
|
import androidx.compose.ui.input.pointer.pointerInput
|
|
36
37
|
import androidx.compose.ui.layout.boundsInWindow
|
|
37
38
|
import androidx.compose.ui.layout.onGloballyPositioned
|
|
39
|
+
import androidx.compose.ui.platform.LocalContext
|
|
38
40
|
import androidx.compose.ui.text.SpanStyle
|
|
39
41
|
import androidx.compose.ui.text.TextStyle
|
|
40
42
|
import androidx.compose.ui.text.buildAnnotatedString
|
|
@@ -43,11 +45,10 @@ import androidx.compose.ui.text.withStyle
|
|
|
43
45
|
import androidx.compose.ui.unit.dp
|
|
44
46
|
import androidx.compose.ui.unit.sp
|
|
45
47
|
import androidx.navigation.NavController
|
|
46
|
-
import convertVersesToSpeech
|
|
47
48
|
import fontFamily
|
|
48
49
|
import kotlinx.coroutines.Job
|
|
49
|
-
import kotlinx.coroutines.launch
|
|
50
50
|
import kotlinx.serialization.Serializable
|
|
51
|
+
import shareVerses
|
|
51
52
|
|
|
52
53
|
// TODO: once androidx.navigation 2.8.0 is released
|
|
53
54
|
@Serializable
|
|
@@ -65,6 +66,7 @@ fun ChapterScreen(
|
|
|
65
66
|
navController: NavController,
|
|
66
67
|
openDrawer: (MenuType, Int) -> Job,
|
|
67
68
|
) {
|
|
69
|
+
val context = LocalContext.current;
|
|
68
70
|
val scope = rememberCoroutineScope()
|
|
69
71
|
var selectedVerseBounds: Rect by remember { mutableStateOf(Rect.Zero) }
|
|
70
72
|
var selectedVerses by rememberSaveable {
|
|
@@ -186,10 +188,18 @@ fun ChapterScreen(
|
|
|
186
188
|
modifier = Modifier.fillMaxWidth(),
|
|
187
189
|
horizontalArrangement = Arrangement.End,
|
|
188
190
|
) {
|
|
191
|
+
if (selectedVerses.isNotEmpty()) {
|
|
189
|
-
|
|
192
|
+
IconButton(onClick = {
|
|
190
|
-
scope.launch {
|
|
191
|
-
|
|
193
|
+
shareVerses(context, selectedVerses)
|
|
194
|
+
selectedVerses = listOf()
|
|
195
|
+
}) {
|
|
196
|
+
Icon(Icons.Outlined.Share, "Share")
|
|
192
197
|
}
|
|
198
|
+
}
|
|
199
|
+
IconButton(onClick = {
|
|
200
|
+
// scope.launch {
|
|
201
|
+
// convertVersesToSpeech(scope, selectedVerses.sortedBy { it.verseIndex })
|
|
202
|
+
// }
|
|
193
203
|
}) {
|
|
194
204
|
Icon(Icons.Outlined.MoreVert, "Close")
|
|
195
205
|
}
|
app/src/main/java/dev/pyrossh/onlyBible/Utils.kt
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import android.content.Context
|
|
2
|
+
import android.content.Intent
|
|
2
3
|
import com.microsoft.cognitiveservices.speech.SpeechConfig
|
|
3
4
|
import com.microsoft.cognitiveservices.speech.SpeechSynthesizer
|
|
4
5
|
import dev.pyrossh.onlyBible.BuildConfig
|
|
@@ -40,4 +41,20 @@ suspend fun convertVersesToSpeech(scope: CoroutineScope, verses: List<Verse>) {
|
|
|
40
41
|
""".trimIndent()
|
|
41
42
|
).wait()
|
|
42
43
|
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
fun shareVerses(context: Context, verses: List<Verse>) {
|
|
47
|
+
val items = verses.sortedBy { it.verseIndex }
|
|
48
|
+
val versesThrough =
|
|
49
|
+
if (items.size >= 3) "${items.first().verseIndex + 1}-${items.last().verseIndex + 1}" else items.map { it.verseIndex + 1 }
|
|
50
|
+
.joinToString(",");
|
|
51
|
+
val title = "${verses[0].bookName} ${verses[0].chapterIndex + 1}:${versesThrough}"
|
|
52
|
+
val text = verses.joinToString("\n") { it.text };
|
|
53
|
+
val sendIntent = Intent().apply {
|
|
54
|
+
action = Intent.ACTION_SEND
|
|
55
|
+
putExtra(Intent.EXTRA_TEXT, "${title}\n${text}")
|
|
56
|
+
type = "text/plain"
|
|
57
|
+
}
|
|
58
|
+
val shareIntent = Intent.createChooser(sendIntent, null)
|
|
59
|
+
context.startActivity(shareIntent)
|
|
43
60
|
}
|