From 24d881f2e0f225b7a41d37ed999b94515e637913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Font=C3=A1n?= Date: Sun, 5 May 2024 23:12:48 +0200 Subject: [PATCH] chore: Updated Media3 to the latest alpha ui: Added a "no songs" screen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gabriel Fontán --- .../presentation/pages/MediaStorePage.kt | 103 ++++++++++-------- .../pages/status/EmptyMediaStore.kt | 75 +++++++++++++ app/src/main/res/values-es/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + .../mediastore/MediaStoreReceiver.kt | 3 +- gradle.properties | 3 +- gradle/libs.versions.toml | 2 +- 7 files changed, 139 insertions(+), 51 deletions(-) create mode 100644 app/src/main/java/com/bobbyesp/metadator/presentation/pages/status/EmptyMediaStore.kt diff --git a/app/src/main/java/com/bobbyesp/metadator/presentation/pages/MediaStorePage.kt b/app/src/main/java/com/bobbyesp/metadator/presentation/pages/MediaStorePage.kt index 1e01591..23538ce 100644 --- a/app/src/main/java/com/bobbyesp/metadator/presentation/pages/MediaStorePage.kt +++ b/app/src/main/java/com/bobbyesp/metadator/presentation/pages/MediaStorePage.kt @@ -20,6 +20,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.bobbyesp.metadator.presentation.components.cards.songs.HorizontalSongCard import com.bobbyesp.metadator.presentation.components.cards.songs.VerticalSongCard import com.bobbyesp.metadator.presentation.pages.home.LayoutType +import com.bobbyesp.metadator.presentation.pages.status.EmptyMediaStore import com.bobbyesp.model.Song import my.nanihadesuka.compose.LazyColumnScrollbar import my.nanihadesuka.compose.LazyGridVerticalScrollbar @@ -42,60 +43,66 @@ fun MediaStorePage( Crossfade( targetState = desiredLayout, label = "List item transition", animationSpec = tween(200) ) { type -> - when (type) { - LayoutType.Grid -> { - LazyGridVerticalScrollbar( - state = lazyGridState, - thumbColor = MaterialTheme.colorScheme.onSurfaceVariant, - thumbSelectedColor = MaterialTheme.colorScheme.primary, - selectionActionable = ScrollbarSelectionActionable.WhenVisible, - ) { - LazyVerticalGrid( - columns = GridCells.Adaptive(125.dp), - verticalArrangement = Arrangement.spacedBy(6.dp), - horizontalArrangement = Arrangement.spacedBy(6.dp), - contentPadding = PaddingValues(8.dp), - modifier = Modifier - .fillMaxSize() - .background(MaterialTheme.colorScheme.background), - state = lazyGridState + if (songs.isEmpty()) { + EmptyMediaStore( + modifier = Modifier.fillMaxSize() + ) + } else { + when (type) { + LayoutType.Grid -> { + LazyGridVerticalScrollbar( + state = lazyGridState, + thumbColor = MaterialTheme.colorScheme.onSurfaceVariant, + thumbSelectedColor = MaterialTheme.colorScheme.primary, + selectionActionable = ScrollbarSelectionActionable.WhenVisible, ) { - items(count = songs.size, - key = { index -> songs[index].id }, - contentType = { index -> songs[index].id.toString() }) { index -> - val song = songs[index] - VerticalSongCard(song = song, modifier = Modifier.animateItem( - fadeInSpec = null, fadeOutSpec = null - ), onClick = { - onItemClicked(song) - }) + LazyVerticalGrid( + columns = GridCells.Adaptive(125.dp), + verticalArrangement = Arrangement.spacedBy(6.dp), + horizontalArrangement = Arrangement.spacedBy(6.dp), + contentPadding = PaddingValues(8.dp), + modifier = Modifier + .fillMaxSize() + .background(MaterialTheme.colorScheme.background), + state = lazyGridState + ) { + items(count = songs.size, + key = { index -> songs[index].id }, + contentType = { index -> songs[index].id.toString() }) { index -> + val song = songs[index] + VerticalSongCard(song = song, modifier = Modifier.animateItem( + fadeInSpec = null, fadeOutSpec = null + ), onClick = { + onItemClicked(song) + }) + } } } } - } - LayoutType.List -> { - LazyColumnScrollbar( - listState = lazyListState, - thumbColor = MaterialTheme.colorScheme.onSurfaceVariant, - thumbSelectedColor = MaterialTheme.colorScheme.primary, - selectionActionable = ScrollbarSelectionActionable.WhenVisible, - ) { - LazyColumn( - modifier = Modifier - .fillMaxSize() - .background(MaterialTheme.colorScheme.background), - state = lazyListState, + LayoutType.List -> { + LazyColumnScrollbar( + listState = lazyListState, + thumbColor = MaterialTheme.colorScheme.onSurfaceVariant, + thumbSelectedColor = MaterialTheme.colorScheme.primary, + selectionActionable = ScrollbarSelectionActionable.WhenVisible, ) { - items(count = songs.size, - key = { index -> songs[index].id }, - contentType = { index -> songs[index].id.toString() }) { index -> - val song = songs[index] - HorizontalSongCard(song = song, modifier = Modifier.animateItem( - fadeInSpec = null, fadeOutSpec = null - ), onClick = { - onItemClicked(song) - }) + LazyColumn( + modifier = Modifier + .fillMaxSize() + .background(MaterialTheme.colorScheme.background), + state = lazyListState, + ) { + items(count = songs.size, + key = { index -> songs[index].id }, + contentType = { index -> songs[index].id.toString() }) { index -> + val song = songs[index] + HorizontalSongCard(song = song, modifier = Modifier.animateItem( + fadeInSpec = null, fadeOutSpec = null + ), onClick = { + onItemClicked(song) + }) + } } } } diff --git a/app/src/main/java/com/bobbyesp/metadator/presentation/pages/status/EmptyMediaStore.kt b/app/src/main/java/com/bobbyesp/metadator/presentation/pages/status/EmptyMediaStore.kt new file mode 100644 index 0000000..f9a4657 --- /dev/null +++ b/app/src/main/java/com/bobbyesp/metadator/presentation/pages/status/EmptyMediaStore.kt @@ -0,0 +1,75 @@ +package com.bobbyesp.metadator.presentation.pages.status + +import android.content.res.Configuration.UI_MODE_NIGHT_YES +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.twotone.LibraryMusic +import androidx.compose.material3.HorizontalDivider +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.bobbyesp.metadator.R +import com.bobbyesp.metadator.presentation.theme.MetadatorTheme + +@Composable +fun EmptyMediaStore( + modifier: Modifier = Modifier +) { + Box( + modifier = modifier, + contentAlignment = Alignment.Center + ) { + Column( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp), + verticalArrangement = Arrangement.spacedBy(8.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + Icon( + modifier = Modifier.size(72.dp), + imageVector = Icons.TwoTone.LibraryMusic, + contentDescription = stringResource(id = R.string.empty_media_store) + ) + HorizontalDivider(modifier = Modifier.fillMaxWidth(0.7f)) + Text( + text = stringResource(id = R.string.empty_media_store), + style = MaterialTheme.typography.bodyLarge, + fontWeight = FontWeight.SemiBold + ) + Text( + text = stringResource(id = R.string.empty_media_store_desc), + style = MaterialTheme.typography.bodyMedium, + textAlign = TextAlign.Center + ) + } + } +} + +@Preview +@Preview(uiMode = UI_MODE_NIGHT_YES) +@Composable +private fun EmptyMediaStorePrev() { + MetadatorTheme { + EmptyMediaStore( + modifier = Modifier + .fillMaxSize() + .background(MaterialTheme.colorScheme.background) + ) + } +} \ No newline at end of file diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 0173048..61d0bc8 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -54,4 +54,6 @@ Cola de música Alternar modo aleatorio Alternar modo de repetición + MediaStore vacío + Parece que no tienes canciones en tu dispositivo. Vuelve cuando tengas algo que editar! \ 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 54adea6..61f0ce9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -53,5 +53,7 @@ Music queue Toggle shuffle Toggle repeat + Empty MediaStore + Seems like you have no songs on your device. Come back when there\'s something to edit! \ No newline at end of file diff --git a/app/utilities/src/main/java/com/bobbyesp/utilities/mediastore/MediaStoreReceiver.kt b/app/utilities/src/main/java/com/bobbyesp/utilities/mediastore/MediaStoreReceiver.kt index e067ab9..b9236a9 100644 --- a/app/utilities/src/main/java/com/bobbyesp/utilities/mediastore/MediaStoreReceiver.kt +++ b/app/utilities/src/main/java/com/bobbyesp/utilities/mediastore/MediaStoreReceiver.kt @@ -227,9 +227,10 @@ object MediaStoreReceiver { } fun ContentResolver.observeSongs( + searchTerm: String? = null, filter: MediaStoreFilterType? = null, ) = observe(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI).map { - getSongs(filterType = filter) + getSongs(filterType = filter, searchTerm = searchTerm) } } } diff --git a/gradle.properties b/gradle.properties index 20e4cc3..36b0127 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,4 +21,5 @@ kotlin.code.style=official # resources declared in the library itself and none from the library's dependencies, # thereby reducing the size of the R class for that library android.nonTransitiveRClass=true -android.defaultConfig.ndk.debugSymbolLevel='FULL' \ No newline at end of file +android.defaultConfig.ndk.debugSymbolLevel='FULL' +org.gradle.configuration-cache=true \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a9d10d2..e068779 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -14,7 +14,7 @@ ksp = "1.9.23-1.0.19" lyricfier = "1.0" splashscreen = "1.0.1" material = "1.11.0" -media3 = "1.3.1" +media3 = "1.4.0-alpha01" leakcanary = "2.13" #Compose