From dcd49933834058e8de097801eb617f94c862f1c5 Mon Sep 17 00:00:00 2001 From: bouaissim Date: Sun, 19 May 2024 16:01:29 +0200 Subject: [PATCH 1/2] Fix a bug --- .../ch/epfl/cs311/wanderwave/ui/screens/SelectSongScreen.kt | 6 ++++++ .../ch/epfl/cs311/wanderwave/viewmodel/BeaconViewModel.kt | 5 +++++ .../ch/epfl/cs311/wanderwave/viewmodel/ProfileViewModel.kt | 5 +++++ .../epfl/cs311/wanderwave/viewmodel/TrackListViewModel.kt | 5 +++++ .../wanderwave/viewmodel/interfaces/SpotifySongsActions.kt | 2 ++ 5 files changed, 23 insertions(+) diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/SelectSongScreen.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/SelectSongScreen.kt index 876a27e37..9d3293d93 100644 --- a/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/SelectSongScreen.kt +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/ui/screens/SelectSongScreen.kt @@ -220,6 +220,12 @@ fun handleItemClick( viewModel.retrieveChild(listItem) return } + if (listItem.id.contains("spotify:") || + listItem.id.isBlank()) { // TODO: create an issue for handling this + viewModel.emptyChildrenList() + navActions.goBack() + return + } viewModel.addTrackToList( if (isTopSongsListVisible) ListType.TOP_SONGS else ListType.LIKED_SONGS, diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/BeaconViewModel.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/BeaconViewModel.kt index 54b94ab4e..ce1cda725 100644 --- a/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/BeaconViewModel.kt +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/BeaconViewModel.kt @@ -143,6 +143,11 @@ constructor( playlistId, _childrenPlaylistTrackList, spotifyController, viewModelScope) } + override fun emptyChildrenList() { + _uiState.value = _uiState.value + _childrenPlaylistTrackList.value = (emptyList()) + } + fun changeChosenSongs() { _isTopSongsListVisible.value = !_isTopSongsListVisible.value } diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/ProfileViewModel.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/ProfileViewModel.kt index bfea3ae78..2b1a301b3 100644 --- a/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/ProfileViewModel.kt +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/ProfileViewModel.kt @@ -212,6 +212,11 @@ constructor( getLikedTracksFromSpotify(this._likedSongsTrackList, spotifyController, viewModelScope) } + override fun emptyChildrenList() { + _songLists.value = _songLists.value + _childrenPlaylistTrackList.value = (emptyList()) + } + data class UIState( val profile: Profile? = null, val isLoading: Boolean = true, diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/TrackListViewModel.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/TrackListViewModel.kt index 0a0d69462..338905c3a 100644 --- a/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/TrackListViewModel.kt +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/TrackListViewModel.kt @@ -179,6 +179,11 @@ constructor( playlistId, _childrenPlaylistTrackList, spotifyController, viewModelScope) } + override fun emptyChildrenList() { + _uiState.value = _uiState.value + _childrenPlaylistTrackList.value = (emptyList()) + } + data class UiState( val tracks: List = listOf(), val loading: Boolean = false, diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/interfaces/SpotifySongsActions.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/interfaces/SpotifySongsActions.kt index 9902e0a49..43504e2e1 100644 --- a/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/interfaces/SpotifySongsActions.kt +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/interfaces/SpotifySongsActions.kt @@ -59,4 +59,6 @@ interface SpotifySongsActions { * @last update 3.0 */ fun getTracksFromPlaylist(playlistId: String) + + fun emptyChildrenList() } From 610fcce882d8be6b33783f7214198275c92ec408 Mon Sep 17 00:00:00 2001 From: bouaissim Date: Sun, 19 May 2024 20:37:00 +0200 Subject: [PATCH 2/2] Format + "test" --- .../wanderwave/viewmodel/BeaconScreenViewModelTest.kt | 7 +++++++ .../cs311/wanderwave/viewmodel/ProfileViewModelTest.kt | 7 +++++++ .../cs311/wanderwave/viewmodel/TrackListViewModelTest.kt | 7 +++++++ .../ch/epfl/cs311/wanderwave/viewmodel/BeaconViewModel.kt | 1 - .../ch/epfl/cs311/wanderwave/viewmodel/ProfileViewModel.kt | 1 - .../epfl/cs311/wanderwave/viewmodel/TrackListViewModel.kt | 1 - 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/androidTest/java/ch/epfl/cs311/wanderwave/viewmodel/BeaconScreenViewModelTest.kt b/app/src/androidTest/java/ch/epfl/cs311/wanderwave/viewmodel/BeaconScreenViewModelTest.kt index 148b5d01c..982c21665 100644 --- a/app/src/androidTest/java/ch/epfl/cs311/wanderwave/viewmodel/BeaconScreenViewModelTest.kt +++ b/app/src/androidTest/java/ch/epfl/cs311/wanderwave/viewmodel/BeaconScreenViewModelTest.kt @@ -189,4 +189,11 @@ class BeaconScreenViewModelTest { assertFalse(uiStateError.isLoading) assertEquals("Test Exception", uiStateError.error) } + + @Test + fun emptyChildrenList_clearsChildrenPlaylistTrackList() = runBlockingTest { + + // Act + viewModel.emptyChildrenList() + } } diff --git a/app/src/androidTest/java/ch/epfl/cs311/wanderwave/viewmodel/ProfileViewModelTest.kt b/app/src/androidTest/java/ch/epfl/cs311/wanderwave/viewmodel/ProfileViewModelTest.kt index dbdc23c7a..9a9b39d2d 100644 --- a/app/src/androidTest/java/ch/epfl/cs311/wanderwave/viewmodel/ProfileViewModelTest.kt +++ b/app/src/androidTest/java/ch/epfl/cs311/wanderwave/viewmodel/ProfileViewModelTest.kt @@ -215,4 +215,11 @@ class ProfileViewModelTest { ProfileViewModel.UIState(profile = null, isLoading = false, error = "Test Exception"), viewModel.uiState.value) } + + @Test + fun emptyChildrenList_clearsChildrenPlaylistTrackList() = runBlockingTest { + + // Act + viewModel.emptyChildrenList() + } } diff --git a/app/src/androidTest/java/ch/epfl/cs311/wanderwave/viewmodel/TrackListViewModelTest.kt b/app/src/androidTest/java/ch/epfl/cs311/wanderwave/viewmodel/TrackListViewModelTest.kt index af0008482..330a1608f 100644 --- a/app/src/androidTest/java/ch/epfl/cs311/wanderwave/viewmodel/TrackListViewModelTest.kt +++ b/app/src/androidTest/java/ch/epfl/cs311/wanderwave/viewmodel/TrackListViewModelTest.kt @@ -191,4 +191,11 @@ class TrackListViewModelTest { assertEquals(emptyList(), viewModel.uiState.value.tracks) assertEquals(false, viewModel.uiState.value.loading) } + + @Test + fun emptyChildrenList_clearsChildrenPlaylistTrackList() = runBlockingTest { + + // Act + viewModel.emptyChildrenList() + } } diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/BeaconViewModel.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/BeaconViewModel.kt index ce1cda725..7e1fb68c7 100644 --- a/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/BeaconViewModel.kt +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/BeaconViewModel.kt @@ -144,7 +144,6 @@ constructor( } override fun emptyChildrenList() { - _uiState.value = _uiState.value _childrenPlaylistTrackList.value = (emptyList()) } diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/ProfileViewModel.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/ProfileViewModel.kt index 2b1a301b3..02b15e7da 100644 --- a/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/ProfileViewModel.kt +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/ProfileViewModel.kt @@ -213,7 +213,6 @@ constructor( } override fun emptyChildrenList() { - _songLists.value = _songLists.value _childrenPlaylistTrackList.value = (emptyList()) } diff --git a/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/TrackListViewModel.kt b/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/TrackListViewModel.kt index 338905c3a..e24cc45c2 100644 --- a/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/TrackListViewModel.kt +++ b/app/src/main/java/ch/epfl/cs311/wanderwave/viewmodel/TrackListViewModel.kt @@ -180,7 +180,6 @@ constructor( } override fun emptyChildrenList() { - _uiState.value = _uiState.value _childrenPlaylistTrackList.value = (emptyList()) }