~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.
file:
composeApp/src/commonMain/kotlin/dev/pyrossh/onlyBible/composables/ChapterSelector.kt
package dev.pyrossh.onlyBible.composables
import androidx.compose.foundation.clickableimport androidx.compose.foundation.layout.Arrangementimport androidx.compose.foundation.layout.Spacerimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.heightimport androidx.compose.foundation.layout.paddingimport androidx.compose.foundation.lazy.LazyColumnimport androidx.compose.foundation.lazy.grid.GridCellsimport androidx.compose.foundation.lazy.grid.LazyVerticalGridimport androidx.compose.foundation.lazy.itemsimport androidx.compose.foundation.lazy.rememberLazyListStateimport androidx.compose.foundation.shape.RoundedCornerShapeimport androidx.compose.material3.ButtonDefaultsimport androidx.compose.material3.Cardimport androidx.compose.material3.ExperimentalMaterial3Apiimport androidx.compose.material3.ExposedDropdownMenuDefaultsimport androidx.compose.material3.ListItemimport androidx.compose.material3.ListItemDefaultsimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.Surfaceimport androidx.compose.material3.Textimport androidx.compose.material3.TextButtonimport androidx.compose.runtime.Composableimport androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableIntStateOfimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.rememberimport androidx.compose.runtime.setValueimport androidx.compose.ui.Modifierimport androidx.compose.ui.text.font.FontWeightimport androidx.compose.ui.unit.dpimport androidx.compose.ui.window.Dialogimport dev.pyrossh.onlyBible.screens.ChapterScreenPropsimport dev.pyrossh.onlyBible.domain.Bibleimport dev.pyrossh.onlyBible.domain.chapterSizesimport dev.pyrossh.onlyBible.domain.engTitlesimport dev.pyrossh.onlyBible.getScreenHeightimport utils.LocalNavController
@OptIn(ExperimentalMaterial3Api::class)@Composablefun ChapterSelector( bible: Bible, bookNames: List<String>, startBookIndex: Int, onClose: () -> Unit,) { val navController = LocalNavController.current val height = getScreenHeight() / 2 var expanded by remember { mutableStateOf(false) } var bookIndex by remember { mutableIntStateOf(startBookIndex) } val scrollState = rememberLazyListState( initialFirstVisibleItemIndex = if (startBookIndex - 2 >= 0) startBookIndex - 2 else 0, ) Dialog(onDismissRequest = { onClose() }) { Card( modifier = Modifier .fillMaxWidth() .height(height), shape = RoundedCornerShape(8.dp), ) { ListItem( modifier = Modifier .clickable {// view.playSoundEffect(SoundEffectConstants.CLICK) expanded = !expanded }, colors = ListItemDefaults.colors( containerColor = if (expanded) MaterialTheme.colorScheme.surfaceContainer else MaterialTheme.colorScheme.background ), headlineContent = { Text( modifier = Modifier.padding(start = 4.dp),// .fillMaxWidth()// .wrapContentWidth(Alignment.CenterHorizontally), fontWeight = FontWeight.W600, text = bookNames[bookIndex] ) }, trailingContent = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) } ) if (expanded) { LazyColumn( state = scrollState, ) { items(bookNames.filter { it != bookNames[bookIndex] }) { ListItem( modifier = Modifier.clickable { bookIndex = bookNames.indexOf(it) expanded = false }, headlineContent = { Text( modifier = Modifier.padding(start = 4.dp), fontWeight = FontWeight.W600, text = it, ) }, supportingContent = { if (bible.languageCode != "en") { Text( modifier = Modifier.padding(start = 4.dp), text = engTitles[bookNames.indexOf(it)], ) } } ) } } } LazyVerticalGrid( modifier = Modifier .fillMaxSize() .padding(16.dp), verticalArrangement = Arrangement.spacedBy(10.dp), horizontalArrangement = Arrangement.spacedBy(10.dp), columns = GridCells.Fixed(5) ) { items(chapterSizes[bookIndex]) { c -> Surface( shadowElevation = 1.dp, shape = RoundedCornerShape(8.dp), modifier = Modifier .fillMaxWidth() ) { TextButton( colors = ButtonDefaults.textButtonColors( containerColor = MaterialTheme.colorScheme.surface, contentColor = MaterialTheme.colorScheme.onSurface, ), shape = RoundedCornerShape(8.dp), onClick = {// view.playSoundEffect(SoundEffectConstants.CLICK) onClose() navController.navigate( ChapterScreenProps( bookIndex = bookIndex, chapterIndex = c, verseIndex = 0, ) ) } ) { Text( fontWeight = FontWeight.W600, text = "${c + 1}" ) } } } item { Spacer(modifier = Modifier.padding(bottom = 8.dp)) } } } }}