Skip to content

Commit

Permalink
initial work
Browse files Browse the repository at this point in the history
  • Loading branch information
brdunn committed Dec 20, 2023
1 parent 60345f4 commit 814d0fb
Show file tree
Hide file tree
Showing 17 changed files with 316 additions and 19 deletions.
10 changes: 10 additions & 0 deletions app/src/main/java/com/devdunnapps/amplify/data/PlexAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,14 @@ interface PlexAPI {
@Query("title") title: String? = null,
@Query("summary") summary: String? = null
): NetworkResponse<Unit>

@GET("library/sections/{section}/all?viewCount=1&type=8&sort=lastViewedAt:desc&limit=10")
suspend fun getRecentlyPlayedArtists(
@Path("section") section: String
): NetworkResponse<PlexModelDTO>

@GET("library/sections/{section}/all?type=9&sort=addedAt:desc&limit=10")
suspend fun getRecentlyAddedAlbums(
@Path("section") section: String
): NetworkResponse<PlexModelDTO>
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,14 @@ class PlexRepositoryImpl @Inject constructor(
summary: String?
): NetworkResponse<Unit> =
api.editPlaylistMetadata(playlistId = playlistId, title = title, summary = summary)

override suspend fun getRecentlyPlayedArtists(): NetworkResponse<List<Artist>> =
api.getRecentlyPlayedArtists(section).map {
it.mediaContainer.metadata?.map { artist -> artist.toArtist() }.orEmpty()
}

override suspend fun getRecentlyAddedAlbums(): NetworkResponse<List<Album>> =
api.getRecentlyAddedAlbums(section).map {
it.mediaContainer.metadata?.map { album -> album.toAlbum() }.orEmpty()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@ interface PlexRepository {
suspend fun markSongAsListened(songId: String): NetworkResponse<Unit>

suspend fun editPlaylistMetadata(playlistId: String, title: String?, summary: String?): NetworkResponse<Unit>

suspend fun getRecentlyPlayedArtists(): NetworkResponse<List<Artist>>

suspend fun getRecentlyAddedAlbums(): NetworkResponse<List<Album>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import com.devdunnapps.amplify.ui.components.LoadingScreen
import com.devdunnapps.amplify.ui.utils.FragmentRootDestinationScaffold
import dagger.hilt.android.AndroidEntryPoint

private const val ARTWORK_SIZE = 100

@AndroidEntryPoint
class AlbumsFragment : Fragment() {

Expand Down Expand Up @@ -74,7 +76,7 @@ private fun AlbumsScreen(
LoadingScreen(modifier = modifier)

LazyVerticalGrid(
columns = GridCells.Adaptive(100.dp),
columns = GridCells.Adaptive(ARTWORK_SIZE.dp),
contentPadding = PaddingValues(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
horizontalArrangement = Arrangement.spacedBy(16.dp),
Expand All @@ -84,7 +86,8 @@ private fun AlbumsScreen(
albums[index]?.let {
AlbumCard(
onClick = { onAlbumClick(it.id) },
album = it
album = it,
artworkSize = ARTWORK_SIZE.dp
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import com.devdunnapps.amplify.ui.utils.FragmentSubDestinationScaffold
import com.devdunnapps.amplify.utils.Resource
import dagger.hilt.android.AndroidEntryPoint

private const val ARTWORK_SIZE = 150

@AndroidEntryPoint
class ArtistAllAlbumsFragment : Fragment() {

Expand Down Expand Up @@ -85,7 +87,7 @@ private fun ArtistAllAlbumsScreen(
@Composable
private fun ArtistAllAlbumsList(albums: List<Album>, onAlbumClick: (String) -> Unit, modifier: Modifier = Modifier) {
LazyVerticalGrid(
columns = GridCells.Adaptive(150.dp),
columns = GridCells.Adaptive(ARTWORK_SIZE.dp),
contentPadding = PaddingValues(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
horizontalArrangement = Arrangement.spacedBy(16.dp),
Expand All @@ -94,6 +96,7 @@ private fun ArtistAllAlbumsList(albums: List<Album>, onAlbumClick: (String) -> U
items(albums) {
AlbumCard(
onClick = { onAlbumClick(it.id) },
artworkSize = ARTWORK_SIZE.dp,
album = it
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import com.devdunnapps.amplify.ui.components.LoadingScreen
import com.devdunnapps.amplify.ui.utils.FragmentRootDestinationScaffold
import dagger.hilt.android.AndroidEntryPoint

private const val ARTWORK_SIZE = 100

@AndroidEntryPoint
class ArtistsFragment : Fragment() {

Expand Down Expand Up @@ -74,7 +76,7 @@ private fun ArtistsScreen(
LoadingScreen(modifier = modifier)

LazyVerticalGrid(
columns = GridCells.Adaptive(100.dp),
columns = GridCells.Adaptive(ARTWORK_SIZE.dp),
contentPadding = PaddingValues(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
horizontalArrangement = Arrangement.spacedBy(16.dp),
Expand All @@ -84,7 +86,8 @@ private fun ArtistsScreen(
artists[index]?.let {
ArtistCard(
onClick = { onArtistClick(it.id) },
artist = it
artist = it,
artworkSize = ARTWORK_SIZE.dp
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package com.devdunnapps.amplify.ui.components
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
Expand All @@ -16,6 +20,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.devdunnapps.amplify.R
Expand All @@ -24,15 +29,23 @@ import com.devdunnapps.amplify.utils.PlexUtils
import com.google.accompanist.themeadapter.material3.Mdc3Theme

@Composable
fun AlbumCard(onClick: () -> Unit, album: Album, modifier: Modifier = Modifier) {
fun AlbumCard(
onClick: () -> Unit,
album: Album,
artworkSize: Dp,
modifier: Modifier = Modifier
) {
Column(
modifier = modifier.clickable { onClick() },
modifier = modifier
.width(IntrinsicSize.Min)
.clickable { onClick() },
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
val context = LocalContext.current
val imageUrl = remember { PlexUtils.getInstance(context).getSizedImage(album.thumb, 300, 300) }
AsyncImage(
modifier = Modifier
.size(artworkSize)
.aspectRatio(1f)
.clip(RoundedCornerShape(6.dp)),
model = imageUrl,
Expand All @@ -42,7 +55,7 @@ fun AlbumCard(onClick: () -> Unit, album: Album, modifier: Modifier = Modifier)
contentScale = ContentScale.Crop
)

Column {
Column(modifier = Modifier.fillMaxWidth()) {
Text(
text = album.title,
style = MaterialTheme.typography.bodyMedium,
Expand Down Expand Up @@ -77,7 +90,8 @@ fun AlbumCardPreview() {
year = "",
artistName = "",
studio = ""
)
),
artworkSize = 100.dp
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package com.devdunnapps.amplify.ui.components
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountCircle
Expand All @@ -21,6 +25,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.devdunnapps.amplify.R
Expand All @@ -29,16 +34,24 @@ import com.devdunnapps.amplify.utils.PlexUtils
import com.google.accompanist.themeadapter.material3.Mdc3Theme

@Composable
fun ArtistCard(onClick: () -> Unit, artist: Artist, modifier: Modifier = Modifier) {
fun ArtistCard(
artist: Artist,
artworkSize: Dp,
onClick: () -> Unit,
modifier: Modifier = Modifier
) {
Column(
modifier = modifier.clickable { onClick() },
modifier = modifier
.width(IntrinsicSize.Min)
.clickable { onClick() },
verticalArrangement = Arrangement.spacedBy(4.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
val context = LocalContext.current
val imageUrl = remember { PlexUtils.getInstance(context).getSizedImage(artist.thumb, 500, 500) }
AsyncImage(
modifier = Modifier
.size(artworkSize)
.aspectRatio(1f)
.clip(CircleShape),
model = imageUrl,
Expand All @@ -53,7 +66,8 @@ fun ArtistCard(onClick: () -> Unit, artist: Artist, modifier: Modifier = Modifie
textAlign = TextAlign.Center,
style = MaterialTheme.typography.bodySmall,
maxLines = 1,
overflow = TextOverflow.Ellipsis
overflow = TextOverflow.Ellipsis,
modifier = Modifier.fillMaxWidth()
)
}
}
Expand All @@ -70,7 +84,8 @@ fun ArtistCardPreview() {
thumb = "/library/metadata/45209/thumb/1641184622",
art = null,
bio = ""
)
),
artworkSize = 100.dp
)
}
}
Loading

0 comments on commit 814d0fb

Please sign in to comment.