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