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


25dc77f7 pyrossh

1 year ago
improve Book selection
app/src/main/java/dev/pyrossh/onlyBible/composables/ChapterSelector.kt CHANGED
@@ -25,7 +25,6 @@ import androidx.compose.material3.Surface
25
25
  import androidx.compose.material3.Text
26
26
  import androidx.compose.material3.TextButton
27
27
  import androidx.compose.runtime.Composable
28
- import androidx.compose.runtime.LaunchedEffect
29
28
  import androidx.compose.runtime.getValue
30
29
  import androidx.compose.runtime.mutableIntStateOf
31
30
  import androidx.compose.runtime.mutableStateOf
@@ -56,11 +55,12 @@ fun ChapterSelector(
56
55
  val height = context.resources.configuration.screenHeightDp.dp / 2
57
56
  var expanded by remember { mutableStateOf(false) }
58
57
  var bookIndex by remember { mutableIntStateOf(startBookIndex) }
59
- val scrollState = rememberLazyListState()
58
+ val scrollState = rememberLazyListState(
60
- val bookList = bookNames - bookNames[bookIndex]
59
+ initialFirstVisibleItemIndex = if (startBookIndex - 2 >= 0)
61
- LaunchedEffect(key1 = bookIndex) {
60
+ startBookIndex - 2
62
- scrollState.scrollToItem(0, 0)
61
+ else
62
+ 0,
63
- }
63
+ )
64
64
  Dialog(onDismissRequest = { onClose() }) {
65
65
  Card(
66
66
  modifier = Modifier
@@ -84,7 +84,10 @@ fun ChapterSelector(
84
84
  Text(
85
85
  modifier = Modifier.padding(start = 4.dp),
86
86
  fontWeight = FontWeight.W600,
87
+ text = if (expanded)
88
+ "Books"
89
+ else
87
- text = bookNames[bookIndex]
90
+ bookNames[bookIndex]
88
91
  )
89
92
  },
90
93
  trailingContent = {
@@ -95,7 +98,7 @@ fun ChapterSelector(
95
98
  LazyColumn(
96
99
  state = scrollState,
97
100
  ) {
98
- items(bookList) {
101
+ items(bookNames) {
99
102
  ListItem(
100
103
  modifier = Modifier.clickable {
101
104
  bookIndex = bookNames.indexOf(it)