Skip to content

Commit

Permalink
feat: Added reduce shadows setting. Added a new setting to reduce sha…
Browse files Browse the repository at this point in the history
…dows drawn by the app to improve performance.

- Added a new preference key `REDUCE_SHADOWS` with a default value of `false`.
- Added a new switch in the General settings page to control the setting.
- Modified `CompactSongCard` to conditionally apply shadows based on the setting.
- Updated translations for the new setting.
  • Loading branch information
BobbyESP committed Dec 18, 2024
1 parent e8479d5 commit d79860a
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 62 deletions.
7 changes: 3 additions & 4 deletions app/src/main/java/com/bobbyesp/metadator/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ import com.bobbyesp.metadator.di.mediaplayerViewModels
import com.bobbyesp.metadator.di.utilitiesViewModels
import com.bobbyesp.metadator.features.spotify.di.spotifyMainModule
import com.bobbyesp.metadator.features.spotify.di.spotifyServicesModule
import com.bobbyesp.metadator.util.preferences.BooleanPreferenceDefaults
import com.bobbyesp.metadator.util.preferences.IntPreferenceDefaults
import com.bobbyesp.metadator.util.preferences.PreferencesKeys
import com.bobbyesp.metadator.util.preferences.StringPreferenceDefaults
import com.bobbyesp.metadator.util.preferences.PreferencesKeys.BooleanPreferenceDefaults
import com.bobbyesp.metadator.util.preferences.PreferencesKeys.IntPreferenceDefaults
import com.bobbyesp.metadator.util.preferences.PreferencesKeys.StringPreferenceDefaults
import com.bobbyesp.utilities.Preferences
import com.tencent.mmkv.MMKV
import mediaplayerInternalsModule
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.GlobalContext.startKoin
import org.koin.dsl.module
import kotlin.properties.Delegates

class App : Application() {
Expand Down
8 changes: 1 addition & 7 deletions app/src/main/java/com/bobbyesp/metadator/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@ import com.bobbyesp.mediaplayer.service.MediaplayerService
import com.bobbyesp.metadator.presentation.Navigator
import com.bobbyesp.metadator.presentation.common.AppLocalSettingsProvider
import com.bobbyesp.metadator.presentation.theme.MetadatorTheme
import com.bobbyesp.metadator.util.preferences.BooleanPreferenceDefaults
import com.bobbyesp.metadator.util.preferences.CoreSettings
import com.bobbyesp.metadator.util.preferences.IntPreferenceDefaults
import com.bobbyesp.metadator.util.preferences.PreferencesKeys
import com.bobbyesp.metadator.util.preferences.StringPreferenceDefaults
import com.bobbyesp.utilities.Preferences
import org.koin.android.ext.android.inject
import org.koin.compose.KoinContext
import org.koin.core.component.KoinComponent
import setCrashlyticsCollection
import kotlin.getValue

@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
class MainActivity : ComponentActivity(), KoinComponent {
Expand All @@ -43,7 +37,7 @@ class MainActivity : ComponentActivity(), KoinComponent {
AppLocalSettingsProvider(
windowWidthSize = windowSizeClass.widthSizeClass,
playerConnectionHandler = connectionHandler,
coreSettings = CoreSettings(App.preferences.kv)
coreSettings = CoreSettings.initialize(App.preferences.kv)
) {
MetadatorTheme {
Navigator()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.bobbyesp.metadator.presentation.components.cards.songs.compact

import android.net.Uri
import android.util.Log
import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
Expand All @@ -14,7 +12,6 @@ import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -32,6 +29,8 @@ import androidx.compose.ui.unit.dp
import com.bobbyesp.metadator.presentation.components.cards.songs.compact.CompactCardSize.Companion.toShape
import com.bobbyesp.metadator.presentation.components.image.AsyncImage
import com.bobbyesp.metadator.presentation.components.text.ConditionedMarqueeText
import com.bobbyesp.metadator.util.preferences.PreferencesKeys.REDUCE_SHADOWS
import com.bobbyesp.metadator.util.preferences.booleanState

@Composable
fun CompactSongCard(
Expand All @@ -45,6 +44,8 @@ fun CompactSongCard(
shape: Shape? = MaterialTheme.shapes.large,
onClick: () -> Unit
) {
val reduceShadows = REDUCE_SHADOWS.booleanState

val cardSize by remember(size) {
mutableStateOf(size.value)
}
Expand All @@ -53,9 +54,10 @@ fun CompactSongCard(

Box(
modifier = modifier
.shadow(
elevation = shadow ?: 0.dp,
shape = formalizedShape
.then(
if (reduceShadows.value) Modifier else Modifier.shadow(
elevation = shadow ?: 0.dp, shape = formalizedShape
)
)
.clip(formalizedShape)
.size(cardSize)
Expand All @@ -80,16 +82,14 @@ fun CompactSongCard(
}
Column(
modifier = Modifier
.background(
brush = Brush.verticalGradient(
colors = listOf(
Color.Transparent,
MaterialTheme.colorScheme.scrim
),
startY = 0f,
endY = 500f
),
alpha = 0.6f
.then(
if (reduceShadows.value) Modifier else Modifier.background(
brush = Brush.verticalGradient(
colors = listOf(
Color.Transparent, MaterialTheme.colorScheme.scrim
), startY = 0f, endY = 500f
), alpha = 0.6f
)
)
.fillMaxSize()
.padding(horizontal = 8.dp, vertical = 6.dp),
Expand All @@ -104,7 +104,7 @@ fun CompactSongCard(
maxLines = 1
)

if(artists.isNotEmpty()) {
if (artists.isNotEmpty()) {
ConditionedMarqueeText(
text = artists,
style = MaterialTheme.typography.bodySmall,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ fun SettingsPage(
}
)
}
item {
SettingItem(
title = stringResource(id = R.string.appearance),
description = stringResource(id = R.string.appearance_description),
icon = Icons.Rounded.Palette,
onClick = {
navController.navigate(Route.SettingsNavigator.Settings.Appearance)
}
)
}
// item { TODO: Implement this
// SettingItem(
// title = stringResource(id = R.string.appearance),
// description = stringResource(id = R.string.appearance_description),
// icon = Icons.Rounded.Palette,
// onClick = {
// navController.navigate(Route.SettingsNavigator.Settings.Appearance)
// }
// )
// }
item {
HorizontalDivider(modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp))
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.bobbyesp.metadator.App.Companion.preferences
import com.bobbyesp.metadator.R
import com.bobbyesp.metadator.presentation.common.LocalNavController
import com.bobbyesp.metadator.util.preferences.PreferencesKeys.MARQUEE_TEXT
import com.bobbyesp.metadator.util.preferences.PreferencesKeys.REDUCE_SHADOWS
import com.bobbyesp.metadator.util.preferences.booleanState
import com.bobbyesp.ui.components.button.BackButton
import com.bobbyesp.ui.components.preferences.PreferenceSwitch
Expand All @@ -25,6 +26,7 @@ import com.bobbyesp.ui.components.preferences.PreferenceSwitch
@Composable
fun GeneralSettingsPage() {
val useMarqueeText = MARQUEE_TEXT.booleanState
val reduceShadows = REDUCE_SHADOWS.booleanState

val navController = LocalNavController.current
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(
Expand Down Expand Up @@ -70,6 +72,17 @@ fun GeneralSettingsPage() {
}
)
}
item {
PreferenceSwitch(
title = stringResource(R.string.reduce_shadows),
description = stringResource(R.string.reduce_shadows_description),
isChecked = reduceShadows.value,
onClick = {
reduceShadows.value = !reduceShadows.value
preferences.updateValue(REDUCE_SHADOWS, reduceShadows.value)
}
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.bobbyesp.metadator.util.preferences

import com.bobbyesp.metadator.util.preferences.PreferencesKeys.DARK_THEME_VALUE
import com.bobbyesp.metadator.util.preferences.PreferencesKeys.MARQUEE_TEXT
import com.bobbyesp.metadator.util.preferences.PreferencesKeys.SONG_CARD_SIZE
import com.bobbyesp.metadator.util.theme.DarkThemePreference

object PreferencesKeys {
//------------GENERAL--------------
const val DESIRED_LAYOUT = "desired_overlay"
const val SONG_CARD_SIZE = "song_card_size"
const val MARQUEE_TEXT = "marquee_text"
const val REDUCE_SHADOWS = "reduce_shadows"

//------------THEME----------------
const val DARK_THEME_VALUE = "dark_theme_value"
Expand All @@ -19,18 +17,19 @@ object PreferencesKeys {
const val DYNAMIC_COLOR = "dynamic_color"

const val MMKV_PREFERENCES_NAME = "metadator_preferences"
}

val StringPreferenceDefaults: Map<String, String> =
mapOf()
val StringPreferenceDefaults: Map<String, String> =
mapOf()

val BooleanPreferenceDefaults: Map<String, Boolean> =
mapOf(
MARQUEE_TEXT to true
)
val BooleanPreferenceDefaults: Map<String, Boolean> =
mapOf(
MARQUEE_TEXT to true,
REDUCE_SHADOWS to false
)

val IntPreferenceDefaults: Map<String, Int> =
mapOf(
DARK_THEME_VALUE to DarkThemePreference.FOLLOW_SYSTEM,
SONG_CARD_SIZE to 2 //CompactCardSize.LARGE
)
val IntPreferenceDefaults: Map<String, Int> =
mapOf(
DARK_THEME_VALUE to DarkThemePreference.FOLLOW_SYSTEM,
SONG_CARD_SIZE to 2 //CompactCardSize.LARGE
)
}
12 changes: 6 additions & 6 deletions app/src/main/java/com/bobbyesp/metadator/util/theme/Theme.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bobbyesp.metadator.util.theme

import com.bobbyesp.metadator.util.preferences.CoreSettings
import com.bobbyesp.metadator.util.preferences.CoreSettings.Companion.appMainSettingsStateFlow
import com.bobbyesp.metadator.util.preferences.CoreSettings.Companion.mutableAppMainSettingsStateFlow
import com.bobbyesp.metadator.util.preferences.PreferencesKeys.DARK_THEME_VALUE
import com.bobbyesp.metadator.util.preferences.PreferencesKeys.DYNAMIC_COLOR
import com.bobbyesp.metadator.util.preferences.PreferencesKeys.HIGH_CONTRAST
Expand All @@ -13,10 +14,9 @@ import kotlinx.coroutines.launch

class AppTheme(
private val kv: MMKV,
private val coreSettings: CoreSettings,
private val scope: CoroutineScope
) {
private val appSettingsFlow = coreSettings.appMainSettingsStateFlow.value
private val appSettingsFlow = appMainSettingsStateFlow.value

private val theme = appSettingsFlow.darkTheme

Expand All @@ -25,7 +25,7 @@ class AppTheme(
highContrast: Boolean = theme.isHighContrastModeEnabled
) {
scope.launch(Dispatchers.IO) {
coreSettings.mutableAppMainSettingsStateFlow.update {
mutableAppMainSettingsStateFlow.update {
it.copy(
darkTheme = it.darkTheme.copy(
darkThemeValue = darkTheme,
Expand All @@ -41,7 +41,7 @@ class AppTheme(

fun modifySeedColor(argbColor: Int) {
scope.launch(Dispatchers.IO) {
coreSettings.mutableAppMainSettingsStateFlow.update {
mutableAppMainSettingsStateFlow.update {
it.copy(seedColor = argbColor)
}

Expand All @@ -51,7 +51,7 @@ class AppTheme(

fun switchDynamicColoring(enabled: Boolean = !appSettingsFlow.useDynamicColoring) {
scope.launch(Dispatchers.IO) {
coreSettings.mutableAppMainSettingsStateFlow.update {
mutableAppMainSettingsStateFlow.update {
it.copy(useDynamicColoring = enabled)
}
}
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,16 @@
<string name="general">General</string>
<string name="general_description">Algunos ajustes principales de la aplicación</string>
<string name="marquee_text">Texto en movimiento</string>
<string name="marquee_text_description">El texto que sobrepase los límites de la pantalla tienen una animación en lateral para que se vea todo su contenido (esto puede empeorar el rendimiento de la aplicación).</string>
<string name="marquee_text_description">Añadir una animación lateral al texto que se desborda para mostrar su contenido completo. Esto podría afectar el rendimiento de la aplicación.</string>
<string name="lyrics">Letras</string>
<string name="retrieving_spotify_token">Obteniendo credenciales de la API de Spotify…</string>
<string name="by">por</string>
<string name="edit_query">Editar búsqueda</string>
<string name="retrieve_lyrics">Obtener letras</string>
<string name="lyrics_retrieve_cancelled">El proceso de búsqueda de letras ha sido cancelado</string>
<string name="empty_lyrics_received">Las letras enviadas por la aplicación proveedora eran nulas o estaban vacías</string>
<string name="something_unexpected_occurred">Ha ocurrido algo inesperado!</string>
<string name="card_size">Tamaño de tarjeta</string>
<string name="reduce_shadows">Reducir sombras</string>
<string name="reduce_shadows_description">Reduce las sombras dibujadas por la app para mejorar el rendimiento.</string>
</resources>
6 changes: 4 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,16 @@
<string name="general">General</string>
<string name="general_description">Some main settings of the app</string>
<string name="marquee_text">Marquee text</string>
<string name="marquee_text_description">The text that overflows the limits of the screen has a lateral animation to show its entire content (this may worsen the app performance).</string>
<string name="marquee_text_description">Add a lateral animation to show an entire text when overflowing the screen. This may worsen the app performance.</string>
<string name="lyrics">Lyrics</string>
<string name="retrieving_spotify_token">Retrieving Spotify API token…</string>
<string name="by">by</string>
<string name="edit_query">Edit query</string>
<string name="retrieve_lyrics">Retrieve lyrics</string>
<string name="lyrics_retrieve_cancelled">The lyrics retrievement process has been cancelled</string>
<string name="lyrics_retrieve_cancelled">The lyrics retrieve process has been cancelled</string>
<string name="empty_lyrics_received">The lyrics sent from the provider app were null or empty</string>
<string name="something_unexpected_occurred">Something unexpected occurred!</string>
<string name="card_size">Card size</string>
<string name="reduce_shadows">Reduce shadows</string>
<string name="reduce_shadows_description">Reduce the shadows drawn by the app to improve performance.</string>
</resources>

0 comments on commit d79860a

Please sign in to comment.