Skip to content

Commit

Permalink
Merge pull request #55 from swingmx/artist-info
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericgacoki authored Nov 27, 2024
2 parents 40d42d4 + 196608c commit df335cf
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ import com.android.swingmusic.auth.data.workmanager.scheduleTokenRefreshWork
import com.android.swingmusic.auth.presentation.screen.destinations.LoginWithQrCodeDestination
import com.android.swingmusic.auth.presentation.screen.destinations.LoginWithUsernameScreenDestination
import com.android.swingmusic.auth.presentation.viewmodel.AuthViewModel
import com.android.swingmusic.folder.presentation.event.FolderUiEvent
import com.android.swingmusic.folder.presentation.screen.destinations.FoldersAndTracksScreenDestination
import com.android.swingmusic.folder.presentation.viewmodel.FoldersViewModel
import com.android.swingmusic.player.presentation.screen.MiniPlayer
import com.android.swingmusic.player.presentation.screen.destinations.NowPlayingScreenDestination
import com.android.swingmusic.player.presentation.screen.destinations.QueueScreenDestination
Expand All @@ -81,13 +83,13 @@ import com.ramcosta.composedestinations.spec.NavGraphSpec
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import timber.log.Timber

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
private val mediaControllerViewModel: MediaControllerViewModel by viewModels<MediaControllerViewModel>()
private val authViewModel: AuthViewModel by viewModels<AuthViewModel>()
private val artistInfoViewModel: ArtistInfoViewModel by viewModels<ArtistInfoViewModel>()
private val foldersViewModel: FoldersViewModel by viewModels<FoldersViewModel>()

private lateinit var controllerFuture: ListenableFuture<MediaController>

Expand Down Expand Up @@ -155,7 +157,7 @@ class MainActivity : ComponentActivity() {
label = "Spacer Height"
)

var folderClickCounter by remember{ mutableIntStateOf(0) }
var folderClickCounter by remember { mutableIntStateOf(0) }
SwingMusicTheme {
Scaffold(
modifier = Modifier.fillMaxSize(),
Expand Down Expand Up @@ -258,9 +260,12 @@ class MainActivity : ComponentActivity() {
}
)

if (item.navGraph == NavGraphs.folder){
folderClickCounter += 1
Timber.e("TODO: Fire an action to reset to root folder on second click... $folderClickCounter")
if (item.navGraph == NavGraphs.folder) {
foldersViewModel.onFolderUiEvent(
FolderUiEvent.OnClickNavPath(
folder = foldersViewModel.homeDir
)
)
}
}
)
Expand All @@ -276,6 +281,7 @@ class MainActivity : ComponentActivity() {
isUserLoggedIn = isUserLoggedIn,
navController = navController,
authViewModel = authViewModel,
foldersViewModel = foldersViewModel,
artistInfoViewModel = artistInfoViewModel,
mediaControllerViewModel = mediaControllerViewModel
)
Expand Down Expand Up @@ -331,6 +337,7 @@ internal fun SwingMusicAppNavigation(
isUserLoggedIn: Boolean,
navController: NavHostController,
authViewModel: AuthViewModel,
foldersViewModel: FoldersViewModel,
artistInfoViewModel: ArtistInfoViewModel,
mediaControllerViewModel: MediaControllerViewModel
) {
Expand Down Expand Up @@ -431,6 +438,7 @@ internal fun SwingMusicAppNavigation(
navGraph = NavGraphs.root(isUserLoggedIn),
dependenciesContainerBuilder = {
dependency(authViewModel)
dependency(foldersViewModel)
dependency(mediaControllerViewModel)
dependency(artistInfoViewModel)
dependency(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -984,10 +984,6 @@ fun ArtistInfoScreen(
},
onGetSheetAction = { track, sheetAction ->
when (sheetAction) {
is BottomSheetAction.OpenArtistsDialog -> {

}

is BottomSheetAction.GotoAlbum -> {
commonNavigator.gotoAlbumWithInfo(track.albumHash)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ private fun FoldersAndTracks(
@Destination
@Composable
fun FoldersAndTracksScreen(
foldersViewModel: FoldersViewModel = hiltViewModel(),
foldersViewModel: FoldersViewModel,
albumWithInfoViewModel: AlbumWithInfoViewModel = hiltViewModel(),
mediaControllerViewModel: MediaControllerViewModel,
navigator: CommonNavigator,
Expand All @@ -401,19 +401,26 @@ fun FoldersAndTracksScreen(
val playerUiState by mediaControllerViewModel.playerUiState.collectAsState()
val baseUrl by mediaControllerViewModel.baseUrl.collectAsState()

var routeByGotoFolder by remember{ mutableStateOf(false) }

LaunchedEffect(key1 = Unit) {
if (gotoFolderName != null && gotoFolderPath != null) {
routeByGotoFolder = true
foldersViewModel.resetNavPaths()

val folder = Folder(
name = gotoFolderName,
path = gotoFolderPath,
trackCount = 0,
folderCount = 0,
isSym = false
)

foldersViewModel.onFolderUiEvent(FolderUiEvent.OnClickFolder(folder))
} else if (foldersAndTracksState.foldersAndTracks.folders.isEmpty() &&
foldersAndTracksState.foldersAndTracks.tracks.isEmpty()
) {
routeByGotoFolder = false
foldersViewModel.onFolderUiEvent(FolderUiEvent.OnClickFolder(homeDir))
}
}
Expand All @@ -428,6 +435,7 @@ fun FoldersAndTracksScreen(
navPaths = navPaths,
baseUrl = baseUrl ?: "",
onClickNavPath = { folder ->
routeByGotoFolder = false
foldersViewModel.onFolderUiEvent(FolderUiEvent.OnClickNavPath(folder))
},
onRetry = { event ->
Expand All @@ -439,6 +447,7 @@ fun FoldersAndTracksScreen(
mediaControllerViewModel.onPlayerUiEvent(PlayerUiEvent.OnRetry)
},
onClickFolder = { folder ->
routeByGotoFolder = false
foldersViewModel.onFolderUiEvent(FolderUiEvent.OnClickFolder(folder))
},
onClickTrackItem = { index: Int, queue: List<Track> ->
Expand Down Expand Up @@ -471,7 +480,7 @@ fun FoldersAndTracksScreen(
)

val overrideSystemBackNav = currentFolder.path != "\$home"
BackHandler(enabled = overrideSystemBackNav) {
BackHandler(enabled = overrideSystemBackNav && routeByGotoFolder.not()) {
foldersViewModel.onFolderUiEvent(FolderUiEvent.OnBackNav(currentFolder))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.android.swingmusic.folder.presentation.state.FoldersAndTracksState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject

@HiltViewModel
Expand All @@ -36,6 +37,10 @@ class FoldersViewModel @Inject constructor(
mutableStateOf(listOf(homeDir))
val navPaths: State<List<Folder>> = _navPaths

fun resetNavPaths() {
_navPaths.value = listOf(homeDir)
}

private var _foldersAndTracks: MutableState<FoldersAndTracksState> =
mutableStateOf(
FoldersAndTracksState(
Expand Down Expand Up @@ -127,14 +132,11 @@ class FoldersViewModel @Inject constructor(

if (!_navPaths.value.contains(event.folder)) {
_navPaths.value = listOf<Folder>(homeDir)
// TODO: rebuild the entire path (use network result path)
.plus(
(_navPaths.value.filter {
event.folder.path.contains(it.path)
}.plus(event.folder))
.toSet()
.toList()
)
).distinctBy { it.path }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@ fun QueueScreen(
is BottomSheetAction.GotoAlbum -> {
navigator.gotoAlbumWithInfo(track.albumHash)
}
is BottomSheetAction.GotoFolder -> {
navigator.gotoSourceFolder(name = sheetAction.name, path = sheetAction.path)
}

else -> {}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.android.swingmusic.uicomponent.presentation.component

import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
Expand Down

0 comments on commit df335cf

Please sign in to comment.