Skip to content

Commit

Permalink
Add Blur (Motion) in Player Style
Browse files Browse the repository at this point in the history
  • Loading branch information
Arturo254 committed Sep 22, 2024
1 parent f1e57c7 commit 73d48c7
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {
//noinspection OldTargetApi
targetSdk = 34
versionCode = 25
versionName = "1.2.0"
versionName = "1.3.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Binary file modified app/foss/release/baselineProfiles/0/app-foss-release.dm
Binary file not shown.
Binary file modified app/foss/release/baselineProfiles/1/app-foss-release.dm
Binary file not shown.
2 changes: 1 addition & 1 deletion app/foss/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"filters": [],
"attributes": [],
"versionCode": 25,
"versionName": "1.2.0",
"versionName": "1.3.0",
"outputFile": "app-foss-release.apk"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ enum class PlayerBackgroundStyle {
DEFAULT,
GRADIENT,
BLUR,
BLURMOV,

}

Expand Down
110 changes: 100 additions & 10 deletions app/src/main/java/com/malopieds/innertune/ui/player/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import android.text.format.Formatter
import android.widget.Toast
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.spring
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
Expand Down Expand Up @@ -72,6 +76,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.blur
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.draw.scale
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
Expand Down Expand Up @@ -225,6 +231,9 @@ fun BottomSheetPlayer(
if (useBlackBackground && playerBackground != PlayerBackgroundStyle.BLUR ) {
gradientColors = listOf(Color.Black, Color.Black)
}
if (useBlackBackground && playerBackground != PlayerBackgroundStyle.BLURMOV ) {
gradientColors = listOf(Color.Black, Color.Black)
}
else if (playerBackground == PlayerBackgroundStyle.GRADIENT) {
withContext(Dispatchers.IO) {
val result =
Expand Down Expand Up @@ -301,6 +310,19 @@ fun BottomSheetPlayer(
MaterialTheme.colorScheme.onSurface
}
}
when (playerBackground) {
PlayerBackgroundStyle.BLURMOV -> MaterialTheme.colorScheme.onBackground
else ->
if (gradientColors.size >= 3 &&
ColorUtils.calculateContrast(gradientColors.first().toArgb(), Color.White.toArgb()) < 1.5f
) {
changeColor = true
Color.Black
} else {
changeColor = false
MaterialTheme.colorScheme.onSurface
}
}



Expand Down Expand Up @@ -947,16 +969,24 @@ fun BottomSheetPlayer(
.fillMaxWidth()
.padding(horizontal = PlayerHorizontalPadding),
) {
// Box(modifier = Modifier.weight(1f)) {
// ResizableIconButton(
// icon = if (currentSong?.song?.liked == true) R.drawable.favorite else R.drawable.favorite_border,
// color = if (currentSong?.song?.liked == true) MaterialTheme.colorScheme.error else onBackgroundColor,
// modifier =
// Modifier
// .size(32.dp)
// .padding(4.dp)
// .align(Alignment.Center),
// onClick = playerConnection::toggleLike,
// )
// }
// button to toggle like
Box(modifier = Modifier.weight(1f)) {
ResizableIconButton(
icon = if (currentSong?.song?.liked == true) R.drawable.favorite else R.drawable.favorite_border,
color = if (currentSong?.song?.liked == true) MaterialTheme.colorScheme.error else onBackgroundColor,
modifier =
Modifier
.size(32.dp)
.padding(4.dp)
.align(Alignment.Center),
onClick = playerConnection::toggleLike,
LikeButton(
isLiked = currentSong?.song?.liked == true,
onLikeClick = playerConnection::toggleLike,
color = if (currentSong?.song?.liked == true) MaterialTheme.colorScheme.error else onBackgroundColor
)
}

Expand Down Expand Up @@ -1070,8 +1100,39 @@ fun BottomSheetPlayer(
.blur(200.dp)
.alpha(0.8f)
.background(if (useBlackBackground) Color.Black.copy(alpha = 0.5f) else Color.Transparent)

)
}
else if (playerBackground == PlayerBackgroundStyle.BLURMOV) {
val infiniteTransition = rememberInfiniteTransition(label = "")


val rotation by infiniteTransition.animateFloat(
initialValue = 0f,
targetValue = 360f,
animationSpec = infiniteRepeatable(
animation = tween(
durationMillis = 100000,
easing = FastOutSlowInEasing // Easing suave
),
repeatMode = RepeatMode.Restart
), label = ""
)
AsyncImage(
model = mediaMetadata?.thumbnailUrl,
contentDescription = null,
contentScale = ContentScale.FillBounds,
modifier = Modifier
.fillMaxSize()
.blur(200.dp)
.alpha(0.8f)
.background(if (useBlackBackground) Color.Black.copy(alpha = 0.5f) else Color.Transparent)
.rotate(rotation)

)
} else if (useBlackBackground && playerBackground == PlayerBackgroundStyle.DEFAULT) {
}

else if (useBlackBackground && playerBackground == PlayerBackgroundStyle.DEFAULT) {
Box(
modifier = Modifier
.fillMaxSize()
Expand Down Expand Up @@ -1162,3 +1223,32 @@ fun BottomSheetPlayer(
}
}


@Composable
fun LikeButton(
isLiked: Boolean,
onLikeClick: () -> Unit,
color: Color
) {
var isLikedState by remember { mutableStateOf(isLiked) }
val scale by animateFloatAsState(
targetValue = if (isLikedState) 1.2f else 1f,
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow
), label = ""
)

ResizableIconButton(
icon = if (isLikedState) R.drawable.favorite else R.drawable.favorite_border,
color = color,
modifier = Modifier
.size(32.dp)
.padding(4.dp)
.scale(scale),
onClick = {
isLikedState = !isLikedState
onLikeClick()
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ fun AppearanceSettings(
when (style) {
PlayerBackgroundStyle.DEFAULT -> stringResource(R.string.follow_theme)
PlayerBackgroundStyle.GRADIENT -> stringResource(R.string.gradient)
PlayerBackgroundStyle.BLURMOV -> if (isBlurSupported) {
stringResource(R.string.blurmv)
} else {
stringResource(R.string.blur_not_supported)
}
PlayerBackgroundStyle.BLUR -> if (isBlurSupported) {
stringResource(R.string.blur)
} else {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,5 @@
<string name="internet_required">It looks like you have no Internet connection. Please check your network.</string>
<string name="downloadspage">Go to downloads</string>
<string name="blur_not_supported">Blur not supported</string>
<string name="blurmv">Blur (Motion)</string>
</resources>

0 comments on commit 73d48c7

Please sign in to comment.