@@ -2,6 +2,8 @@ package indi.dmzz_yyhyy.lightnovelreader.ui.book.reader
22
33import android.annotation.SuppressLint
44import android.app.Activity
5+ import android.content.Context.BATTERY_SERVICE
6+ import android.os.BatteryManager
57import android.util.Log
68import android.view.View
79import android.view.WindowManager
@@ -26,6 +28,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
2628import androidx.compose.foundation.layout.height
2729import androidx.compose.foundation.layout.padding
2830import androidx.compose.foundation.layout.safeContent
31+ import androidx.compose.foundation.layout.size
2932import androidx.compose.foundation.layout.width
3033import androidx.compose.foundation.lazy.LazyColumn
3134import androidx.compose.foundation.lazy.LazyRow
@@ -36,7 +39,7 @@ import androidx.compose.material3.CircularProgressIndicator
3639import androidx.compose.material3.ExperimentalMaterial3Api
3740import androidx.compose.material3.Icon
3841import androidx.compose.material3.IconButton
39- import androidx.compose.material3.MaterialTheme
42+ import androidx.compose.material3.MaterialTheme.colorScheme
4043import androidx.compose.material3.ModalBottomSheet
4144import androidx.compose.material3.Scaffold
4245import 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
657672fun 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 }
0 commit comments