Skip to content

Commit

Permalink
chore: Updated Media3 to the latest alpha
Browse files Browse the repository at this point in the history
ui: Added a "no songs" screen

Signed-off-by: Gabriel Fontán <[email protected]>
  • Loading branch information
BobbyESP committed May 5, 2024
1 parent 72ad4b6 commit 24d881f
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
})
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
)
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@
<string name="music_queue">Cola de música</string>
<string name="toggle_shuffle">Alternar modo aleatorio</string>
<string name="toggle_repeat">Alternar modo de repetición</string>
<string name="empty_media_store">MediaStore vacío</string>
<string name="empty_media_store_desc">Parece que no tienes canciones en tu dispositivo. Vuelve cuando tengas algo que editar!</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@
<string name="music_queue">Music queue</string>
<string name="toggle_shuffle">Toggle shuffle</string>
<string name="toggle_repeat">Toggle repeat</string>
<string name="empty_media_store">Empty MediaStore</string>
<string name="empty_media_store_desc">Seems like you have no songs on your device. Come back when there\'s something to edit!</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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'
android.defaultConfig.ndk.debugSymbolLevel='FULL'
org.gradle.configuration-cache=true
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 24d881f

Please sign in to comment.