~repos /only-bible-app

#kotlin#android#ios

git clone https://pyrossh.dev/repos/only-bible-app.git
Discussions: https://groups.google.com/g/rust-embed-devs

The only bible app you will ever need. No ads. No in-app purchases. No distractions.


27473294 Peter John

1 year ago
improve theming
app/src/main/java/dev/pyrossh/onlyBible/ChapterScreen.kt CHANGED
@@ -15,7 +15,6 @@ import androidx.compose.foundation.layout.Arrangement
15
15
  import androidx.compose.foundation.layout.Box
16
16
  import androidx.compose.foundation.layout.Row
17
17
  import androidx.compose.foundation.layout.fillMaxSize
18
- import androidx.compose.foundation.layout.height
19
18
  import androidx.compose.foundation.layout.padding
20
19
  import androidx.compose.foundation.layout.wrapContentSize
21
20
  import androidx.compose.foundation.lazy.LazyColumn
@@ -112,8 +111,8 @@ fun ChapterScreen(
112
111
  .fillMaxSize(),
113
112
  topBar = {
114
113
  TopAppBar(
115
- modifier = Modifier
114
+ // modifier = Modifier
116
- .height(72.dp),
115
+ // .height(90.dp),
117
116
  // .padding(vertical = 8.dp),
118
117
  title = {
119
118
  Row(
@@ -289,7 +288,7 @@ fun ChapterScreen(
289
288
  }
290
289
  val isSelected = selectedVerses.contains(v);
291
290
  val background =
292
- if (isSelected) Color(0xFFEEEEEE) else MaterialTheme.colorScheme.background
291
+ if (isSelected) MaterialTheme.colorScheme.onPrimary else MaterialTheme.colorScheme.background
293
292
  Text(modifier = Modifier
294
293
  .clickable {
295
294
  selectedVerses = if (selectedVerses.contains(v)) {
@@ -301,7 +300,7 @@ fun ChapterScreen(
301
300
  style = TextStyle(
302
301
  background = background,
303
302
  fontFamily = fontFamily,
304
- color = Color.Black,
303
+ color = MaterialTheme.typography.bodyMedium.color,
305
304
  fontWeight = boldWeight,
306
305
  fontSize = (16 + state.fontSizeDelta).sp,
307
306
  lineHeight = (22 + state.fontSizeDelta).sp,
app/src/main/java/dev/pyrossh/onlyBible/Drawer.kt CHANGED
@@ -40,6 +40,7 @@ import androidx.compose.ui.unit.dp
40
40
  import androidx.compose.ui.unit.sp
41
41
  import androidx.navigation.NavController
42
42
  import kotlinx.coroutines.Job
43
+ import kotlinx.coroutines.delay
43
44
  import kotlinx.coroutines.launch
44
45
 
45
46
  enum class MenuType {
@@ -127,20 +128,12 @@ fun Drawer(
127
128
  items(state.bibles) { b ->
128
129
  QuickButton(b) {
129
130
  scope.launch {
130
- drawerState.close();
131
+ drawerState.close()
131
- state.isLoading = true;
132
+ state.isLoading = true
133
+ delay(500L)
134
+ }.invokeOnCompletion {
132
135
  state.setBibleName(b)
133
- state.reload()
134
136
  }
135
- // scope.launch {
136
- // navController.navigate(
137
- // ChapterScreenProps(
138
- // bookIndex = bookIndex,
139
- // chapterIndex = 0,
140
- // )
141
- // )
142
- // drawerState.close();
143
- // }
144
137
  }
145
138
  }
146
139
  }
@@ -153,24 +146,24 @@ fun Drawer(
153
146
  columns = GridCells.Fixed(5)
154
147
  ) {
155
148
  header {
156
- Row(
149
+ Row(
157
- modifier = Modifier.fillMaxWidth(),
150
+ modifier = Modifier.fillMaxWidth(),
158
- horizontalArrangement = Arrangement.SpaceBetween,
151
+ horizontalArrangement = Arrangement.SpaceBetween,
159
- verticalAlignment = Alignment.CenterVertically,
152
+ verticalAlignment = Alignment.CenterVertically,
160
- ) {
153
+ ) {
161
- Text(
154
+ Text(
162
- text = "Old Testament",
155
+ text = "Old Testament",
163
- fontSize = 18.sp,
156
+ fontSize = 18.sp,
164
- fontWeight = FontWeight.W500
157
+ fontWeight = FontWeight.W500
165
- )
158
+ )
166
- IconButton(onClick = {
159
+ IconButton(onClick = {
167
- scope.launch {
160
+ scope.launch {
168
- drawerState.close();
161
+ drawerState.close();
169
- }
170
- }) {
171
- Icon(Icons.Filled.Close, "Close")
172
162
  }
163
+ }) {
164
+ Icon(Icons.Filled.Close, "Close")
173
165
  }
166
+ }
174
167
  }
175
168
  items(39) { b ->
176
169
  QuickButton(shortName(bookNames[b])) {
app/src/main/java/dev/pyrossh/onlyBible/LoadingBox.kt CHANGED
@@ -16,7 +16,7 @@ import androidx.compose.ui.draw.alpha
16
16
  @Composable
17
17
  fun LoadingBox(
18
18
  modifier: Modifier = Modifier,
19
- isLoading: Boolean = false,
19
+ isLoading: Boolean,
20
20
  content: @Composable() () -> Unit
21
21
  ) {
22
22
  Box(
app/src/main/java/dev/pyrossh/onlyBible/MainActivity.kt CHANGED
@@ -19,26 +19,16 @@ class MainActivity : ComponentActivity() {
19
19
  val prefs = applicationContext.getSharedPreferences("settings", Context.MODE_PRIVATE)
20
20
  val bibles =
21
21
  assets.list("bibles")?.map { it.replace("bibles/", "").replace(".txt", "") } ?: listOf()
22
- val reload = {
23
- recreate()
24
- // finish();
25
- // overrideActivityTransition(0, 0, 0);
26
- // startActivity(intent);
27
- // overrideActivityTransition(0, 0, 0);
28
- // finish();
29
- // startActivity(intent);
30
- }
31
- val state = State(prefs, bibles, reload)
22
+ val state = State(prefs, bibles) { recreate() }
32
23
  val bibleName = state.getBibleName()
33
24
  val fileName = bibles.find { it.contains(bibleName) } ?: "English"
34
25
  val verses = Verse.parseFromBibleTxt(
35
26
  bibleName,
36
27
  assets.open("bibles/${fileName}.txt").bufferedReader()
37
28
  )
38
-
39
29
  setContent {
30
+ CompositionLocalProvider(LocalState provides state) {
40
- AppTheme {
31
+ AppTheme {
41
- CompositionLocalProvider(LocalState provides state) {
42
32
  AppHost(
43
33
  verses = verses
44
34
  )
app/src/main/java/dev/pyrossh/onlyBible/State.kt CHANGED
@@ -1,39 +1,18 @@
1
1
  package dev.pyrossh.onlyBible
2
2
 
3
+ import FontType
3
4
  import android.content.SharedPreferences
4
5
  import androidx.compose.runtime.getValue
5
6
  import androidx.compose.runtime.mutableIntStateOf
6
7
  import androidx.compose.runtime.mutableStateOf
7
8
  import androidx.compose.runtime.setValue
8
9
  import androidx.compose.runtime.staticCompositionLocalOf
9
- import androidx.compose.ui.text.font.FontFamily
10
- import androidx.compose.ui.text.font.GenericFontFamily
11
10
  import androidx.lifecycle.ViewModel
11
+ import dev.pyrossh.onlyBible.ui.theme.ThemeType
12
12
  import java.util.Locale
13
13
 
14
14
  val LocalState = staticCompositionLocalOf<State?> { null }
15
15
 
16
- enum class FontType {
17
- Sans,
18
- Serif,
19
- Mono;
20
-
21
- fun family(): GenericFontFamily {
22
- return when (this) {
23
- Sans -> FontFamily.SansSerif
24
- Serif -> FontFamily.Serif
25
- Mono -> FontFamily.Monospace
26
- }
27
- }
28
- }
29
-
30
- enum class ThemeType {
31
- Light,
32
- Warm,
33
- Dark,
34
- Auto
35
- }
36
-
37
16
  class State(p: SharedPreferences, val bibles: List<String>, val reload: () -> Unit) : ViewModel() {
38
17
  private val prefs: SharedPreferences = p
39
18
  var isLoading by mutableStateOf(false)
@@ -45,16 +24,20 @@ class State(p: SharedPreferences, val bibles: List<String>, val reload: () -> Un
45
24
  )
46
25
  var fontSizeDelta by mutableIntStateOf(prefs.getInt("fontSizeDelta", 0))
47
26
  var boldEnabled by mutableStateOf(prefs.getBoolean("bold", false))
48
- var themeType by mutableStateOf(prefs.getString("themeType", ThemeType.Auto.name))
27
+ var themeType by mutableStateOf(
49
-
28
+ ThemeType.valueOf(
29
+ prefs.getString(
30
+ "themeType",
31
+ ThemeType.Auto.name
50
- fun getThemeType(): Int {
32
+ ) ?: ThemeType.Auto.name
51
- return prefs.getInt("themeType", 0)
52
- }
33
+ )
34
+ )
53
35
 
54
- fun setThemeType(v: ThemeType) {
36
+ fun updateTheme(v: ThemeType) {
55
37
  val editor = prefs.edit()
56
38
  editor.putString("themeType", v.name)
57
39
  editor.apply()
40
+ reload()
58
41
  }
59
42
 
60
43
  fun getBibleName(): String {
@@ -66,6 +49,7 @@ class State(p: SharedPreferences, val bibles: List<String>, val reload: () -> Un
66
49
  val editor = prefs.edit()
67
50
  editor.putString("bibleName", v)
68
51
  editor.apply()
52
+ reload()
69
53
  }
70
54
 
71
55
  fun getBookIndex(): Int {
@@ -116,5 +100,4 @@ class State(p: SharedPreferences, val bibles: List<String>, val reload: () -> Un
116
100
  editor.putString("fontType", v.name)
117
101
  editor.apply()
118
102
  }
119
-
120
103
  }
app/src/main/java/dev/pyrossh/onlyBible/{TextSettings.kt → TextSettingsBottomSheet.kt} RENAMED
@@ -1,5 +1,6 @@
1
1
  package dev.pyrossh.onlyBible
2
2
 
3
+ import FontType
3
4
  import androidx.compose.foundation.BorderStroke
4
5
  import androidx.compose.foundation.background
5
6
  import androidx.compose.foundation.layout.Arrangement
@@ -29,12 +30,12 @@ import androidx.compose.runtime.Composable
29
30
  import androidx.compose.runtime.rememberCoroutineScope
30
31
  import androidx.compose.ui.Alignment
31
32
  import androidx.compose.ui.Modifier
32
- import androidx.compose.ui.graphics.Color
33
- import androidx.compose.ui.res.painterResource
34
33
  import androidx.compose.ui.text.TextStyle
35
34
  import androidx.compose.ui.text.font.FontWeight
36
35
  import androidx.compose.ui.unit.dp
37
36
  import androidx.compose.ui.unit.sp
37
+ import dev.pyrossh.onlyBible.ui.theme.ThemeType
38
+ import kotlinx.coroutines.delay
38
39
  import kotlinx.coroutines.launch
39
40
 
40
41
  @Composable
@@ -44,11 +45,14 @@ fun TextSettingsBottomSheet() {
44
45
  val sheetState = rememberModalBottomSheetState()
45
46
  val state = LocalState.current!!
46
47
  return ModalBottomSheet(
48
+ sheetState = sheetState,
47
49
  onDismissRequest = {
48
50
  scope.launch {
51
+ sheetState.hide()
52
+ }.invokeOnCompletion {
49
53
  state.closeSheet()
50
54
  }
51
- }, sheetState = sheetState
55
+ },
52
56
  ) {
53
57
  Column(
54
58
  modifier = Modifier
@@ -67,6 +71,8 @@ fun TextSettingsBottomSheet() {
67
71
  Row(horizontalArrangement = Arrangement.End) {
68
72
  IconButton(onClick = {
69
73
  scope.launch {
74
+ sheetState.hide()
75
+ }.invokeOnCompletion {
70
76
  state.closeSheet()
71
77
  }
72
78
  }) {
@@ -171,7 +177,8 @@ fun TextSettingsBottomSheet() {
171
177
  verticalAlignment = Alignment.CenterVertically,
172
178
  ) {
173
179
  FontType.entries.map {
180
+ Surface(
174
- Surface(shape = RoundedCornerShape(8.dp),
181
+ shape = RoundedCornerShape(8.dp),
175
182
  border = if (state.fontType == it) BorderStroke(
176
183
  2.dp, MaterialTheme.colorScheme.primary
177
184
  ) else null,
@@ -209,79 +216,31 @@ fun TextSettingsBottomSheet() {
209
216
  horizontalArrangement = Arrangement.SpaceBetween,
210
217
  verticalAlignment = Alignment.CenterVertically,
211
218
  ) {
212
- // #72abbf on active
213
- // #ebe0c7 on yellow
219
+ ThemeType.entries.map { t ->
214
- // #424547 on dark
220
+ Surface(
215
- Surface(shape = RoundedCornerShape(8.dp),
221
+ shape = RoundedCornerShape(8.dp),
216
- border = BorderStroke(
222
+ border = if (state.themeType == t) BorderStroke(
217
- 2.dp, MaterialTheme.colorScheme.primary
223
+ 2.dp, MaterialTheme.colorScheme.primary
218
- ),
219
- modifier = Modifier
220
- .fillMaxWidth()
221
- .height(80.dp)
222
- .padding(end = 16.dp)
223
- .weight(1f),
224
+ ) else null,
224
- onClick = {}) {
225
- Icon(
226
- painter = painterResource(id = R.drawable.text_theme),
227
- contentDescription = "Light",
228
- tint = Color(0xFF424547),
229
- modifier = Modifier
230
- .background(Color.White)
231
- .padding(8.dp)
232
- )
233
- }
234
- Surface(shape = RoundedCornerShape(8.dp),
235
- modifier = Modifier
236
- .fillMaxWidth()
237
- .height(80.dp)
238
- .padding(end = 16.dp)
239
- .weight(1f),
240
- onClick = {}) {
241
- Icon(
242
- painter = painterResource(id = R.drawable.text_theme),
243
- contentDescription = "Warm",
244
- tint = Color(0xFF424547),
245
- modifier = Modifier
246
- .background(Color(0xFFe5e0d1))
247
- .padding(8.dp)
248
- )
249
- }
250
- Surface(shape = RoundedCornerShape(8.dp),
251
- modifier = Modifier
252
- .fillMaxWidth()
253
- .height(80.dp)
254
- .padding(end = 16.dp)
255
- .weight(1f),
256
- onClick = {}) {
257
- Icon(
258
- painter = painterResource(id = R.drawable.text_theme),
259
- contentDescription = "Dark",
260
- tint = Color(0xFFd3d7da),
261
225
  modifier = Modifier
226
+ .fillMaxWidth()
262
- .background(Color(0xFF2c2e30))
227
+ .height(80.dp)
263
- .padding(8.dp)
228
+ .padding(end = 16.dp)
229
+ .weight(1f),
230
+ onClick = {
231
+ scope.launch {
232
+ sheetState.hide()
233
+ state.isLoading = true
264
- )
234
+ delay(500L)
235
+ }.invokeOnCompletion {
236
+ state.closeSheet()
237
+ state.updateTheme(t)
265
- }
238
+ }
266
- Surface(shape = RoundedCornerShape(8.dp),
267
- modifier = Modifier
268
- .fillMaxWidth()
269
- .height(80.dp)
270
- .padding(end = 16.dp)
271
- .weight(1f),
272
- onClick = {}) {
239
+ }
273
- Column(
274
- modifier = Modifier.background(Color(0xFFFAFAFA)),
275
- verticalArrangement = Arrangement.Center,
276
- horizontalAlignment = Alignment.CenterHorizontally
277
240
  ) {
278
- Text(
241
+ t.Icon()
279
- text = "Auto", style = TextStyle(
280
- fontSize = 18.sp,
281
- fontWeight = FontWeight.Medium,
282
- )
283
- )
284
242
  }
243
+
285
244
  }
286
245
  }
287
246
  }
app/src/main/java/dev/pyrossh/onlyBible/ui/theme/Font.kt CHANGED
@@ -1,8 +1,23 @@
1
1
  import androidx.compose.ui.text.font.FontFamily
2
+ import androidx.compose.ui.text.font.GenericFontFamily
2
3
  import androidx.compose.ui.text.googlefonts.Font
3
4
  import androidx.compose.ui.text.googlefonts.GoogleFont
4
5
  import dev.pyrossh.onlyBible.R
5
6
 
7
+ enum class FontType {
8
+ Sans,
9
+ Serif,
10
+ Mono;
11
+
12
+ fun family(): GenericFontFamily {
13
+ return when (this) {
14
+ Sans -> FontFamily.SansSerif
15
+ Serif -> FontFamily.Serif
16
+ Mono -> FontFamily.Monospace
17
+ }
18
+ }
19
+ }
20
+
6
21
  val provider = GoogleFont.Provider(
7
22
  providerAuthority = "com.google.android.gms.fonts",
8
23
  providerPackage = "com.google.android.gms",
app/src/main/java/dev/pyrossh/onlyBible/ui/theme/Theme.kt CHANGED
@@ -1,22 +1,94 @@
1
1
  package dev.pyrossh.onlyBible.ui.theme
2
2
 
3
+ import androidx.compose.foundation.background
3
4
  import androidx.compose.foundation.isSystemInDarkTheme
5
+ import androidx.compose.foundation.layout.Arrangement
6
+ import androidx.compose.foundation.layout.Column
7
+ import androidx.compose.foundation.layout.padding
4
8
  import androidx.compose.material3.MaterialTheme
9
+ import androidx.compose.material3.Text
5
10
  import androidx.compose.material3.dynamicDarkColorScheme
6
11
  import androidx.compose.material3.dynamicLightColorScheme
7
12
  import androidx.compose.runtime.Composable
13
+ import androidx.compose.ui.Alignment
14
+ import androidx.compose.ui.Modifier
15
+ import androidx.compose.ui.graphics.Color
8
16
  import androidx.compose.ui.platform.LocalContext
17
+ import androidx.compose.ui.res.painterResource
18
+ import androidx.compose.ui.text.TextStyle
19
+ import androidx.compose.ui.text.font.FontWeight
20
+ import androidx.compose.ui.unit.dp
21
+ import androidx.compose.ui.unit.sp
9
22
  import com.google.accompanist.systemuicontroller.rememberSystemUiController
23
+ import dev.pyrossh.onlyBible.LocalState
24
+ import dev.pyrossh.onlyBible.R
25
+
26
+
27
+ enum class ThemeType {
28
+ Light,
29
+ Dark,
30
+ Auto;
31
+
32
+ private fun background(isDark: Boolean): Color {
33
+ return when {
34
+ this == Light || (this == Auto && !isDark) -> Color.White
35
+ else -> Color(0xFF2c2e30)
36
+ }
37
+ }
38
+
39
+ private fun tint(isDark: Boolean): Color {
40
+ return when {
41
+ this == Light || (this == Auto && !isDark) -> Color(0xFF424547)
42
+ else -> Color(0xFFd3d7da)
43
+ }
44
+ }
45
+
46
+ @Composable
47
+ fun Icon() {
48
+ val name = this.name;
49
+ val darkTheme = isSystemInDarkTheme()
50
+ when (this) {
51
+ Light, Dark -> androidx.compose.material3.Icon(
52
+ painter = painterResource(id = R.drawable.text_theme),
53
+ contentDescription = "Light",
54
+ tint = this.tint(darkTheme),
55
+ modifier = Modifier
56
+ .background(this.background(darkTheme))
57
+ .padding(4.dp)
58
+ )
59
+
60
+ Auto -> Column(
61
+ modifier = Modifier.background(
62
+ color = MaterialTheme.colorScheme.background,
63
+ ),
64
+ verticalArrangement = Arrangement.Center,
65
+ horizontalAlignment = Alignment.CenterHorizontally
66
+ ) {
67
+ Text(
68
+ text = name,
69
+ style = TextStyle(
70
+ fontSize = 18.sp,
71
+ fontWeight = FontWeight.Medium,
72
+ ),
73
+ )
74
+ }
75
+ }
76
+ }
77
+ }
10
78
 
11
79
  @Composable
12
80
  fun AppTheme(
13
81
  content: @Composable() () -> Unit
14
82
  ) {
83
+ val context = LocalContext.current
84
+ val state = LocalState.current!!
15
85
  val darkTheme = isSystemInDarkTheme()
16
86
  val systemUiController = rememberSystemUiController()
17
- val context = LocalContext.current
87
+ val colorScheme = when (state.themeType) {
88
+ ThemeType.Light -> dynamicLightColorScheme(context)
18
- val colorScheme =
89
+ ThemeType.Dark -> dynamicDarkColorScheme(context)
19
- if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
90
+ ThemeType.Auto -> if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
91
+ }
20
92
  systemUiController.setSystemBarsColor(
21
93
  color = colorScheme.background
22
94
  )