-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
database-design branch - feat: implement a feature that allows adding…
… song to the albums
- Loading branch information
1 parent
1ea68e1
commit def4068
Showing
5 changed files
with
134 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
app/src/main/java/com/example/harmonyhub/presentation/viewmodel/PlaylistViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.example.harmonyhub.presentation.viewmodel | ||
|
||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import com.example.harmonyhub.domain.repository.UserDataRepo | ||
import com.example.harmonyhub.ui.components.Song | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class PlaylistViewModel @Inject constructor( | ||
private val userRepo: UserDataRepo, | ||
): ViewModel() { | ||
private val _dataFetchingState = MutableLiveData<PlaylistSongFetchingState>() | ||
val dataFetchingState: MutableLiveData<PlaylistSongFetchingState> get() = _dataFetchingState | ||
|
||
init { | ||
resetDataFetchingState() | ||
} | ||
|
||
fun addSongToPlayList(song: Song, playlistName: String) { | ||
userRepo.addSongToPlayList(song, playlistName, callback = { | ||
_dataFetchingState.value = it | ||
}) | ||
} | ||
|
||
fun resetDataFetchingState() { | ||
_dataFetchingState.value = PlaylistSongFetchingState.Pending | ||
} | ||
} | ||
|
||
sealed class PlaylistSongFetchingState { | ||
object Pending : PlaylistSongFetchingState() | ||
data class Success(val data: Any) : PlaylistSongFetchingState() | ||
data class Error(val message: String) : PlaylistSongFetchingState() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters