Skip to content

Commit

Permalink
ui: Disable certain effects in power saver mode
Browse files Browse the repository at this point in the history
* Blur/gradient and playing animation
  • Loading branch information
mikooomich committed Oct 13, 2024
1 parent 7068b73 commit 798e836
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion app/src/main/java/com/dd3boh/outertune/ui/component/Items.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.dd3boh.outertune.ui.component

import android.content.Context
import android.os.PowerManager
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.tween
import androidx.compose.animation.expandIn
Expand Down Expand Up @@ -59,6 +61,7 @@ import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
Expand Down Expand Up @@ -1092,6 +1095,9 @@ fun ItemThumbnail(
modifier: Modifier = Modifier,
albumIndex: Int? = null,
) {
// ehhhh make a nicer thing for later
val context = LocalContext.current

Box(
contentAlignment = Alignment.Center,
modifier = modifier
Expand Down Expand Up @@ -1128,7 +1134,7 @@ fun ItemThumbnail(
}

PlayingIndicatorBox(
isActive = isActive,
isActive = isActive && !(context.getSystemService(Context.POWER_SERVICE) as PowerManager).isPowerSaveMode,
playWhenReady = isPlaying,
color = if (albumIndex != null) MaterialTheme.colorScheme.onBackground else Color.White,
modifier = Modifier
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/dd3boh/outertune/ui/player/Player.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.dd3boh.outertune.ui.player

import android.content.Context
import android.content.res.Configuration
import android.graphics.drawable.BitmapDrawable
import android.text.format.Formatter
import android.widget.Toast
import android.os.PowerManager
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.animateDpAsState
Expand Down Expand Up @@ -188,8 +190,12 @@ fun BottomSheetPlayer(
mutableStateOf<List<Color>>(emptyList())
}

val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager


// gradient colours
LaunchedEffect(mediaMetadata) {
if (playerBackground != PlayerBackgroundStyle.GRADIENT) return@LaunchedEffect
if (playerBackground != PlayerBackgroundStyle.GRADIENT || powerManager.isPowerSaveMode) return@LaunchedEffect

withContext(Dispatchers.IO) {
if (mediaMetadata?.isLocal == true) {
Expand Down Expand Up @@ -567,7 +573,7 @@ fun BottomSheetPlayer(
}

AnimatedVisibility(
visible = state.isExpanded,
visible = !powerManager.isPowerSaveMode && state.isExpanded,
enter = fadeIn(tween(1000)),
exit = fadeOut()
) {
Expand Down

0 comments on commit 798e836

Please sign in to comment.