Skip to content

Commit a2471bb

Browse files
authored
Merge pull request #239 from dmzz-yyhyy/undo
重新支持隐藏阅读器电池指示器
2 parents a972c99 + 09525b7 commit a2471bb

16 files changed

Lines changed: 191 additions & 26 deletions

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ android {
1919
minSdk = 24
2020
targetSdk = 36
2121
// 版本号为x.y.z则versionCode为x*1000000+y*10000+z*1000+debug版本号(开发需要时迭代, 三位数)
22-
versionCode = 1_01_00_033
22+
versionCode = 1_01_00_035
2323
versionName = "1.1.0"
2424

2525
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/data/userdata/UserDataPath.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ sealed class UserDataPath(
2828
data object IsUsingVolumeKeyFlip : UserDataPath("isUsingVolumeKeyFlip", Reader)
2929
data object FlipAnime : UserDataPath("flipAnime", Reader)
3030
data object FastChapterChange : UserDataPath("fastChapterChange", Reader)
31-
data object EnableBatteryIndicator : UserDataPath("enableBatteryIndicator", Reader)
31+
data object BatteryIndicatorDisplayMode : UserDataPath("batteryIndicatorDisplayMode", Reader)
3232
data object EnableTimeIndicator : UserDataPath("enableTimeIndicator", Reader)
3333
data object EnableChapterTitleIndicator : UserDataPath("enableChapterTitleIndicator", Reader)
3434
data object EnableReadingChapterProgressIndicator : UserDataPath("enableReadingChapterProgressIndicator", Reader)

app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/ui/book/reader/ReaderScreen.kt

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package indi.dmzz_yyhyy.lightnovelreader.ui.book.reader
22

33
import android.annotation.SuppressLint
44
import android.app.Activity
5+
import android.content.Context.BATTERY_SERVICE
6+
import android.os.BatteryManager
57
import android.util.Log
68
import android.view.View
79
import android.view.WindowManager
@@ -26,6 +28,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
2628
import androidx.compose.foundation.layout.height
2729
import androidx.compose.foundation.layout.padding
2830
import androidx.compose.foundation.layout.safeContent
31+
import androidx.compose.foundation.layout.size
2932
import androidx.compose.foundation.layout.width
3033
import androidx.compose.foundation.lazy.LazyColumn
3134
import androidx.compose.foundation.lazy.LazyRow
@@ -36,7 +39,7 @@ import androidx.compose.material3.CircularProgressIndicator
3639
import androidx.compose.material3.ExperimentalMaterial3Api
3740
import androidx.compose.material3.Icon
3841
import androidx.compose.material3.IconButton
39-
import androidx.compose.material3.MaterialTheme
42+
import androidx.compose.material3.MaterialTheme.colorScheme
4043
import androidx.compose.material3.ModalBottomSheet
4144
import androidx.compose.material3.Scaffold
4245
import androidx.compose.material3.SheetState
@@ -128,7 +131,7 @@ fun ReaderScreen(
128131
)
129132
}
130133
},
131-
containerColor = if (settingState.backgroundColor.isUnspecified) MaterialTheme.colorScheme.background else settingState.backgroundColor
134+
containerColor = if (settingState.backgroundColor.isUnspecified) colorScheme.background else settingState.backgroundColor
132135
) { _ ->
133136
if (settingState.enableBackgroundImage) {
134137
Image(
@@ -190,10 +193,19 @@ fun Content(
190193
@Suppress("DEPRECATION")
191194
controller.apply {
192195
if (isImmersive) {
193-
var visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
194-
val navbar = (View.SYSTEM_UI_FLAG_LOW_PROFILE or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)
195-
visibility = visibility or navbar
196-
window.decorView.systemUiVisibility = visibility
196+
if (settingState.batteryIndicatorDisplayMode == "immersed") {
197+
var visibility =
198+
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
199+
val navbar =
200+
View.SYSTEM_UI_FLAG_LOW_PROFILE or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
201+
visibility = visibility or navbar
202+
window.decorView.systemUiVisibility = visibility
203+
} else {
204+
val visibility =
205+
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
206+
window.decorView.systemUiVisibility = visibility
207+
}
208+
197209
} else {
198210
show(WindowInsetsCompat.Type.systemBars())
199211
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
@@ -312,6 +324,7 @@ fun Content(
312324
end = settingState.rightPadding.dp
313325
)
314326
),
327+
enableBatteryIndicator = settingState.batteryIndicatorDisplayMode == "classic",
315328
enableTimeIndicator = settingState.enableTimeIndicator,
316329
enableChapterTitle = settingState.enableChapterTitleIndicator,
317330
chapterTitle = readingScreenUiState.contentUiState.readingChapterContent.title,
@@ -396,7 +409,7 @@ private fun TopBar(
396409
text = it,
397410
style = AppTypography.titleTopBar,
398411
fontWeight = FontWeight.W400,
399-
color = MaterialTheme.colorScheme.onSurface,
412+
color = colorScheme.onSurface,
400413
maxLines = 1
401414
)
402415
}
@@ -555,7 +568,9 @@ fun ChapterSelectorBottomSheet(
555568
exit = shrinkVertically() + fadeOut()
556569
) {
557570
Box(
558-
modifier = Modifier.fillMaxWidth().height(300.dp)
571+
modifier = Modifier
572+
.fillMaxWidth()
573+
.height(300.dp)
559574
) {
560575
CircularProgressIndicator(
561576
modifier = Modifier.align(Alignment.Center)
@@ -588,14 +603,14 @@ fun ChapterSelectorBottomSheet(
588603
text = volume.volumeTitle,
589604
fontWeight = FontWeight.W600,
590605
style = AppTypography.titleMedium,
591-
color = MaterialTheme.colorScheme.onSurface
606+
color = colorScheme.onSurface
592607
)
593608
Text(
594609
text = stringResource(
595610
R.string.info_volume_chapters_count,
596611
volume.chapters.size
597612
),
598-
color = MaterialTheme.colorScheme.secondary,
613+
color = colorScheme.secondary,
599614
style = AppTypography.labelMedium
600615
)
601616
}
@@ -605,7 +620,7 @@ fun ChapterSelectorBottomSheet(
605620
.scale(0.75f, 0.75f)
606621
.rotate(if (selectedVolumeId == volume.volumeId) -90f else 90f),
607622
painter = painterResource(R.drawable.arrow_forward_ios_24px),
608-
tint = MaterialTheme.colorScheme.onSurface,
623+
tint = colorScheme.onSurface,
609624
contentDescription = null
610625
)
611626
}
@@ -630,7 +645,7 @@ fun ChapterSelectorBottomSheet(
630645
if (isSelected) {
631646
Icon(
632647
painter = painterResource(R.drawable.play_arrow_24px),
633-
tint = MaterialTheme.colorScheme.outline,
648+
tint = colorScheme.outline,
634649
contentDescription = null
635650
)
636651
Spacer(Modifier.width(8.dp))
@@ -639,7 +654,7 @@ fun ChapterSelectorBottomSheet(
639654
text = chapter.title,
640655
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal,
641656
style = AppTypography.titleSmall,
642-
color = MaterialTheme.colorScheme.onSurfaceVariant,
657+
color = colorScheme.onSurfaceVariant,
643658
maxLines = 2
644659
)
645660
}
@@ -656,6 +671,7 @@ fun ChapterSelectorBottomSheet(
656671
@Composable
657672
fun Indicator(
658673
modifier: Modifier = Modifier,
674+
enableBatteryIndicator: Boolean,
659675
enableTimeIndicator: Boolean,
660676
enableChapterTitle: Boolean,
661677
chapterTitle: String,
@@ -672,6 +688,42 @@ fun Indicator(
672688
Row(
673689
verticalAlignment = Alignment.CenterVertically
674690
) {
691+
if (enableBatteryIndicator) {
692+
val batteryManager = LocalContext.current.getSystemService(BATTERY_SERVICE) as BatteryManager
693+
val batLevel: Int = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
694+
RollingNumber(
695+
modifier = Modifier.align(Alignment.CenterVertically),
696+
number = batLevel,
697+
style = AppTypography.labelMedium.copy(
698+
fontWeight = FontWeight.W500
699+
),
700+
color = colorScheme.onSurfaceVariant,
701+
length = 3
702+
)
703+
Text(
704+
text = "%",
705+
style = AppTypography.labelMedium,
706+
fontWeight = FontWeight.W500,
707+
color = colorScheme.onSurfaceVariant
708+
)
709+
Spacer(Modifier.width(4.dp))
710+
Icon(
711+
modifier = Modifier.size(20.dp),
712+
painter =
713+
when {
714+
(batLevel in 0..15) -> painterResource(R.drawable.battery_android_alert_24px)
715+
(batLevel in 16..35) -> painterResource(R.drawable.battery_android_3_24px)
716+
(batLevel in 36..65) -> painterResource(R.drawable.battery_android_4_24px)
717+
(batLevel in 66..80) -> painterResource(R.drawable.battery_android_5_24px)
718+
(batLevel in 81..95) -> painterResource(R.drawable.battery_android_6_24px)
719+
(batLevel in 96..100) -> painterResource(R.drawable.battery_android_full_24px)
720+
else -> painterResource(R.drawable.battery_android_question_24px)
721+
},
722+
tint = colorScheme.onSurfaceVariant,
723+
contentDescription = null
724+
)
725+
Spacer(Modifier.width(14.dp))
726+
}
675727
if (enableTimeIndicator) {
676728
AnimatedText(
677729
modifier = Modifier.align(Alignment.CenterVertically),
@@ -680,9 +732,8 @@ fun Indicator(
680732
letterSpacing = 1.sp
681733
),
682734
fontWeight = FontWeight.W500,
683-
color = MaterialTheme.colorScheme.onSurfaceVariant
735+
color = colorScheme.onSurfaceVariant
684736
)
685-
686737
}
687738
}
688739

@@ -698,7 +749,7 @@ fun Indicator(
698749
text = chapterTitle,
699750
textAlign = TextAlign.End,
700751
style = AppTypography.labelMedium,
701-
color = MaterialTheme.colorScheme.onSurfaceVariant,
752+
color = colorScheme.onSurfaceVariant,
702753
maxLines = 1,
703754
overflow = TextOverflow.Ellipsis
704755
)
@@ -715,14 +766,14 @@ fun Indicator(
715766
style = AppTypography.labelMedium.copy(
716767
fontWeight = FontWeight.W500
717768
),
718-
color = MaterialTheme.colorScheme.onSurfaceVariant,
769+
color = colorScheme.onSurfaceVariant,
719770
length = 3
720771
)
721772
Text(
722773
text = "%",
723774
style = AppTypography.labelMedium,
724775
fontWeight = FontWeight.W500,
725-
color = MaterialTheme.colorScheme.onSurfaceVariant
776+
color = colorScheme.onSurfaceVariant
726777
)
727778
}
728779
}

app/src/main/kotlin/indi/dmzz_yyhyy/lightnovelreader/ui/book/reader/ReaderSettingsScreen.kt

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
package indi.dmzz_yyhyy.lightnovelreader.ui.book.reader
23

34
import android.content.Intent
@@ -22,7 +23,7 @@ import androidx.compose.foundation.pager.rememberPagerState
2223
import androidx.compose.foundation.shape.RoundedCornerShape
2324
import androidx.compose.material3.ExperimentalMaterial3Api
2425
import androidx.compose.material3.Icon
25-
import androidx.compose.material3.MaterialTheme
26+
import androidx.compose.material3.MaterialTheme.colorScheme
2627
import androidx.compose.material3.ModalBottomSheet
2728
import androidx.compose.material3.SheetState
2829
import androidx.compose.material3.Tab
@@ -66,7 +67,7 @@ fun SettingsBottomSheet(
6667
onDismissRequest = onDismissRequest,
6768
sheetState = sheetState,
6869
shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp),
69-
containerColor = MaterialTheme.colorScheme.surfaceContainerHigh,
70+
containerColor = colorScheme.surfaceContainerHigh,
7071
tonalElevation = 16.dp
7172
) {
7273
var selectedTabIndex by remember { mutableIntStateOf(0) }
@@ -127,7 +128,7 @@ fun ContentSettings(
127128
state = pagerState,
128129
modifier = Modifier
129130
.fillMaxSize()
130-
.background(MaterialTheme.colorScheme.surfaceContainerLow)
131+
.background(colorScheme.surfaceContainerLow)
131132
.padding(horizontal = 8.dp, vertical = 12.dp),
132133
userScrollEnabled = false
133134
) { pageIndex ->
@@ -154,7 +155,7 @@ fun TabsRow(
154155
onTabSelected: (Int) -> Unit
155156
) {
156157
TabRow(
157-
containerColor = MaterialTheme.colorScheme.surfaceContainerHigh,
158+
containerColor = colorScheme.surfaceContainerHigh,
158159
selectedTabIndex = selectedTabIndex,
159160
indicator = { tabPositions ->
160161
SecondaryIndicator(
@@ -199,6 +200,7 @@ fun LazyListScope.AppearancePage(
199200
) {
200201
item {
201202
SettingsClickableEntry(
203+
modifier = Modifier.animateItem(),
202204
iconRes = R.drawable.format_paint_24px,
203205
title = stringResource(R.string.settings_theme_settings),
204206
description = stringResource(R.string.settings_theme_settings_desc),
@@ -207,6 +209,7 @@ fun LazyListScope.AppearancePage(
207209
}
208210
item {
209211
SettingsSwitchEntry(
212+
modifier = Modifier.animateItem(),
210213
iconRes = R.drawable.lightbulb_24px,
211214
title = stringResource(R.string.settings_reader_keep_screen_on),
212215
description = stringResource(R.string.settings_reader_keep_screen_on_desc),
@@ -216,6 +219,7 @@ fun LazyListScope.AppearancePage(
216219
}
217220
item {
218221
SettingsSwitchEntry(
222+
modifier = Modifier.animateItem(),
219223
iconRes = R.drawable.toolbar_24px,
220224
title = stringResource(R.string.settings_hide_status_bar),
221225
description = stringResource(R.string.settings_hide_status_bar_desc),
@@ -225,15 +229,28 @@ fun LazyListScope.AppearancePage(
225229
}
226230
item {
227231
SettingsSwitchEntry(
232+
modifier = Modifier.animateItem(),
228233
iconRes = R.drawable.translate_24px,
229234
title = stringResource(R.string.settings_trad_conversion),
230235
description = stringResource(R.string.settings_trad_conversion_desc),
231236
checked = settingState.enableSimplifiedTraditionalTransform,
232237
booleanUserData = settingState.enableSimplifiedTraditionalTransformUserData,
233238
)
234239
}
240+
item {
241+
SettingsMenuEntry(
242+
modifier = Modifier.animateItem(),
243+
iconRes = R.drawable.battery_android_full_24px,
244+
title = stringResource(R.string.settings_reader_battery_indicator),
245+
description = stringResource(R.string.settings_reader_battery_indicator_desc),
246+
options = MenuOptions.ReaderIndicatorBatteryDisplayMode,
247+
selectedOptionKey = settingState.batteryIndicatorDisplayMode,
248+
stringUserData = settingState.batteryIndicatorDisplayModeUserData
249+
)
250+
}
235251
item {
236252
SettingsSwitchEntry(
253+
modifier = Modifier.animateItem(),
237254
iconRes = R.drawable.outline_schedule_24px,
238255
title = stringResource(R.string.settings_reader_time_indicator),
239256
description = stringResource(R.string.settings_reader_time_indicator_desc),
@@ -243,6 +260,7 @@ fun LazyListScope.AppearancePage(
243260
}
244261
item {
245262
SettingsSwitchEntry(
263+
modifier = Modifier.animateItem(),
246264
iconRes = R.drawable.contract_24px,
247265
title = stringResource(R.string.settings_reader_chapter_indicator),
248266
description = stringResource(R.string.settings_reader_chapter_indicator_desc),
@@ -252,6 +270,7 @@ fun LazyListScope.AppearancePage(
252270
}
253271
item {
254272
SettingsSwitchEntry(
273+
modifier = Modifier.animateItem(),
255274
iconRes = R.drawable.clock_loader_40_24px,
256275
title = stringResource(R.string.settings_reader_progress_indicator),
257276
description = stringResource(R.string.settings_reader_progress_indicator_desc),
@@ -264,6 +283,7 @@ fun LazyListScope.AppearancePage(
264283
fun LazyListScope.ActionPage(settingState: SettingState) {
265284
item {
266285
SettingsSwitchEntry(
286+
modifier = Modifier.animateItem(),
267287
iconRes = R.drawable.menu_book_24px,
268288
title = stringResource(R.string.settings_reader_page_mode),
269289
description = stringResource(R.string.settings_reader_page_mode_desc),
@@ -337,6 +357,7 @@ fun LazyListScope.ActionPage(settingState: SettingState) {
337357
fun LazyListScope.PaddingPage(settingState: SettingState) {
338358
item {
339359
SettingsSwitchEntry(
360+
modifier = Modifier.animateItem(),
340361
title = stringResource(R.string.settings_reader_auto_margin),
341362
description = stringResource(R.string.settings_reader_auto_margin_desc),
342363
checked = settingState.autoPadding,
@@ -346,6 +367,7 @@ fun LazyListScope.PaddingPage(settingState: SettingState) {
346367
if (!settingState.autoPadding) {
347368
item {
348369
SettingsSliderEntry(
370+
modifier = Modifier.animateItem(),
349371
title = stringResource(R.string.settings_reader_top_margin),
350372
unit = "dp",
351373
valueRange = 0f..128f,
@@ -357,6 +379,7 @@ fun LazyListScope.PaddingPage(settingState: SettingState) {
357379
if (!settingState.autoPadding) {
358380
item {
359381
SettingsSliderEntry(
382+
modifier = Modifier.animateItem(),
360383
title = stringResource(R.string.settings_reader_bottom_margin),
361384
unit = "dp",
362385
valueRange = 0f..128f,
@@ -368,6 +391,7 @@ fun LazyListScope.PaddingPage(settingState: SettingState) {
368391
if (!settingState.autoPadding) {
369392
item {
370393
SettingsSliderEntry(
394+
modifier = Modifier.animateItem(),
371395
title = stringResource(R.string.settings_reader_left_margin),
372396
unit = "dp",
373397
valueRange = 0f..128f,
@@ -379,6 +403,7 @@ fun LazyListScope.PaddingPage(settingState: SettingState) {
379403
if (!settingState.autoPadding) {
380404
item {
381405
SettingsSliderEntry(
406+
modifier = Modifier.animateItem(),
382407
title = stringResource(R.string.settings_reader_right_margin),
383408
unit = "dp",
384409
valueRange = 0f..128f,

0 commit comments

Comments
 (0)