Skip to content

Commit

Permalink
Merge pull request #48 from swingmx/artist-info
Browse files Browse the repository at this point in the history
`:feature:artist`: Go To Similar Artists
  • Loading branch information
Ericgacoki authored Nov 5, 2024
2 parents d0c1581 + 664be79 commit 694d52f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@ interface ArtistInfoUiEvent {

data class OnLoadArtistInfo(val artistHash: String) : ArtistInfoUiEvent

data class OnToggleArtistFavorite(val artistHash: String, val isFavorite: Boolean) :
ArtistInfoUiEvent
data class OnUpdateArtistHash(val artistHash: String) : ArtistInfoUiEvent

data class OnViewAllTracks(val artistHash: String) : ArtistInfoUiEvent

data class OnViewAllAlbums(val artistHash: String) : ArtistInfoUiEvent

data class OnViewAllEPAndSingles(val artistHash: String) : ArtistInfoUiEvent

data class OnViewAllAppearances(val artistHash: String) : ArtistInfoUiEvent

data class OnClickAlbum(val albumHash: String) : ArtistInfoUiEvent

data class OnClickSimilarArtist(val artistHash: String) : ArtistInfoUiEvent
data class OnToggleArtistFavorite(
val artistHash: String,
val isFavorite: Boolean
) : ArtistInfoUiEvent

data class OnRefresh(val artistHash: String) : ArtistInfoUiEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ private fun ArtistInfo(
onToggleFavorite: (String, Boolean) -> Unit,
onShuffle: () -> Unit,
onPlayAllTracks: () -> Unit,
onClickArtistTrack: (queue: List<Track>, index: Int) -> Unit
onClickArtistTrack: (queue: List<Track>, index: Int) -> Unit,
onClickSimilarArtist: (artistHash: String) -> Unit
) {
val clickInteractionSource = remember { MutableInteractionSource() }

Expand Down Expand Up @@ -705,7 +706,9 @@ private fun ArtistInfo(
modifier = Modifier.fillMaxWidth(),
artist = artist,
baseUrl = baseUrl,
onClick = {}
onClick = { artistHash ->
onClickSimilarArtist(artistHash)
}
)
}
}
Expand Down Expand Up @@ -741,7 +744,9 @@ fun ArtistInfoScreen(
) {
if (artistInfoState.value.requiresReload) {
artistInfoViewModel.onArtistInfoUiEvent(
event = ArtistInfoUiEvent.OnLoadArtistInfo(artistHash)
event = ArtistInfoUiEvent.OnLoadArtistInfo(
artistInfoState.value.infoResource.data?.artist?.artistHash ?: artistHash
)
)
}
}
Expand All @@ -755,7 +760,8 @@ fun ArtistInfoScreen(

artistInfoViewModel.onArtistInfoUiEvent(
ArtistInfoUiEvent.OnRefresh(
artistHash = artistHash
artistHash = artistInfoState.value.infoResource.data?.artist?.artistHash
?: artistHash
)
)
},
Expand Down Expand Up @@ -870,6 +876,11 @@ fun ArtistInfoScreen(
queue = queue
)
)
},
onClickSimilarArtist = {
artistInfoViewModel.onArtistInfoUiEvent(
ArtistInfoUiEvent.OnUpdateArtistHash(it)
)
}
)
}
Expand Down Expand Up @@ -1274,7 +1285,8 @@ fun ArtistInfoPreview() {
onToggleFavorite = { _, _ -> },
onShuffle = {},
onPlayAllTracks = {},
onClickArtistTrack = { _, _ -> }
onClickArtistTrack = { _, _ -> },
onClickSimilarArtist = {}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.android.swingmusic.artist.presentation.viewmodel

import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.android.swingmusic.artist.domain.repository.ArtistRepository
Expand All @@ -11,7 +9,6 @@ import com.android.swingmusic.core.data.util.Resource
import com.android.swingmusic.core.domain.model.AlbumsAndAppearances
import com.android.swingmusic.core.domain.model.ArtistExpanded
import com.android.swingmusic.core.domain.model.ArtistInfo
import com.android.swingmusic.player.presentation.event.PlayerUiEvent
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand All @@ -24,7 +21,8 @@ import javax.inject.Inject
class ArtistInfoViewModel @Inject constructor(
private val artistRepository: ArtistRepository
) : ViewModel() {
private val _artistInfoState: MutableStateFlow<ArtistInfoState> = MutableStateFlow(ArtistInfoState())
private val _artistInfoState: MutableStateFlow<ArtistInfoState> =
MutableStateFlow(ArtistInfoState())
val artistInfoState: StateFlow<ArtistInfoState> = _artistInfoState

private fun getArtistInfo(artistHash: String) {
Expand Down Expand Up @@ -147,33 +145,29 @@ class ArtistInfoViewModel @Inject constructor(
toggleArtistFavorite(event.artistHash, event.isFavorite)
}

is ArtistInfoUiEvent.OnViewAllTracks -> {
// Handle viewing all tracks of artist
}

is ArtistInfoUiEvent.OnViewAllAlbums -> {
// Handle viewing all albums of artist
}

is ArtistInfoUiEvent.OnViewAllEPAndSingles -> {
// Handle viewing all EPs and singles of artist
is ArtistInfoUiEvent.OnRefresh -> {
getArtistInfo(event.artistHash)
getSimilarArtists(event.artistHash)
}

is ArtistInfoUiEvent.OnViewAllAppearances -> {
// Handle viewing all appearances of artist
}
is ArtistInfoUiEvent.OnUpdateArtistHash -> {

is ArtistInfoUiEvent.OnClickAlbum -> {
// Handle album click event
}
val currentState = _artistInfoState.value
val currentInfo = currentState.infoResource.data

is ArtistInfoUiEvent.OnClickSimilarArtist -> {
// Handle similar artist click event
}
currentInfo?.let { info ->
_artistInfoState.value = currentState.copy(
infoResource = Resource.Success(
data = info.copy(
artist = info.artist.copy(artistHash = event.artistHash),
albumsAndAppearances = info.albumsAndAppearances,
tracks = info.tracks
)
)
)
}

is ArtistInfoUiEvent.OnRefresh -> {
getArtistInfo(event.artistHash)
getSimilarArtists(event.artistHash)
onArtistInfoUiEvent(ArtistInfoUiEvent.OnLoadArtistInfo(event.artistHash))
}

else -> {
Expand Down

0 comments on commit 694d52f

Please sign in to comment.