Skip to content

Commit

Permalink
initial work
Browse files Browse the repository at this point in the history
  • Loading branch information
brdunn committed Oct 10, 2023
1 parent 7cf6776 commit a5121a1
Show file tree
Hide file tree
Showing 53 changed files with 1,042 additions and 314 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ dependencies {
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.navigation.ui.ktx)
implementation(libs.androidx.hilt.navigation.compose)
implementation(libs.accompanist.navigation.material)

implementation(libs.androidx.lifecycle.viewModel.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
Expand All @@ -96,6 +97,7 @@ dependencies {
implementation(libs.androidx.compose.animation)
implementation(libs.androidx.compose.ui.tooling.preview)
debugImplementation(libs.androidx.compose.ui.tooling)
implementation(libs.androidx.compose.material)
implementation(libs.androidx.compose.material.iconsExtended)
compileOnly(libs.androidx.compose.compiler)
implementation(libs.androidx.compose.paging)
Expand Down
19 changes: 13 additions & 6 deletions app/src/main/java/com/devdunnapps/amplify/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ object AppModule {

@Provides
@Singleton
fun provideMusicServiceConnection(@ApplicationContext context: Context): MusicServiceConnection =
fun provideMusicServiceConnection(
@ApplicationContext context: Context
): MusicServiceConnection =
MusicServiceConnection(context, ComponentName(context, MusicService::class.java))

@Provides
Expand All @@ -59,7 +61,8 @@ object AppModule {
.create(PlexTVAPI::class.java)

@Provides
fun providePlexTVRepository(plexTVAPI: PlexTVAPI): PlexTVRepository = PlexTVRepositoryImpl(plexTVAPI)
fun providePlexTVRepository(plexTVAPI: PlexTVAPI): PlexTVRepository =
PlexTVRepositoryImpl(plexTVAPI)

@Provides
fun providePlexAPI(@ApplicationContext context: Context): PlexAPI {
Expand All @@ -82,15 +85,18 @@ object AppModule {
@Provides
@Named("library")
fun provideLibrary(@ApplicationContext context: Context): String =
PreferencesUtils.readSharedSetting(context, PreferencesUtils.PREF_PLEX_SERVER_LIBRARY).orEmpty()
PreferencesUtils.readSharedSetting(context, PreferencesUtils.PREF_PLEX_SERVER_LIBRARY)
.orEmpty()

@Provides
fun providePlexRepository(api: PlexAPI, @Named("library") library: String): PlexRepository =
PlexRepositoryImpl(api, library)

@Provides
@Singleton
fun providePreferencesDataStore(@ApplicationContext context: Context): DataStore<UserPreferences> =
fun providePreferencesDataStore(
@ApplicationContext context: Context
): DataStore<UserPreferences> =
DataStoreFactory.create(
scope = CoroutineScope(Dispatchers.IO + SupervisorJob()),
serializer = UserPreferencesSerializer()
Expand All @@ -100,6 +106,7 @@ object AppModule {

@Provides
@Singleton
fun providePreferencesRepository(preferencesDataStore: DataStore<UserPreferences>): PreferencesRepository =
PreferencesRepositoryImpl(preferences = preferencesDataStore)
fun providePreferencesRepository(
preferencesDataStore: DataStore<UserPreferences>
): PreferencesRepository = PreferencesRepositoryImpl(preferences = preferencesDataStore)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.devdunnapps.amplify.R
import com.google.accompanist.themeadapter.material3.Mdc3Theme
import com.devdunnapps.amplify.ui.theme.Theme

class AboutActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContent {
Mdc3Theme {
Theme {
AboutScreen(onNavigateUp = ::onNavigateUp)
}
}
Expand All @@ -32,7 +32,7 @@ class AboutActivity : AppCompatActivity() {

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun AboutScreen(onNavigateUp: () -> Unit) {
internal fun AboutScreen(onNavigateUp: () -> Unit) {
Scaffold(
topBar = { AboutTopBar(onNavigateUp = onNavigateUp) },
content = { contentPadding ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.devdunnapps.amplify.ui.about

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.navArgument

fun NavGraphBuilder.aboutScreen(onNavigateUp: () -> Unit) {
composable(route = "about") {
AboutScreen(onNavigateUp = onNavigateUp)
}
}

fun NavController.navigateToAbout() {
navigate("about")
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import com.devdunnapps.amplify.R
import com.devdunnapps.amplify.domain.models.Playlist
import com.devdunnapps.amplify.ui.components.LoadingPager
import com.devdunnapps.amplify.ui.theme.Theme
import com.devdunnapps.amplify.utils.Resource
import com.google.accompanist.themeadapter.material3.Mdc3Theme
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
Expand All @@ -53,7 +53,7 @@ class AddToPlaylistBottomSheetFragment : BottomSheetDialogFragment() {

return ComposeView(requireContext()).apply {
setContent {
Mdc3Theme {
Theme {
AddToPlaylistBottomSheet(viewModel = viewModel)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,37 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.outlined.PlaylistPlay
import androidx.compose.material.icons.outlined.QueueMusic
import androidx.compose.material3.*
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand All @@ -38,6 +58,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.fragment.findNavController
import coil.compose.AsyncImage
import com.devdunnapps.amplify.MobileNavigationDirections
Expand All @@ -47,6 +68,7 @@ import com.devdunnapps.amplify.domain.models.Song
import com.devdunnapps.amplify.ui.components.ErrorScreen
import com.devdunnapps.amplify.ui.components.ExpandableText
import com.devdunnapps.amplify.ui.components.LoadingScreen
import com.devdunnapps.amplify.ui.theme.Theme
import com.devdunnapps.amplify.ui.utils.FragmentSubDestinationScaffold
import com.devdunnapps.amplify.ui.utils.getCurrentSizeClass
import com.devdunnapps.amplify.utils.PlexUtils
Expand Down Expand Up @@ -82,7 +104,11 @@ class AlbumFragment : Fragment() {
}

@Composable
fun AlbumRoute(viewModel: AlbumViewModel, onSongMenuClick: (String) -> Unit, modifier: Modifier = Modifier) {
fun AlbumRoute(
viewModel: AlbumViewModel = hiltViewModel(),
onSongMenuClick: (String) -> Unit,
modifier: Modifier = Modifier
) {
AlbumScreen(
album = viewModel.album.collectAsState().value,
onSongClick = { viewModel.playSong(it) },
Expand Down Expand Up @@ -552,7 +578,7 @@ private fun AlbumSong(
@Preview
@Composable
private fun PreviewAlbumHeader() {
Mdc3Theme {
Theme {
Surface {
val album = Album(
artistId = "0",
Expand All @@ -579,7 +605,7 @@ private fun PreviewAlbumHeader() {
@Preview
@Composable
private fun PreviewAlbumSong() {
Mdc3Theme {
Theme {
Surface {
val song = Song(
year = "2021",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.devdunnapps.amplify.ui.album

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.navArgument

fun NavGraphBuilder.albumScreen(
onOpenSongMenu: (String) -> Unit
) {
composable(
route = "albums/{albumId}",
arguments = listOf(navArgument("albumId") { type = NavType.StringType })
) {
AlbumRoute(onSongMenuClick = onOpenSongMenu)
}
}

fun NavController.navigateToAlbum(albumId: String) {
navigate("albums/$albumId")
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AlbumViewModel @Inject constructor(
private val musicServiceConnection: MusicServiceConnection
) : ViewModel() {

private val albumId = AlbumFragmentArgs.fromSavedStateHandle(savedStateHandle).albumId
private val albumId: String = checkNotNull(savedStateHandle["albumId"])

private val _album = MutableStateFlow<Resource<AlbumScreenUIModel>>(Resource.Loading)
val album = _album.asStateFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class AlbumsFragment : Fragment() {
}

@Composable
private fun AlbumsRoute(
internal fun AlbumsRoute(
onAlbumClick: (String) -> Unit,
modifier: Modifier = Modifier,
viewModel: AlbumsViewModel = hiltViewModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import coil.compose.AsyncImage
Expand Down Expand Up @@ -96,8 +97,8 @@ class ArtistFragment : Fragment() {
}

@Composable
private fun ArtistRoute(
viewModel: ArtistViewModel,
internal fun ArtistRoute(
viewModel: ArtistViewModel = hiltViewModel(),
onAlbumClick: (String) -> Unit,
onViewAllAlbumsClick: () -> Unit,
onViewAllSinglesEPsClick: () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.devdunnapps.amplify.ui.artist

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.navArgument

private const val ARTIST_ID_ARG = "artistId"

fun NavGraphBuilder.artistScreen(
onNavigateToAlbum: (String) -> Unit,
onNavigateToAllArtistAlbums: () -> Unit,
onNavigateToAllArtistEPsSingles: () -> Unit,
onOpenSongMenu: (String) -> Unit,
onNavigateToAllArtistSongs: () -> Unit
) {
composable(
route = "artists/{artistId}",
arguments = listOf(navArgument(ARTIST_ID_ARG) { type = NavType.StringType })
) {
ArtistRoute(
onAlbumClick = onNavigateToAlbum,
onViewAllAlbumsClick = onNavigateToAllArtistAlbums,
onViewAllSinglesEPsClick = onNavigateToAllArtistEPsSingles,
onSongMenuClick = onOpenSongMenu,
onViewAllSongsClick = onNavigateToAllArtistSongs
)
}
}

fun NavController.navigateToArtist(artistId: String) {
navigate("artists/$artistId")
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ArtistViewModel @Inject constructor(
private val musicServiceConnection: MusicServiceConnection
) : ViewModel() {

private val artistId = ArtistFragmentArgs.fromSavedStateHandle(savedStateHandle).artistKey
private val artistId: String = checkNotNull(savedStateHandle["artistId"])

private val _artistSongs = MutableStateFlow<Resource<List<Song>>>(Resource.Loading)
val artistSongs = _artistSongs.asStateFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ArtistsFragment : Fragment() {
}

@Composable
private fun ArtistsRoute(
internal fun ArtistsRoute(
onArtistClick: (String) -> Unit,
modifier: Modifier = Modifier,
viewModel: ArtistsViewModel = hiltViewModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.devdunnapps.amplify.R
import com.devdunnapps.amplify.domain.models.Album
import com.devdunnapps.amplify.ui.theme.Theme
import com.devdunnapps.amplify.utils.PlexUtils
import com.google.accompanist.themeadapter.material3.Mdc3Theme

@Composable
fun AlbumCard(onClick: () -> Unit, album: Album, modifier: Modifier = Modifier) {
Expand Down Expand Up @@ -54,7 +54,7 @@ fun AlbumCard(onClick: () -> Unit, album: Album, modifier: Modifier = Modifier)
@Preview
@Composable
fun AlbumCardPreview() {
Mdc3Theme {
Theme {
AlbumCard(
onClick = {},
album = Album(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.google.accompanist.themeadapter.material3.Mdc3Theme
import com.devdunnapps.amplify.ui.theme.Theme

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand All @@ -15,7 +15,7 @@ fun AmplifyScaffold(
floatingActionButton: @Composable () -> Unit = {},
content: @Composable (PaddingValues) -> Unit
) {
Mdc3Theme {
Theme {
Scaffold(
topBar = topBar,
content = content,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
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 coil.compose.AsyncImage
import com.devdunnapps.amplify.R
import com.devdunnapps.amplify.domain.models.Artist
import com.devdunnapps.amplify.ui.theme.Theme
import com.devdunnapps.amplify.utils.PlexUtils
import com.google.accompanist.themeadapter.material3.Mdc3Theme

@Composable
fun ArtistCard(onClick: () -> Unit, artist: Artist, modifier: Modifier = Modifier) {
Expand Down Expand Up @@ -61,7 +59,7 @@ fun ArtistCard(onClick: () -> Unit, artist: Artist, modifier: Modifier = Modifie
@Preview
@Composable
fun ArtistCardPreview() {
Mdc3Theme {
Theme {
ArtistCard(
onClick = {},
artist = Artist(
Expand Down
Loading

0 comments on commit a5121a1

Please sign in to comment.