From d79860a24b8f4f29415ebbbde9834a503640e30d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Font=C3=A1n?= Date: Wed, 18 Dec 2024 21:31:07 +0100 Subject: [PATCH] feat: Added reduce shadows setting. Added a new setting to reduce shadows 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. --- .../main/java/com/bobbyesp/metadator/App.kt | 7 ++-- .../com/bobbyesp/metadator/MainActivity.kt | 8 +---- .../cards/songs/compact/CompactSongCard.kt | 34 +++++++++---------- .../pages/settings/SettingsPage.kt | 20 +++++------ .../settings/modules/GeneralSettingsPage.kt | 13 +++++++ .../util/preferences/PreferencesKeys.kt | 29 ++++++++-------- .../bobbyesp/metadator/util/theme/Theme.kt | 12 +++---- app/src/main/res/values-es/strings.xml | 11 +++++- app/src/main/res/values/strings.xml | 6 ++-- 9 files changed, 78 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/com/bobbyesp/metadator/App.kt b/app/src/main/java/com/bobbyesp/metadator/App.kt index f263f96..4fbf493 100644 --- a/app/src/main/java/com/bobbyesp/metadator/App.kt +++ b/app/src/main/java/com/bobbyesp/metadator/App.kt @@ -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() { diff --git a/app/src/main/java/com/bobbyesp/metadator/MainActivity.kt b/app/src/main/java/com/bobbyesp/metadator/MainActivity.kt index cc977f8..957442f 100644 --- a/app/src/main/java/com/bobbyesp/metadator/MainActivity.kt +++ b/app/src/main/java/com/bobbyesp/metadator/MainActivity.kt @@ -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 { @@ -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() diff --git a/app/src/main/java/com/bobbyesp/metadator/presentation/components/cards/songs/compact/CompactSongCard.kt b/app/src/main/java/com/bobbyesp/metadator/presentation/components/cards/songs/compact/CompactSongCard.kt index 47eb27b..7604c94 100644 --- a/app/src/main/java/com/bobbyesp/metadator/presentation/components/cards/songs/compact/CompactSongCard.kt +++ b/app/src/main/java/com/bobbyesp/metadator/presentation/components/cards/songs/compact/CompactSongCard.kt @@ -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 @@ -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 @@ -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( @@ -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) } @@ -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) @@ -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), @@ -104,7 +104,7 @@ fun CompactSongCard( maxLines = 1 ) - if(artists.isNotEmpty()) { + if (artists.isNotEmpty()) { ConditionedMarqueeText( text = artists, style = MaterialTheme.typography.bodySmall, diff --git a/app/src/main/java/com/bobbyesp/metadator/presentation/pages/settings/SettingsPage.kt b/app/src/main/java/com/bobbyesp/metadator/presentation/pages/settings/SettingsPage.kt index 5f1d884..2961c91 100644 --- a/app/src/main/java/com/bobbyesp/metadator/presentation/pages/settings/SettingsPage.kt +++ b/app/src/main/java/com/bobbyesp/metadator/presentation/pages/settings/SettingsPage.kt @@ -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( diff --git a/app/src/main/java/com/bobbyesp/metadator/presentation/pages/settings/modules/GeneralSettingsPage.kt b/app/src/main/java/com/bobbyesp/metadator/presentation/pages/settings/modules/GeneralSettingsPage.kt index 676ace3..f98b484 100644 --- a/app/src/main/java/com/bobbyesp/metadator/presentation/pages/settings/modules/GeneralSettingsPage.kt +++ b/app/src/main/java/com/bobbyesp/metadator/presentation/pages/settings/modules/GeneralSettingsPage.kt @@ -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 @@ -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( @@ -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) + } + ) + } } } } \ No newline at end of file diff --git a/app/src/main/java/com/bobbyesp/metadator/util/preferences/PreferencesKeys.kt b/app/src/main/java/com/bobbyesp/metadator/util/preferences/PreferencesKeys.kt index ff96e1d..7797a9f 100644 --- a/app/src/main/java/com/bobbyesp/metadator/util/preferences/PreferencesKeys.kt +++ b/app/src/main/java/com/bobbyesp/metadator/util/preferences/PreferencesKeys.kt @@ -1,8 +1,5 @@ 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 { @@ -10,6 +7,7 @@ object PreferencesKeys { 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" @@ -19,18 +17,19 @@ object PreferencesKeys { const val DYNAMIC_COLOR = "dynamic_color" const val MMKV_PREFERENCES_NAME = "metadator_preferences" -} -val StringPreferenceDefaults: Map = - mapOf() + val StringPreferenceDefaults: Map = + mapOf() -val BooleanPreferenceDefaults: Map = - mapOf( - MARQUEE_TEXT to true - ) + val BooleanPreferenceDefaults: Map = + mapOf( + MARQUEE_TEXT to true, + REDUCE_SHADOWS to false + ) -val IntPreferenceDefaults: Map = - mapOf( - DARK_THEME_VALUE to DarkThemePreference.FOLLOW_SYSTEM, - SONG_CARD_SIZE to 2 //CompactCardSize.LARGE - ) \ No newline at end of file + val IntPreferenceDefaults: Map = + mapOf( + DARK_THEME_VALUE to DarkThemePreference.FOLLOW_SYSTEM, + SONG_CARD_SIZE to 2 //CompactCardSize.LARGE + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/bobbyesp/metadator/util/theme/Theme.kt b/app/src/main/java/com/bobbyesp/metadator/util/theme/Theme.kt index 9172e96..11ee951 100644 --- a/app/src/main/java/com/bobbyesp/metadator/util/theme/Theme.kt +++ b/app/src/main/java/com/bobbyesp/metadator/util/theme/Theme.kt @@ -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 @@ -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 @@ -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, @@ -41,7 +41,7 @@ class AppTheme( fun modifySeedColor(argbColor: Int) { scope.launch(Dispatchers.IO) { - coreSettings.mutableAppMainSettingsStateFlow.update { + mutableAppMainSettingsStateFlow.update { it.copy(seedColor = argbColor) } @@ -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) } } diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 4797095..a5f6921 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -73,7 +73,16 @@ General Algunos ajustes principales de la aplicación Texto en movimiento - 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). + 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. Letras Obteniendo credenciales de la API de Spotify… + por + Editar búsqueda + Obtener letras + El proceso de búsqueda de letras ha sido cancelado + Las letras enviadas por la aplicación proveedora eran nulas o estaban vacías + Ha ocurrido algo inesperado! + Tamaño de tarjeta + Reducir sombras + Reduce las sombras dibujadas por la app para mejorar el rendimiento. \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a221df9..c8a905a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -72,14 +72,16 @@ General Some main settings of the app Marquee text - The text that overflows the limits of the screen has a lateral animation to show its entire content (this may worsen the app performance). + Add a lateral animation to show an entire text when overflowing the screen. This may worsen the app performance. Lyrics Retrieving Spotify API token… by Edit query Retrieve lyrics - The lyrics retrievement process has been cancelled + The lyrics retrieve process has been cancelled The lyrics sent from the provider app were null or empty Something unexpected occurred! Card size + Reduce shadows + Reduce the shadows drawn by the app to improve performance. \ No newline at end of file