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


2f264a57 pyrossh

1 year ago
fix nightMode
.idea/inspectionProfiles/Project_Default.xml CHANGED
@@ -3,39 +3,30 @@
3
3
  <option name="myName" value="Project Default" />
4
4
  <inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
5
5
  <option name="composableFile" value="true" />
6
- <option name="previewFile" value="true" />
7
6
  </inspection_tool>
8
7
  <inspection_tool class="PreviewApiLevelMustBeValid" enabled="true" level="ERROR" enabled_by_default="true">
9
8
  <option name="composableFile" value="true" />
10
- <option name="previewFile" value="true" />
11
9
  </inspection_tool>
12
10
  <inspection_tool class="PreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
13
11
  <option name="composableFile" value="true" />
14
- <option name="previewFile" value="true" />
15
12
  </inspection_tool>
16
13
  <inspection_tool class="PreviewFontScaleMustBeGreaterThanZero" enabled="true" level="ERROR" enabled_by_default="true">
17
14
  <option name="composableFile" value="true" />
18
- <option name="previewFile" value="true" />
19
15
  </inspection_tool>
20
16
  <inspection_tool class="PreviewMultipleParameterProviders" enabled="true" level="ERROR" enabled_by_default="true">
21
17
  <option name="composableFile" value="true" />
22
- <option name="previewFile" value="true" />
23
18
  </inspection_tool>
24
19
  <inspection_tool class="PreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
25
20
  <option name="composableFile" value="true" />
26
- <option name="previewFile" value="true" />
27
21
  </inspection_tool>
28
22
  <inspection_tool class="PreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
29
23
  <option name="composableFile" value="true" />
30
- <option name="previewFile" value="true" />
31
24
  </inspection_tool>
32
25
  <inspection_tool class="PreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
33
26
  <option name="composableFile" value="true" />
34
- <option name="previewFile" value="true" />
35
27
  </inspection_tool>
36
28
  <inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
37
29
  <option name="composableFile" value="true" />
38
- <option name="previewFile" value="true" />
39
30
  </inspection_tool>
40
31
  </profile>
41
32
  </component>
app/src/main/java/dev/pyrossh/onlyBible/AppTheme.kt CHANGED
@@ -1,8 +1,6 @@
1
1
  package dev.pyrossh.onlyBible
2
2
 
3
- import android.content.res.Configuration.UI_MODE_NIGHT_MASK
4
- import android.content.res.Configuration.UI_MODE_NIGHT_NO
3
+ import android.app.UiModeManager
5
- import android.content.res.Configuration.UI_MODE_NIGHT_UNDEFINED
6
4
  import androidx.compose.foundation.isSystemInDarkTheme
7
5
  import androidx.compose.material3.MaterialTheme
8
6
  import androidx.compose.material3.dynamicDarkColorScheme
@@ -44,8 +42,7 @@ val darkHighlights = listOf(
44
42
 
45
43
 
46
44
  fun isLightTheme(uiMode: Int, isSystemDark: Boolean): Boolean {
47
- val maskedMode = uiMode and UI_MODE_NIGHT_MASK
48
- return maskedMode == UI_MODE_NIGHT_NO || (maskedMode == UI_MODE_NIGHT_UNDEFINED && !isSystemDark)
45
+ return uiMode == UiModeManager.MODE_NIGHT_NO || (uiMode == UiModeManager.MODE_NIGHT_AUTO && !isSystemDark)
49
46
  }
50
47
 
51
48
  @Composable
@@ -55,7 +52,7 @@ fun AppTheme(
55
52
  ) {
56
53
  val context = LocalContext.current
57
54
  val systemUiController = rememberSystemUiController()
58
- val colorScheme = if (isLightTheme(model.uiMode, isSystemInDarkTheme()))
55
+ val colorScheme = if (isLightTheme(model.nightMode, isSystemInDarkTheme()))
59
56
  dynamicLightColorScheme(context).copy(
60
57
  onSurface = Color.Black,
61
58
  outline = Color.LightGray,
@@ -66,8 +63,7 @@ fun AppTheme(
66
63
  surface = Color(0xFF090F12),
67
64
  outline = Color(0xAA5D4979),
68
65
  )
69
- println("AppTheme ${model.uiMode}")
70
- LaunchedEffect(key1 = model.uiMode) {
66
+ LaunchedEffect(key1 = model.nightMode) {
71
67
  systemUiController.setSystemBarsColor(
72
68
  color = colorScheme.background
73
69
  )
app/src/main/java/dev/pyrossh/onlyBible/AppViewModel.kt CHANGED
@@ -3,8 +3,10 @@ package dev.pyrossh.onlyBible
3
3
  import android.app.Application
4
4
  import android.app.LocaleConfig
5
5
  import android.app.LocaleManager
6
+ import android.app.UiModeManager
6
7
  import android.content.Context
7
8
  import android.content.Context.MODE_PRIVATE
9
+ import android.content.Context.UI_MODE_SERVICE
8
10
  import android.content.Intent
9
11
  import android.os.Build
10
12
  import android.os.LocaleList
@@ -72,7 +74,8 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {
72
74
  var fontType by mutableStateOf(FontType.Sans)
73
75
  var fontSizeDelta by mutableIntStateOf(0)
74
76
  var fontBoldEnabled by mutableStateOf(false)
75
- var uiMode by mutableIntStateOf(0)
77
+ var lineSpacingDelta by mutableStateOf(0)
78
+ var nightMode by mutableStateOf(UiModeManager.MODE_NIGHT_AUTO)
76
79
  var scrollState = LazyListState(
77
80
  0,
78
81
  0
@@ -129,9 +132,14 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {
129
132
  showBottomSheet = false
130
133
  }
131
134
 
135
+ fun setApplicationNightMode(v: Int) {
136
+ val uiModeManager = context.getSystemService(UI_MODE_SERVICE) as UiModeManager
137
+ uiModeManager.setApplicationNightMode(v)
138
+ nightMode = v
139
+ }
140
+
132
141
  fun loadData() {
133
142
  viewModelScope.launch(Dispatchers.IO) {
134
- uiMode = context.applicationContext.resources.configuration.uiMode
135
143
  loadedOnce = prefs.getBoolean("loadedOnce", false)
136
144
  if (!loadedOnce) {
137
145
  initLocales()
@@ -144,6 +152,8 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {
144
152
  )
145
153
  fontSizeDelta = prefs.getInt("fontSizeDelta", 0)
146
154
  fontBoldEnabled = prefs.getBoolean("fontBoldEnabled", false)
155
+ lineSpacingDelta = prefs.getInt("lineSpacingDelta", 0)
156
+ nightMode = prefs.getInt("nightMode", UiModeManager.MODE_NIGHT_AUTO)
147
157
  highlightedVerses.value = JSONObject(prefs.getString("highlightedVerses", "{}") ?: "{}")
148
158
  scrollState = LazyListState(
149
159
  prefs.getInt("scrollIndex", 0),
@@ -197,6 +207,8 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {
197
207
  putString("fontType", fontType.name)
198
208
  putInt("fontSizeDelta", fontSizeDelta)
199
209
  putBoolean("fontBoldEnabled", fontBoldEnabled)
210
+ putInt("lineSpacingDelta", lineSpacingDelta)
211
+ putInt("nightMode", nightMode)
200
212
  putString("highlightedVerses", highlightedVerses.value.toString())
201
213
  putInt("scrollIndex", scrollState.firstVisibleItemIndex)
202
214
  putInt("scrollOffset", scrollState.firstVisibleItemScrollOffset)
app/src/main/java/dev/pyrossh/onlyBible/ChapterScreen.kt CHANGED
@@ -123,7 +123,6 @@ fun ChapterScreen(
123
123
  ) {
124
124
  val view = LocalView.current
125
125
  val context = LocalContext.current
126
- println("Locales ${LocaleList.current.localeList.joinToString { "${it}" }}")
127
126
  val verses by model.verses.collectAsState()
128
127
  val bookNames by model.bookNames.collectAsState()
129
128
  var selectedVerses by rememberSaveable {
@@ -260,7 +259,7 @@ fun ChapterScreen(
260
259
  state = rememberSaveable(saver = LazyListState.Saver) {
261
260
  model.scrollState
262
261
  },
263
- verticalArrangement = Arrangement.spacedBy(12.dp),
262
+ verticalArrangement = Arrangement.spacedBy(16.dp + (model.lineSpacingDelta * 2).dp),
264
263
  modifier = Modifier
265
264
  .fillMaxSize()
266
265
  .padding(innerPadding)
app/src/main/java/dev/pyrossh/onlyBible/MainActivity.kt CHANGED
@@ -1,12 +1,11 @@
1
1
  package dev.pyrossh.onlyBible
2
2
 
3
+ import android.content.res.Configuration.UI_MODE_NIGHT_MASK
3
4
  import android.os.Bundle
4
5
  import androidx.activity.compose.setContent
5
6
  import androidx.activity.enableEdgeToEdge
6
7
  import androidx.activity.viewModels
7
8
  import androidx.appcompat.app.AppCompatActivity
8
- import androidx.appcompat.app.AppCompatDelegate
9
- import androidx.core.os.LocaleListCompat
10
9
  import androidx.lifecycle.lifecycleScope
11
10
  import kotlinx.coroutines.launch
12
11
 
@@ -21,7 +20,6 @@ class MainActivity : AppCompatActivity() {
21
20
  model.loadData()
22
21
  }
23
22
  addOnConfigurationChangedListener {
24
- model.uiMode = it.uiMode
25
23
  }
26
24
  setContent {
27
25
  AppTheme {
app/src/main/java/dev/pyrossh/onlyBible/TextSettingsBottomSheet.kt CHANGED
@@ -1,11 +1,8 @@
1
1
  package dev.pyrossh.onlyBible
2
2
 
3
+ import android.app.UiModeManager.MODE_NIGHT_AUTO
3
- import android.app.UiModeManager
4
+ import android.app.UiModeManager.MODE_NIGHT_NO
4
- import android.content.Context.UI_MODE_SERVICE
5
- import android.content.res.Configuration
6
- import android.content.res.Configuration.UI_MODE_NIGHT_NO
7
- import android.content.res.Configuration.UI_MODE_NIGHT_UNDEFINED
8
- import android.content.res.Configuration.UI_MODE_NIGHT_YES
5
+ import android.app.UiModeManager.MODE_NIGHT_YES
9
6
  import androidx.compose.foundation.BorderStroke
10
7
  import androidx.compose.foundation.background
11
8
  import androidx.compose.foundation.layout.Arrangement
@@ -37,7 +34,6 @@ import androidx.compose.runtime.Composable
37
34
  import androidx.compose.runtime.rememberCoroutineScope
38
35
  import androidx.compose.ui.Alignment
39
36
  import androidx.compose.ui.Modifier
40
- import androidx.compose.ui.platform.LocalContext
41
37
  import androidx.compose.ui.text.TextStyle
42
38
  import androidx.compose.ui.text.font.FontWeight
43
39
  import androidx.compose.ui.unit.dp
@@ -47,8 +43,6 @@ import kotlinx.coroutines.launch
47
43
  @Composable
48
44
  @OptIn(ExperimentalMaterial3Api::class)
49
45
  fun TextSettingsBottomSheet(model: AppViewModel) {
50
- val uiModeManager = LocalContext.current.getSystemService(UI_MODE_SERVICE) as UiModeManager
51
- val uiMode = model.uiMode and Configuration.UI_MODE_NIGHT_MASK
52
46
  val scope = rememberCoroutineScope()
53
47
  val sheetState = rememberModalBottomSheetState()
54
48
  return ModalBottomSheet(
@@ -168,7 +162,13 @@ fun TextSettingsBottomSheet(model: AppViewModel) {
168
162
  .height(60.dp)
169
163
  .padding(end = 16.dp)
170
164
  .weight(1f),
171
- onClick = {}) {
165
+ onClick = {
166
+ if (model.lineSpacingDelta > 5) {
167
+ model.lineSpacingDelta = 0
168
+ } else {
169
+ model.lineSpacingDelta += 1
170
+ }
171
+ }) {
172
172
  Column(
173
173
  modifier = Modifier.background(MaterialTheme.colorScheme.background),
174
174
  verticalArrangement = Arrangement.Center,
@@ -232,17 +232,17 @@ fun TextSettingsBottomSheet(model: AppViewModel) {
232
232
  horizontalArrangement = Arrangement.SpaceBetween,
233
233
  verticalAlignment = Alignment.CenterVertically,
234
234
  ) {
235
- listOf(UI_MODE_NIGHT_NO, UI_MODE_NIGHT_YES, UI_MODE_NIGHT_UNDEFINED).map {
235
+ listOf(MODE_NIGHT_NO, MODE_NIGHT_YES, MODE_NIGHT_AUTO).map {
236
236
  Surface(
237
237
  shape = RoundedCornerShape(8.dp),
238
- border = if (uiMode == it) BorderStroke(
238
+ border = if (model.nightMode == it) BorderStroke(
239
239
  2.dp, MaterialTheme.colorScheme.primary
240
240
  ) else null,
241
- color = if (uiMode == it)
241
+ color = if (model.nightMode == it)
242
242
  MaterialTheme.colorScheme.primary
243
243
  else
244
244
  MaterialTheme.colorScheme.onSurface,
245
- contentColor = if (uiMode == it)
245
+ contentColor = if (model.nightMode == it)
246
246
  MaterialTheme.colorScheme.primary
247
247
  else
248
248
  MaterialTheme.colorScheme.onSurface,
@@ -255,24 +255,12 @@ fun TextSettingsBottomSheet(model: AppViewModel) {
255
255
  scope.launch {
256
256
  sheetState.hide()
257
257
  model.closeSheet()
258
- when (it) {
259
- UI_MODE_NIGHT_NO -> uiModeManager.setApplicationNightMode(
258
+ model.setApplicationNightMode(it)
260
- UiModeManager.MODE_NIGHT_NO
261
- )
262
-
263
- UI_MODE_NIGHT_YES -> uiModeManager.setApplicationNightMode(
264
- UiModeManager.MODE_NIGHT_YES
265
- )
266
-
267
- UI_MODE_NIGHT_UNDEFINED -> uiModeManager.setApplicationNightMode(
268
- UiModeManager.MODE_NIGHT_AUTO
269
- )
270
- }
271
259
  }
272
260
  }
273
261
  ) {
274
262
  when (it) {
275
- UI_MODE_NIGHT_NO -> Icon(
263
+ MODE_NIGHT_NO -> Icon(
276
264
  imageVector = Icons.Filled.LightMode,
277
265
  contentDescription = "Light",
278
266
  modifier = Modifier
@@ -280,7 +268,7 @@ fun TextSettingsBottomSheet(model: AppViewModel) {
280
268
  .padding(12.dp)
281
269
  )
282
270
 
283
- UI_MODE_NIGHT_YES -> Icon(
271
+ MODE_NIGHT_YES -> Icon(
284
272
  imageVector = Icons.Filled.DarkMode,
285
273
  contentDescription = "Dark",
286
274
  modifier = Modifier
@@ -288,7 +276,7 @@ fun TextSettingsBottomSheet(model: AppViewModel) {
288
276
  .padding(12.dp)
289
277
  )
290
278
 
291
- UI_MODE_NIGHT_UNDEFINED -> Column(
279
+ MODE_NIGHT_AUTO -> Column(
292
280
  modifier = Modifier.background(
293
281
  color = MaterialTheme.colorScheme.background,
294
282
  ),
app/src/main/java/dev/pyrossh/onlyBible/composables/VerseView.kt CHANGED
@@ -71,7 +71,7 @@ fun VerseView(
71
71
  var barYPosition by remember {
72
72
  mutableIntStateOf(0)
73
73
  }
74
- val isLight = isLightTheme(model.uiMode, isSystemInDarkTheme())
74
+ val isLight = isLightTheme(model.nightMode, isSystemInDarkTheme())
75
75
  val fontSizeDelta = model.fontSizeDelta
76
76
  val boldWeight = if (model.fontBoldEnabled) FontWeight.W700 else FontWeight.W400
77
77
  val buttonInteractionSource = remember { MutableInteractionSource() }
readme.md CHANGED
@@ -5,8 +5,8 @@ The only bible app you will ever need.
5
5
  No ads, No in-app purchases, No distractions.
6
6
 
7
7
  Optimized for reading and highlighting.
8
- Only Bibles which are in the public domain are available.
8
+ Bibles which are in the public domain are supported.
9
- Verse by verse audio is also supported for some of the languages using Azure TTS.
9
+ Verse by verse audio playback is supported for most of the languages using Azure TTS.
10
10
  Many languages supported Indian, European and Asian.
11
11
 
12
12
  ## Setup
@@ -37,7 +37,3 @@ fastlane supply --aab ../build/app/outputs/bundle/release/app-release.aab
37
37
  flutter build ipa --release --dart-define-from-file=.env
38
38
  fastlane deliver --ipa "../build/ios/ipa/only-bible-app.ipa" --automatic_release --submit_for_review
39
39
  ```
40
-
41
- ## TODO
42
-
43
- * Improve Paging in dark mode