Code Cleanup
This commit is contained in:
parent
943de60f23
commit
fd03cb4e99
2 changed files with 19 additions and 34 deletions
|
@ -97,34 +97,25 @@ class LibraryViewModel(
|
|||
return fabMargin
|
||||
}
|
||||
|
||||
private fun fetchSongs() {
|
||||
viewModelScope.launch(IO) {
|
||||
songs.postValue(repository.allSongs())
|
||||
}
|
||||
private suspend fun fetchSongs() {
|
||||
songs.postValue(repository.allSongs())
|
||||
}
|
||||
|
||||
private fun fetchAlbums() {
|
||||
viewModelScope.launch(IO) {
|
||||
albums.postValue(repository.fetchAlbums())
|
||||
}
|
||||
private suspend fun fetchAlbums() {
|
||||
albums.postValue(repository.fetchAlbums())
|
||||
|
||||
}
|
||||
|
||||
private fun fetchArtists() {
|
||||
private suspend fun fetchArtists() {
|
||||
if (PreferenceUtil.albumArtistsOnly) {
|
||||
viewModelScope.launch(IO) {
|
||||
artists.postValue(repository.albumArtists())
|
||||
}
|
||||
artists.postValue(repository.albumArtists())
|
||||
} else {
|
||||
viewModelScope.launch(IO) {
|
||||
artists.postValue(repository.fetchArtists())
|
||||
}
|
||||
artists.postValue(repository.fetchArtists())
|
||||
}
|
||||
}
|
||||
|
||||
private fun fetchPlaylists() {
|
||||
viewModelScope.launch(IO) {
|
||||
playlists.postValue(repository.fetchPlaylistWithSongs())
|
||||
}
|
||||
private suspend fun fetchPlaylists() {
|
||||
playlists.postValue(repository.fetchPlaylistWithSongs())
|
||||
}
|
||||
|
||||
private fun fetchLegacyPlaylist() {
|
||||
|
@ -133,16 +124,12 @@ class LibraryViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
private fun fetchGenres() {
|
||||
viewModelScope.launch(IO) {
|
||||
genres.postValue(repository.fetchGenres())
|
||||
}
|
||||
private suspend fun fetchGenres() {
|
||||
genres.postValue(repository.fetchGenres())
|
||||
}
|
||||
|
||||
fun fetchHomeSections() {
|
||||
viewModelScope.launch(IO) {
|
||||
home.postValue(repository.homeSections())
|
||||
}
|
||||
private suspend fun fetchHomeSections() {
|
||||
home.postValue(repository.homeSections())
|
||||
}
|
||||
|
||||
fun search(query: String?, filter: Filter) {
|
||||
|
@ -152,7 +139,7 @@ class LibraryViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
fun forceReload(reloadType: ReloadType) = viewModelScope.launch {
|
||||
fun forceReload(reloadType: ReloadType) = viewModelScope.launch(IO) {
|
||||
when (reloadType) {
|
||||
Songs -> fetchSongs()
|
||||
Albums -> fetchAlbums()
|
||||
|
@ -256,7 +243,7 @@ class LibraryViewModel(
|
|||
}
|
||||
repository.insertSongs(songEntities)
|
||||
} else {
|
||||
if (playlist != Playlist.empty){
|
||||
if (playlist != Playlist.empty) {
|
||||
val playListId = createPlaylist(PlaylistEntity(playlistName = playlist.name))
|
||||
val songEntities = playlist.getSongs().map {
|
||||
it.toSongEntity(playListId)
|
||||
|
@ -381,15 +368,12 @@ class LibraryViewModel(
|
|||
}
|
||||
|
||||
fun setFabMargin(bottomMargin: Int) {
|
||||
println("Bottom Margin $bottomMargin")
|
||||
val currentValue = DensityUtil.dip2px(App.getContext(), 16F) +
|
||||
bottomMargin
|
||||
ValueAnimator.ofInt(fabMargin.value!!, currentValue).apply {
|
||||
addUpdateListener {
|
||||
fabMargin.postValue(
|
||||
(it.animatedValue as Int).also { bottomMarginAnimated ->
|
||||
println("Bottom Margin Animated $bottomMarginAnimated")
|
||||
}
|
||||
(it.animatedValue as Int)
|
||||
)
|
||||
}
|
||||
doOnEnd {
|
||||
|
|
|
@ -39,6 +39,7 @@ import code.name.monkey.retromusic.dialogs.ImportPlaylistDialog
|
|||
import code.name.monkey.retromusic.extensions.accentColor
|
||||
import code.name.monkey.retromusic.extensions.drawNextToNavbar
|
||||
import code.name.monkey.retromusic.extensions.elevatedAccentColor
|
||||
import code.name.monkey.retromusic.fragments.ReloadType
|
||||
import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment
|
||||
import code.name.monkey.retromusic.glide.GlideApp
|
||||
import code.name.monkey.retromusic.glide.RetroGlideExtension
|
||||
|
@ -270,7 +271,7 @@ class HomeFragment :
|
|||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
libraryViewModel.fetchHomeSections()
|
||||
libraryViewModel.forceReload(ReloadType.HomeSections)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue