Code Cleanup

This commit is contained in:
Prathamesh More 2022-01-05 16:01:44 +05:30
parent 943de60f23
commit fd03cb4e99
2 changed files with 19 additions and 34 deletions

View file

@ -97,35 +97,26 @@ class LibraryViewModel(
return fabMargin
}
private fun fetchSongs() {
viewModelScope.launch(IO) {
private suspend fun fetchSongs() {
songs.postValue(repository.allSongs())
}
}
private fun fetchAlbums() {
viewModelScope.launch(IO) {
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())
}
} else {
viewModelScope.launch(IO) {
artists.postValue(repository.fetchArtists())
}
}
}
private fun fetchPlaylists() {
viewModelScope.launch(IO) {
private suspend fun fetchPlaylists() {
playlists.postValue(repository.fetchPlaylistWithSongs())
}
}
private fun fetchLegacyPlaylist() {
viewModelScope.launch(IO) {
@ -133,17 +124,13 @@ class LibraryViewModel(
}
}
private fun fetchGenres() {
viewModelScope.launch(IO) {
private suspend fun fetchGenres() {
genres.postValue(repository.fetchGenres())
}
}
fun fetchHomeSections() {
viewModelScope.launch(IO) {
private suspend fun fetchHomeSections() {
home.postValue(repository.homeSections())
}
}
fun search(query: String?, filter: Filter) {
viewModelScope.launch(IO) {
@ -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()
@ -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 {

View file

@ -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() {