Fixed incorrect toast after adding songs to playlist
This commit is contained in:
parent
b143419520
commit
55b3ec81b6
1 changed files with 9 additions and 17 deletions
|
@ -16,6 +16,7 @@ package code.name.monkey.retromusic.fragments
|
||||||
|
|
||||||
import android.animation.ValueAnimator
|
import android.animation.ValueAnimator
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.core.animation.doOnEnd
|
import androidx.core.animation.doOnEnd
|
||||||
import androidx.lifecycle.*
|
import androidx.lifecycle.*
|
||||||
import code.name.monkey.retromusic.*
|
import code.name.monkey.retromusic.*
|
||||||
|
@ -46,7 +47,6 @@ class LibraryViewModel(
|
||||||
private val songs = MutableLiveData<List<Song>>()
|
private val songs = MutableLiveData<List<Song>>()
|
||||||
private val artists = MutableLiveData<List<Artist>>()
|
private val artists = MutableLiveData<List<Artist>>()
|
||||||
private val playlists = MutableLiveData<List<PlaylistWithSongs>>()
|
private val playlists = MutableLiveData<List<PlaylistWithSongs>>()
|
||||||
private val legacyPlaylists = MutableLiveData<List<Playlist>>()
|
|
||||||
private val genres = MutableLiveData<List<Genre>>()
|
private val genres = MutableLiveData<List<Genre>>()
|
||||||
private val searchResults = MutableLiveData<List<Any>>()
|
private val searchResults = MutableLiveData<List<Any>>()
|
||||||
private val fabMargin = MutableLiveData(0)
|
private val fabMargin = MutableLiveData(0)
|
||||||
|
@ -78,8 +78,6 @@ class LibraryViewModel(
|
||||||
|
|
||||||
fun getPlaylists(): LiveData<List<PlaylistWithSongs>> = playlists
|
fun getPlaylists(): LiveData<List<PlaylistWithSongs>> = playlists
|
||||||
|
|
||||||
fun getLegacyPlaylist(): LiveData<List<Playlist>> = legacyPlaylists
|
|
||||||
|
|
||||||
fun getGenre(): LiveData<List<Genre>> = genres
|
fun getGenre(): LiveData<List<Genre>> = genres
|
||||||
|
|
||||||
fun getHome(): LiveData<List<Home>> = home
|
fun getHome(): LiveData<List<Home>> = home
|
||||||
|
@ -108,12 +106,6 @@ class LibraryViewModel(
|
||||||
playlists.postValue(repository.fetchPlaylistWithSongs())
|
playlists.postValue(repository.fetchPlaylistWithSongs())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchLegacyPlaylist() {
|
|
||||||
viewModelScope.launch(IO) {
|
|
||||||
legacyPlaylists.postValue(repository.fetchLegacyPlaylist())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun fetchGenres() {
|
private suspend fun fetchGenres() {
|
||||||
genres.postValue(repository.fetchGenres())
|
genres.postValue(repository.fetchGenres())
|
||||||
}
|
}
|
||||||
|
@ -249,12 +241,6 @@ class LibraryViewModel(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteTracks(songs: List<Song>) = viewModelScope.launch(IO) {
|
|
||||||
repository.deleteSongs(songs)
|
|
||||||
fetchPlaylists()
|
|
||||||
loadLibraryContent()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun recentSongs(): LiveData<List<Song>> = liveData(IO) {
|
fun recentSongs(): LiveData<List<Song>> = liveData(IO) {
|
||||||
emit(repository.recentSongs())
|
emit(repository.recentSongs())
|
||||||
}
|
}
|
||||||
|
@ -348,7 +334,8 @@ class LibraryViewModel(
|
||||||
createPlaylist(PlaylistEntity(playlistName = playlistName))
|
createPlaylist(PlaylistEntity(playlistName = playlistName))
|
||||||
insertSongs(songs.map { it.toSongEntity(playlistId) })
|
insertSongs(songs.map { it.toSongEntity(playlistId) })
|
||||||
withContext(Main) {
|
withContext(Main) {
|
||||||
context.showToast(R.string.playlist_created_sucessfully)
|
context.showToast(context.getString(R.string.playlist_created_sucessfully,
|
||||||
|
playlistName))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val playlist = playlists.firstOrNull()
|
val playlist = playlists.firstOrNull()
|
||||||
|
@ -360,7 +347,12 @@ class LibraryViewModel(
|
||||||
}
|
}
|
||||||
forceReload(Playlists)
|
forceReload(Playlists)
|
||||||
withContext(Main) {
|
withContext(Main) {
|
||||||
context.showToast(R.string.added_song_count_to_playlist)
|
context.showToast(
|
||||||
|
context.getString(
|
||||||
|
R.string.added_song_count_to_playlist,
|
||||||
|
songs.size,
|
||||||
|
playlistName),
|
||||||
|
Toast.LENGTH_SHORT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue