From 03723b62eb90e1a58a0edad07ca4d1aba2d875da Mon Sep 17 00:00:00 2001 From: Hemanth S Date: Thu, 17 Sep 2020 23:26:59 +0530 Subject: [PATCH] Now playing state management --- .../base/AbsSlidingMusicPanelActivity.kt | 83 +++++++++++++++++-- .../fragments/DetailListFragment.kt | 64 +++++--------- .../retromusic/fragments/LibraryViewModel.kt | 54 ++++++++++-- .../fragments/albums/AlbumDetailsFragment.kt | 6 +- .../artists/ArtistDetailsFragment.kt | 13 +-- .../fragments/genres/GenreDetailsFragment.kt | 7 +- .../playlists/PlaylistDetailsFragment.kt | 7 +- .../fragments/search/SearchViewModel.kt | 2 +- .../retromusic/state/NowPlayingPanelState.kt | 8 ++ 9 files changed, 177 insertions(+), 67 deletions(-) create mode 100644 app/src/main/java/code/name/monkey/retromusic/state/NowPlayingPanelState.kt diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsSlidingMusicPanelActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsSlidingMusicPanelActivity.kt index 729adee2..c78c75da 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsSlidingMusicPanelActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsSlidingMusicPanelActivity.kt @@ -9,7 +9,7 @@ import android.widget.FrameLayout import androidx.annotation.LayoutRes import androidx.core.view.ViewCompat import androidx.core.view.isVisible -import androidx.lifecycle.Observer +import androidx.transition.TransitionManager import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.retromusic.R @@ -22,6 +22,7 @@ import code.name.monkey.retromusic.fragments.NowPlayingScreen import code.name.monkey.retromusic.fragments.NowPlayingScreen.* import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.model.CategoryInfo +import code.name.monkey.retromusic.state.NowPlayingPanelState.* import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.views.BottomNavigationBarTinted import com.google.android.material.bottomsheet.BottomSheetBehavior @@ -75,13 +76,11 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { setupSlidingUpPanel() setupBottomSheet() - - libraryViewModel.paletteColorLiveData.observe(this, Observer { - this.paletteColor = it - onPaletteColorChanged() - }) + updatePanelState() + updateColor() } + fun getBottomSheetBehavior() = behavior private fun setupBottomSheet() { @@ -201,7 +200,11 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { ViewTreeObserver.OnGlobalLayoutListener { override fun onGlobalLayout() { slidingPanel.viewTreeObserver.removeOnGlobalLayoutListener(this) - hideBottomBar(false) + if (bottomNavigationView.isVisible) { + libraryViewModel.setPanelState(COLLAPSED_WITH) + } else { + libraryViewModel.setPanelState(COLLAPSED_WITHOUT) + } } }) } // don't call hideBottomBar(true) here as it causes a bug with the SlidingUpPanelLayout @@ -209,7 +212,16 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { override fun onQueueChanged() { super.onQueueChanged() - hideBottomBar(MusicPlayerRemote.playingQueue.isEmpty()) + val isEmpty = MusicPlayerRemote.playingQueue.isEmpty() + if (isEmpty) { + libraryViewModel.setPanelState(HIDE) + } else { + if (bottomNavigationView.isVisible) { + libraryViewModel.setPanelState(EXPAND) + } else { + libraryViewModel.setPanelState(COLLAPSED_WITHOUT) + } + } } override fun onBackPressed() { @@ -308,4 +320,59 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { bottomNavigationView.hide() } } + + private fun updateColor() { + libraryViewModel.paletteColor.observe(this, { color -> + this.paletteColor = color + onPaletteColorChanged() + }) + } + + private fun updatePanelState() { + libraryViewModel.panelState.observe(this, { state -> + when (state) { + EXPAND -> { + println("EXPAND") + expandPanel() + } + HIDE -> { + println("HIDE") + behavior.isHideable = true + behavior.peekHeight = 0 + collapsePanel() + ViewCompat.setElevation(slidingPanel, 0f) + ViewCompat.setElevation(bottomNavigationView, 10f) + } + COLLAPSED_WITH -> { + println("COLLAPSED_WITH") + TransitionManager.beginDelayedTransition(mainContent) + bottomNavigationView.isVisible = true + val heightOfBar = bottomNavigationView.height + ViewCompat.setElevation(bottomNavigationView, 10f) + ViewCompat.setElevation(slidingPanel, 10f) + behavior.isHideable = false + behavior.peekHeight = (heightOfBar * 2) - 24 + } + COLLAPSED_WITHOUT -> { + println("COLLAPSED_WITHOUT") + TransitionManager.beginDelayedTransition(mainContent) + TransitionManager.beginDelayedTransition(slidingPanel) + val heightOfBar = bottomNavigationView.height + bottomNavigationView.isVisible = false + ViewCompat.setElevation(bottomNavigationView, 10f) + ViewCompat.setElevation(slidingPanel, 10f) + behavior.isHideable = false + behavior.peekHeight = heightOfBar - 24 + } + else -> { + println("ELSE") + behavior.isHideable = true + behavior.peekHeight = 0 + collapsePanel() + ViewCompat.setElevation(slidingPanel, 0f) + ViewCompat.setElevation(bottomNavigationView, 10f) + } + } + }) + } } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/DetailListFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/DetailListFragment.kt index 6c7230a5..c08611da 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/DetailListFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/DetailListFragment.kt @@ -4,7 +4,6 @@ import android.os.Bundle import android.view.View import android.widget.ImageView import androidx.lifecycle.Observer -import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.navArgs import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager @@ -18,23 +17,19 @@ import code.name.monkey.retromusic.fragments.artists.ArtistClickListener import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment import code.name.monkey.retromusic.model.Album import code.name.monkey.retromusic.model.Artist -import code.name.monkey.retromusic.repository.RealRepository +import code.name.monkey.retromusic.state.NowPlayingPanelState import kotlinx.android.synthetic.main.fragment_playlist_detail.* -import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.Dispatchers.Main -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import org.koin.android.ext.android.inject +import org.koin.androidx.viewmodel.ext.android.sharedViewModel class DetailListFragment : AbsMainActivityFragment(R.layout.fragment_playlist_detail), ArtistClickListener, AlbumClickListener { private val args by navArgs() - private val repository by inject() + private val libraryViewModel by sharedViewModel() override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) + libraryViewModel.setPanelState(NowPlayingPanelState.COLLAPSED_WITHOUT) mainActivity.setSupportActionBar(toolbar) - mainActivity.hideBottomBarVisibility(false) progressIndicator.hide() when (args.type) { TOP_ARTISTS -> { @@ -67,10 +62,9 @@ class DetailListFragment : AbsMainActivityFragment(R.layout.fragment_playlist_de adapter = songAdapter layoutManager = linearLayoutManager() } - lifecycleScope.launch(IO) { - val songs = repository.recentSongs() - withContext(Main) { songAdapter.swapDataSet(songs) } - } + libraryViewModel.recentSongs().observe(viewLifecycleOwner, Observer { songs -> + songAdapter.swapDataSet(songs) + }) } private fun topPlayed() { @@ -84,12 +78,10 @@ class DetailListFragment : AbsMainActivityFragment(R.layout.fragment_playlist_de adapter = songAdapter layoutManager = linearLayoutManager() } - lifecycleScope.launch(IO) { - val songs = repository.playCountSongs().map { - it.toSong() - } - withContext(Main) { songAdapter.swapDataSet(songs) } - } + libraryViewModel.playCountSongs().observe(viewLifecycleOwner, Observer { songs -> + songAdapter.swapDataSet(songs) + }) + } private fun loadHistory() { @@ -104,7 +96,7 @@ class DetailListFragment : AbsMainActivityFragment(R.layout.fragment_playlist_de adapter = songAdapter layoutManager = linearLayoutManager() } - repository.observableHistorySongs().observe(viewLifecycleOwner, Observer { + libraryViewModel.observableHistorySongs().observe(viewLifecycleOwner, Observer { val songs = it.map { historyEntity -> historyEntity.toSong() } songAdapter.swapDataSet(songs) }) @@ -121,8 +113,7 @@ class DetailListFragment : AbsMainActivityFragment(R.layout.fragment_playlist_de adapter = songAdapter layoutManager = linearLayoutManager() } - repository.favorites().observe(viewLifecycleOwner, Observer { - println(it.size) + libraryViewModel.favorites().observe(viewLifecycleOwner, { val songs = it.map { songEntity -> songEntity.toSong() } songAdapter.swapDataSet(songs) }) @@ -130,31 +121,22 @@ class DetailListFragment : AbsMainActivityFragment(R.layout.fragment_playlist_de private fun loadArtists(title: Int, type: Int) { toolbar.setTitle(title) - lifecycleScope.launch(IO) { - val artists = - if (type == TOP_ARTISTS) repository.topArtists() else repository.recentArtists() - withContext(Main) { - recyclerView.apply { - adapter = artistAdapter(artists) - layoutManager = gridLayoutManager() - } + libraryViewModel.artists(type).observe(viewLifecycleOwner, { artists -> + recyclerView.apply { + adapter = artistAdapter(artists) + layoutManager = gridLayoutManager() } - } + }) } private fun loadAlbums(title: Int, type: Int) { toolbar.setTitle(title) - lifecycleScope.launch(IO) { - val albums = - if (type == TOP_ALBUMS) repository.topAlbums() else repository.recentAlbums() - withContext(Main) { - recyclerView.apply { - adapter = albumAdapter(albums) - layoutManager = gridLayoutManager() - - } + libraryViewModel.albums(type).observe(viewLifecycleOwner, { albums -> + recyclerView.apply { + adapter = albumAdapter(albums) + layoutManager = gridLayoutManager() } - } + }) } private fun artistAdapter(artists: List): ArtistAdapter = ArtistAdapter( diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt index 3999ee70..07ed2acd 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt @@ -1,17 +1,20 @@ package code.name.monkey.retromusic.fragments -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope +import androidx.lifecycle.* +import code.name.monkey.retromusic.RECENT_ALBUMS +import code.name.monkey.retromusic.RECENT_ARTISTS +import code.name.monkey.retromusic.TOP_ALBUMS +import code.name.monkey.retromusic.TOP_ARTISTS import code.name.monkey.retromusic.db.PlaylistEntity import code.name.monkey.retromusic.db.PlaylistWithSongs import code.name.monkey.retromusic.db.SongEntity +import code.name.monkey.retromusic.db.toSong import code.name.monkey.retromusic.fragments.ReloadType.* import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.interfaces.MusicServiceEventListener import code.name.monkey.retromusic.model.* import code.name.monkey.retromusic.repository.RealRepository +import code.name.monkey.retromusic.state.NowPlayingPanelState import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch @@ -19,7 +22,7 @@ class LibraryViewModel( private val repository: RealRepository ) : ViewModel(), MusicServiceEventListener { - private val paletteColor = MutableLiveData() + private val _paletteColor = MutableLiveData() private val albums = MutableLiveData>() private val songs = MutableLiveData>() private val artists = MutableLiveData>() @@ -28,12 +31,17 @@ class LibraryViewModel( private val genres = MutableLiveData>() private val home = MutableLiveData>() - val paletteColorLiveData: LiveData = paletteColor + val paletteColor: LiveData = _paletteColor + val panelState: MutableLiveData = MutableLiveData() init { fetchHomeSections() } + fun setPanelState(state: NowPlayingPanelState) { + panelState.postValue(state) + } + private fun loadLibraryContent() = viewModelScope.launch(IO) { fetchHomeSections() fetchSongs() @@ -132,7 +140,7 @@ class LibraryViewModel( } fun updateColor(newColor: Int) { - paletteColor.postValue(newColor) + _paletteColor.postValue(newColor) } override fun onMediaStoreChanged() { @@ -232,6 +240,38 @@ class LibraryViewModel( fetchPlaylists() loadLibraryContent() } + + fun recentSongs(): LiveData> = liveData { + emit(repository.recentSongs()) + } + + fun playCountSongs(): LiveData> = liveData { + emit(repository.playCountSongs().map { + it.toSong() + }) + } + + fun observableHistorySongs() = repository.observableHistorySongs() + + fun favorites() = repository.favorites() + + fun artists(type: Int): LiveData> = liveData { + when (type) { + TOP_ARTISTS -> emit(repository.topArtists()) + RECENT_ARTISTS -> { + emit(repository.recentArtists()) + } + } + } + + fun albums(type: Int): LiveData> = liveData { + when (type) { + TOP_ALBUMS -> emit(repository.topAlbums()) + RECENT_ALBUMS -> { + emit(repository.recentAlbums()) + } + } + } } enum class ReloadType { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumDetailsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumDetailsFragment.kt index bade59ff..e1e4fc87 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumDetailsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumDetailsFragment.kt @@ -29,6 +29,7 @@ import code.name.monkey.retromusic.dialogs.DeleteSongsDialog import code.name.monkey.retromusic.extensions.applyColor import code.name.monkey.retromusic.extensions.applyOutlineColor import code.name.monkey.retromusic.extensions.show +import code.name.monkey.retromusic.fragments.LibraryViewModel import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment import code.name.monkey.retromusic.glide.AlbumGlideRequest import code.name.monkey.retromusic.glide.ArtistGlideRequest @@ -41,6 +42,7 @@ import code.name.monkey.retromusic.model.Artist import code.name.monkey.retromusic.network.Result import code.name.monkey.retromusic.network.model.LastFmAlbum import code.name.monkey.retromusic.repository.RealRepository +import code.name.monkey.retromusic.state.NowPlayingPanelState import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.RetroUtil @@ -52,6 +54,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.koin.android.ext.android.get +import org.koin.androidx.viewmodel.ext.android.sharedViewModel import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.core.parameter.parametersOf import java.util.* @@ -63,6 +66,7 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det private val detailsViewModel by viewModel { parametersOf(arguments.extraAlbumId) } + private val libraryViewModel by sharedViewModel() private lateinit var simpleSongAdapter: SimpleSongAdapter private lateinit var album: Album @@ -73,7 +77,7 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) setHasOptionsMenu(true) - mainActivity.hideBottomBarVisibility(false) + libraryViewModel.setPanelState(NowPlayingPanelState.COLLAPSED_WITHOUT) mainActivity.addMusicServiceEventListener(detailsViewModel) mainActivity.setSupportActionBar(toolbar) toolbar.title = " " diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistDetailsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistDetailsFragment.kt index 877def06..45469fb5 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistDetailsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistDetailsFragment.kt @@ -27,6 +27,7 @@ import code.name.monkey.retromusic.extensions.applyColor import code.name.monkey.retromusic.extensions.applyOutlineColor import code.name.monkey.retromusic.extensions.show import code.name.monkey.retromusic.extensions.showToast +import code.name.monkey.retromusic.fragments.LibraryViewModel import code.name.monkey.retromusic.fragments.albums.AlbumClickListener import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment import code.name.monkey.retromusic.glide.ArtistGlideRequest @@ -36,6 +37,7 @@ import code.name.monkey.retromusic.model.Artist import code.name.monkey.retromusic.network.Result import code.name.monkey.retromusic.network.model.LastFmArtist import code.name.monkey.retromusic.repository.RealRepository +import code.name.monkey.retromusic.state.NowPlayingPanelState import code.name.monkey.retromusic.util.CustomArtistImageUtil import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.PreferenceUtil @@ -47,6 +49,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.koin.android.ext.android.get +import org.koin.androidx.viewmodel.ext.android.sharedViewModel import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.core.parameter.parametersOf import java.util.* @@ -58,7 +61,7 @@ class ArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_artist_d private val detailsViewModel: ArtistDetailsViewModel by viewModel { parametersOf(arguments.extraArtistId) } - + private val libraryViewModel by sharedViewModel() private lateinit var artist: Artist private lateinit var songAdapter: SimpleSongAdapter private lateinit var albumAdapter: HorizontalAlbumAdapter @@ -70,17 +73,17 @@ class ArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_artist_d override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) setHasOptionsMenu(true) + libraryViewModel.setPanelState(NowPlayingPanelState.COLLAPSED_WITHOUT) mainActivity.setSupportActionBar(toolbar) - mainActivity.hideBottomBarVisibility(false) + toolbar.title = null setupRecyclerView() + postponeEnterTransition() detailsViewModel.getArtist().observe(viewLifecycleOwner, Observer { - showArtist(it) startPostponedEnterTransition() + showArtist(it) }) - - playAction.apply { setOnClickListener { MusicPlayerRemote.openQueue(artist.songs, 0, true) } } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/genres/GenreDetailsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/genres/GenreDetailsFragment.kt index fef2df72..8a5f7d52 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/genres/GenreDetailsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/genres/GenreDetailsFragment.kt @@ -12,11 +12,14 @@ import androidx.recyclerview.widget.RecyclerView import code.name.monkey.retromusic.R import code.name.monkey.retromusic.adapter.song.SongAdapter import code.name.monkey.retromusic.extensions.dipToPix +import code.name.monkey.retromusic.fragments.LibraryViewModel import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment import code.name.monkey.retromusic.helper.menu.GenreMenuHelper import code.name.monkey.retromusic.model.Genre import code.name.monkey.retromusic.model.Song +import code.name.monkey.retromusic.state.NowPlayingPanelState import kotlinx.android.synthetic.main.fragment_playlist_detail.* +import org.koin.androidx.viewmodel.ext.android.sharedViewModel import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.core.parameter.parametersOf import java.util.* @@ -26,7 +29,7 @@ class GenreDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playlist_ private val detailsViewModel: GenreDetailsViewModel by viewModel { parametersOf(arguments.extraGenre) } - + private val libraryViewModel by sharedViewModel() private lateinit var genre: Genre private lateinit var songAdapter: SongAdapter @@ -35,7 +38,7 @@ class GenreDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playlist_ setHasOptionsMenu(true) mainActivity.addMusicServiceEventListener(detailsViewModel) mainActivity.setSupportActionBar(toolbar) - mainActivity.hideBottomBarVisibility(false) + libraryViewModel.setPanelState(NowPlayingPanelState.COLLAPSED_WITHOUT) progressIndicator.hide() setupRecyclerView() detailsViewModel.getSongs().observe(viewLifecycleOwner, androidx.lifecycle.Observer { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/playlists/PlaylistDetailsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/playlists/PlaylistDetailsFragment.kt index a47e29a6..641cab49 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/playlists/PlaylistDetailsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/playlists/PlaylistDetailsFragment.kt @@ -14,14 +14,17 @@ import code.name.monkey.retromusic.adapter.song.SongAdapter import code.name.monkey.retromusic.db.PlaylistWithSongs import code.name.monkey.retromusic.db.toSongs import code.name.monkey.retromusic.extensions.dipToPix +import code.name.monkey.retromusic.fragments.LibraryViewModel import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment import code.name.monkey.retromusic.helper.menu.PlaylistMenuHelper import code.name.monkey.retromusic.model.Song +import code.name.monkey.retromusic.state.NowPlayingPanelState import code.name.monkey.retromusic.util.PlaylistsUtil import com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemAnimator import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils import kotlinx.android.synthetic.main.fragment_playlist_detail.* +import org.koin.androidx.viewmodel.ext.android.sharedViewModel import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.core.parameter.parametersOf @@ -30,7 +33,7 @@ class PlaylistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playli private val viewModel: PlaylistDetailsViewModel by viewModel { parametersOf(arguments.extraPlaylist) } - + private val libraryViewModel by sharedViewModel() private lateinit var playlist: PlaylistWithSongs private lateinit var adapter: SongAdapter @@ -40,9 +43,9 @@ class PlaylistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playli override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) setHasOptionsMenu(true) + libraryViewModel.setPanelState(NowPlayingPanelState.COLLAPSED_WITHOUT) mainActivity.addMusicServiceEventListener(viewModel) mainActivity.setSupportActionBar(toolbar) - mainActivity.hideBottomBarVisibility(false) playlist = arguments.extraPlaylist toolbar.title = playlist.playlistEntity.playlistName diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/search/SearchViewModel.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/search/SearchViewModel.kt index 50681023..adeb09c8 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/search/SearchViewModel.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/search/SearchViewModel.kt @@ -15,6 +15,6 @@ class SearchViewModel(private val realRepository: RealRepository) : ViewModel() fun search(query: String?) = viewModelScope.launch(IO) { val result = realRepository.search(query) - results.value = result + results.postValue(result) } } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/state/NowPlayingPanelState.kt b/app/src/main/java/code/name/monkey/retromusic/state/NowPlayingPanelState.kt new file mode 100644 index 00000000..b142f143 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/state/NowPlayingPanelState.kt @@ -0,0 +1,8 @@ +package code.name.monkey.retromusic.state + +enum class NowPlayingPanelState { + EXPAND, + COLLAPSED_WITH, + COLLAPSED_WITHOUT, + HIDE, +} \ No newline at end of file