Now playing state management
This commit is contained in:
parent
90bca59192
commit
03723b62eb
9 changed files with 177 additions and 67 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -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<DetailListFragmentArgs>()
|
||||
private val repository by inject<RealRepository>()
|
||||
private val libraryViewModel by sharedViewModel<LibraryViewModel>()
|
||||
|
||||
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<Artist>): ArtistAdapter = ArtistAdapter(
|
||||
|
|
|
@ -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<Int>()
|
||||
private val _paletteColor = MutableLiveData<Int>()
|
||||
private val albums = MutableLiveData<List<Album>>()
|
||||
private val songs = MutableLiveData<List<Song>>()
|
||||
private val artists = MutableLiveData<List<Artist>>()
|
||||
|
@ -28,12 +31,17 @@ class LibraryViewModel(
|
|||
private val genres = MutableLiveData<List<Genre>>()
|
||||
private val home = MutableLiveData<List<Home>>()
|
||||
|
||||
val paletteColorLiveData: LiveData<Int> = paletteColor
|
||||
val paletteColor: LiveData<Int> = _paletteColor
|
||||
val panelState: MutableLiveData<NowPlayingPanelState> = MutableLiveData<NowPlayingPanelState>()
|
||||
|
||||
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<List<Song>> = liveData {
|
||||
emit(repository.recentSongs())
|
||||
}
|
||||
|
||||
fun playCountSongs(): LiveData<List<Song>> = liveData {
|
||||
emit(repository.playCountSongs().map {
|
||||
it.toSong()
|
||||
})
|
||||
}
|
||||
|
||||
fun observableHistorySongs() = repository.observableHistorySongs()
|
||||
|
||||
fun favorites() = repository.favorites()
|
||||
|
||||
fun artists(type: Int): LiveData<List<Artist>> = liveData {
|
||||
when (type) {
|
||||
TOP_ARTISTS -> emit(repository.topArtists())
|
||||
RECENT_ARTISTS -> {
|
||||
emit(repository.recentArtists())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun albums(type: Int): LiveData<List<Album>> = liveData {
|
||||
when (type) {
|
||||
TOP_ALBUMS -> emit(repository.topAlbums())
|
||||
RECENT_ALBUMS -> {
|
||||
emit(repository.recentAlbums())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class ReloadType {
|
||||
|
|
|
@ -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<AlbumDetailsViewModel> {
|
||||
parametersOf(arguments.extraAlbumId)
|
||||
}
|
||||
private val libraryViewModel by sharedViewModel<LibraryViewModel>()
|
||||
|
||||
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 = " "
|
||||
|
|
|
@ -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<LibraryViewModel>()
|
||||
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) }
|
||||
}
|
||||
|
|
|
@ -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<LibraryViewModel>()
|
||||
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 {
|
||||
|
|
|
@ -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<LibraryViewModel>()
|
||||
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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package code.name.monkey.retromusic.state
|
||||
|
||||
enum class NowPlayingPanelState {
|
||||
EXPAND,
|
||||
COLLAPSED_WITH,
|
||||
COLLAPSED_WITHOUT,
|
||||
HIDE,
|
||||
}
|
Loading…
Reference in a new issue