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.annotation.LayoutRes
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.isVisible
|
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.ATHUtil
|
||||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||||
import code.name.monkey.retromusic.R
|
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.fragments.NowPlayingScreen.*
|
||||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||||
import code.name.monkey.retromusic.model.CategoryInfo
|
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.util.PreferenceUtil
|
||||||
import code.name.monkey.retromusic.views.BottomNavigationBarTinted
|
import code.name.monkey.retromusic.views.BottomNavigationBarTinted
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
|
@ -75,13 +76,11 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
|
||||||
setupSlidingUpPanel()
|
setupSlidingUpPanel()
|
||||||
|
|
||||||
setupBottomSheet()
|
setupBottomSheet()
|
||||||
|
updatePanelState()
|
||||||
libraryViewModel.paletteColorLiveData.observe(this, Observer {
|
updateColor()
|
||||||
this.paletteColor = it
|
|
||||||
onPaletteColorChanged()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun getBottomSheetBehavior() = behavior
|
fun getBottomSheetBehavior() = behavior
|
||||||
|
|
||||||
private fun setupBottomSheet() {
|
private fun setupBottomSheet() {
|
||||||
|
@ -201,7 +200,11 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
|
||||||
ViewTreeObserver.OnGlobalLayoutListener {
|
ViewTreeObserver.OnGlobalLayoutListener {
|
||||||
override fun onGlobalLayout() {
|
override fun onGlobalLayout() {
|
||||||
slidingPanel.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
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
|
} // 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() {
|
override fun onQueueChanged() {
|
||||||
super.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() {
|
override fun onBackPressed() {
|
||||||
|
@ -308,4 +320,59 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
|
||||||
bottomNavigationView.hide()
|
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.view.View
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.lifecycle.lifecycleScope
|
|
||||||
import androidx.navigation.fragment.navArgs
|
import androidx.navigation.fragment.navArgs
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
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.fragments.base.AbsMainActivityFragment
|
||||||
import code.name.monkey.retromusic.model.Album
|
import code.name.monkey.retromusic.model.Album
|
||||||
import code.name.monkey.retromusic.model.Artist
|
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.android.synthetic.main.fragment_playlist_detail.*
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
|
||||||
import kotlinx.coroutines.Dispatchers.Main
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import org.koin.android.ext.android.inject
|
|
||||||
|
|
||||||
class DetailListFragment : AbsMainActivityFragment(R.layout.fragment_playlist_detail),
|
class DetailListFragment : AbsMainActivityFragment(R.layout.fragment_playlist_detail),
|
||||||
ArtistClickListener, AlbumClickListener {
|
ArtistClickListener, AlbumClickListener {
|
||||||
private val args by navArgs<DetailListFragmentArgs>()
|
private val args by navArgs<DetailListFragmentArgs>()
|
||||||
private val repository by inject<RealRepository>()
|
private val libraryViewModel by sharedViewModel<LibraryViewModel>()
|
||||||
|
|
||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
super.onActivityCreated(savedInstanceState)
|
super.onActivityCreated(savedInstanceState)
|
||||||
|
libraryViewModel.setPanelState(NowPlayingPanelState.COLLAPSED_WITHOUT)
|
||||||
mainActivity.setSupportActionBar(toolbar)
|
mainActivity.setSupportActionBar(toolbar)
|
||||||
mainActivity.hideBottomBarVisibility(false)
|
|
||||||
progressIndicator.hide()
|
progressIndicator.hide()
|
||||||
when (args.type) {
|
when (args.type) {
|
||||||
TOP_ARTISTS -> {
|
TOP_ARTISTS -> {
|
||||||
|
@ -67,10 +62,9 @@ class DetailListFragment : AbsMainActivityFragment(R.layout.fragment_playlist_de
|
||||||
adapter = songAdapter
|
adapter = songAdapter
|
||||||
layoutManager = linearLayoutManager()
|
layoutManager = linearLayoutManager()
|
||||||
}
|
}
|
||||||
lifecycleScope.launch(IO) {
|
libraryViewModel.recentSongs().observe(viewLifecycleOwner, Observer { songs ->
|
||||||
val songs = repository.recentSongs()
|
songAdapter.swapDataSet(songs)
|
||||||
withContext(Main) { songAdapter.swapDataSet(songs) }
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun topPlayed() {
|
private fun topPlayed() {
|
||||||
|
@ -84,12 +78,10 @@ class DetailListFragment : AbsMainActivityFragment(R.layout.fragment_playlist_de
|
||||||
adapter = songAdapter
|
adapter = songAdapter
|
||||||
layoutManager = linearLayoutManager()
|
layoutManager = linearLayoutManager()
|
||||||
}
|
}
|
||||||
lifecycleScope.launch(IO) {
|
libraryViewModel.playCountSongs().observe(viewLifecycleOwner, Observer { songs ->
|
||||||
val songs = repository.playCountSongs().map {
|
songAdapter.swapDataSet(songs)
|
||||||
it.toSong()
|
})
|
||||||
}
|
|
||||||
withContext(Main) { songAdapter.swapDataSet(songs) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadHistory() {
|
private fun loadHistory() {
|
||||||
|
@ -104,7 +96,7 @@ class DetailListFragment : AbsMainActivityFragment(R.layout.fragment_playlist_de
|
||||||
adapter = songAdapter
|
adapter = songAdapter
|
||||||
layoutManager = linearLayoutManager()
|
layoutManager = linearLayoutManager()
|
||||||
}
|
}
|
||||||
repository.observableHistorySongs().observe(viewLifecycleOwner, Observer {
|
libraryViewModel.observableHistorySongs().observe(viewLifecycleOwner, Observer {
|
||||||
val songs = it.map { historyEntity -> historyEntity.toSong() }
|
val songs = it.map { historyEntity -> historyEntity.toSong() }
|
||||||
songAdapter.swapDataSet(songs)
|
songAdapter.swapDataSet(songs)
|
||||||
})
|
})
|
||||||
|
@ -121,8 +113,7 @@ class DetailListFragment : AbsMainActivityFragment(R.layout.fragment_playlist_de
|
||||||
adapter = songAdapter
|
adapter = songAdapter
|
||||||
layoutManager = linearLayoutManager()
|
layoutManager = linearLayoutManager()
|
||||||
}
|
}
|
||||||
repository.favorites().observe(viewLifecycleOwner, Observer {
|
libraryViewModel.favorites().observe(viewLifecycleOwner, {
|
||||||
println(it.size)
|
|
||||||
val songs = it.map { songEntity -> songEntity.toSong() }
|
val songs = it.map { songEntity -> songEntity.toSong() }
|
||||||
songAdapter.swapDataSet(songs)
|
songAdapter.swapDataSet(songs)
|
||||||
})
|
})
|
||||||
|
@ -130,31 +121,22 @@ class DetailListFragment : AbsMainActivityFragment(R.layout.fragment_playlist_de
|
||||||
|
|
||||||
private fun loadArtists(title: Int, type: Int) {
|
private fun loadArtists(title: Int, type: Int) {
|
||||||
toolbar.setTitle(title)
|
toolbar.setTitle(title)
|
||||||
lifecycleScope.launch(IO) {
|
libraryViewModel.artists(type).observe(viewLifecycleOwner, { artists ->
|
||||||
val artists =
|
recyclerView.apply {
|
||||||
if (type == TOP_ARTISTS) repository.topArtists() else repository.recentArtists()
|
adapter = artistAdapter(artists)
|
||||||
withContext(Main) {
|
layoutManager = gridLayoutManager()
|
||||||
recyclerView.apply {
|
|
||||||
adapter = artistAdapter(artists)
|
|
||||||
layoutManager = gridLayoutManager()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadAlbums(title: Int, type: Int) {
|
private fun loadAlbums(title: Int, type: Int) {
|
||||||
toolbar.setTitle(title)
|
toolbar.setTitle(title)
|
||||||
lifecycleScope.launch(IO) {
|
libraryViewModel.albums(type).observe(viewLifecycleOwner, { albums ->
|
||||||
val albums =
|
recyclerView.apply {
|
||||||
if (type == TOP_ALBUMS) repository.topAlbums() else repository.recentAlbums()
|
adapter = albumAdapter(albums)
|
||||||
withContext(Main) {
|
layoutManager = gridLayoutManager()
|
||||||
recyclerView.apply {
|
|
||||||
adapter = albumAdapter(albums)
|
|
||||||
layoutManager = gridLayoutManager()
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun artistAdapter(artists: List<Artist>): ArtistAdapter = ArtistAdapter(
|
private fun artistAdapter(artists: List<Artist>): ArtistAdapter = ArtistAdapter(
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
package code.name.monkey.retromusic.fragments
|
package code.name.monkey.retromusic.fragments
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.*
|
||||||
import androidx.lifecycle.MutableLiveData
|
import code.name.monkey.retromusic.RECENT_ALBUMS
|
||||||
import androidx.lifecycle.ViewModel
|
import code.name.monkey.retromusic.RECENT_ARTISTS
|
||||||
import androidx.lifecycle.viewModelScope
|
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.PlaylistEntity
|
||||||
import code.name.monkey.retromusic.db.PlaylistWithSongs
|
import code.name.monkey.retromusic.db.PlaylistWithSongs
|
||||||
import code.name.monkey.retromusic.db.SongEntity
|
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.fragments.ReloadType.*
|
||||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||||
import code.name.monkey.retromusic.interfaces.MusicServiceEventListener
|
import code.name.monkey.retromusic.interfaces.MusicServiceEventListener
|
||||||
import code.name.monkey.retromusic.model.*
|
import code.name.monkey.retromusic.model.*
|
||||||
import code.name.monkey.retromusic.repository.RealRepository
|
import code.name.monkey.retromusic.repository.RealRepository
|
||||||
|
import code.name.monkey.retromusic.state.NowPlayingPanelState
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
@ -19,7 +22,7 @@ class LibraryViewModel(
|
||||||
private val repository: RealRepository
|
private val repository: RealRepository
|
||||||
) : ViewModel(), MusicServiceEventListener {
|
) : ViewModel(), MusicServiceEventListener {
|
||||||
|
|
||||||
private val paletteColor = MutableLiveData<Int>()
|
private val _paletteColor = MutableLiveData<Int>()
|
||||||
private val albums = MutableLiveData<List<Album>>()
|
private val albums = MutableLiveData<List<Album>>()
|
||||||
private val songs = MutableLiveData<List<Song>>()
|
private val songs = MutableLiveData<List<Song>>()
|
||||||
private val artists = MutableLiveData<List<Artist>>()
|
private val artists = MutableLiveData<List<Artist>>()
|
||||||
|
@ -28,12 +31,17 @@ class LibraryViewModel(
|
||||||
private val genres = MutableLiveData<List<Genre>>()
|
private val genres = MutableLiveData<List<Genre>>()
|
||||||
private val home = MutableLiveData<List<Home>>()
|
private val home = MutableLiveData<List<Home>>()
|
||||||
|
|
||||||
val paletteColorLiveData: LiveData<Int> = paletteColor
|
val paletteColor: LiveData<Int> = _paletteColor
|
||||||
|
val panelState: MutableLiveData<NowPlayingPanelState> = MutableLiveData<NowPlayingPanelState>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
fetchHomeSections()
|
fetchHomeSections()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setPanelState(state: NowPlayingPanelState) {
|
||||||
|
panelState.postValue(state)
|
||||||
|
}
|
||||||
|
|
||||||
private fun loadLibraryContent() = viewModelScope.launch(IO) {
|
private fun loadLibraryContent() = viewModelScope.launch(IO) {
|
||||||
fetchHomeSections()
|
fetchHomeSections()
|
||||||
fetchSongs()
|
fetchSongs()
|
||||||
|
@ -132,7 +140,7 @@ class LibraryViewModel(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateColor(newColor: Int) {
|
fun updateColor(newColor: Int) {
|
||||||
paletteColor.postValue(newColor)
|
_paletteColor.postValue(newColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMediaStoreChanged() {
|
override fun onMediaStoreChanged() {
|
||||||
|
@ -232,6 +240,38 @@ class LibraryViewModel(
|
||||||
fetchPlaylists()
|
fetchPlaylists()
|
||||||
loadLibraryContent()
|
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 {
|
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.applyColor
|
||||||
import code.name.monkey.retromusic.extensions.applyOutlineColor
|
import code.name.monkey.retromusic.extensions.applyOutlineColor
|
||||||
import code.name.monkey.retromusic.extensions.show
|
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.fragments.base.AbsMainActivityFragment
|
||||||
import code.name.monkey.retromusic.glide.AlbumGlideRequest
|
import code.name.monkey.retromusic.glide.AlbumGlideRequest
|
||||||
import code.name.monkey.retromusic.glide.ArtistGlideRequest
|
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.Result
|
||||||
import code.name.monkey.retromusic.network.model.LastFmAlbum
|
import code.name.monkey.retromusic.network.model.LastFmAlbum
|
||||||
import code.name.monkey.retromusic.repository.RealRepository
|
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.MusicUtil
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
import code.name.monkey.retromusic.util.RetroUtil
|
import code.name.monkey.retromusic.util.RetroUtil
|
||||||
|
@ -52,6 +54,7 @@ import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.koin.android.ext.android.get
|
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.androidx.viewmodel.ext.android.viewModel
|
||||||
import org.koin.core.parameter.parametersOf
|
import org.koin.core.parameter.parametersOf
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -63,6 +66,7 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det
|
||||||
private val detailsViewModel by viewModel<AlbumDetailsViewModel> {
|
private val detailsViewModel by viewModel<AlbumDetailsViewModel> {
|
||||||
parametersOf(arguments.extraAlbumId)
|
parametersOf(arguments.extraAlbumId)
|
||||||
}
|
}
|
||||||
|
private val libraryViewModel by sharedViewModel<LibraryViewModel>()
|
||||||
|
|
||||||
private lateinit var simpleSongAdapter: SimpleSongAdapter
|
private lateinit var simpleSongAdapter: SimpleSongAdapter
|
||||||
private lateinit var album: Album
|
private lateinit var album: Album
|
||||||
|
@ -73,7 +77,7 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det
|
||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
super.onActivityCreated(savedInstanceState)
|
super.onActivityCreated(savedInstanceState)
|
||||||
setHasOptionsMenu(true)
|
setHasOptionsMenu(true)
|
||||||
mainActivity.hideBottomBarVisibility(false)
|
libraryViewModel.setPanelState(NowPlayingPanelState.COLLAPSED_WITHOUT)
|
||||||
mainActivity.addMusicServiceEventListener(detailsViewModel)
|
mainActivity.addMusicServiceEventListener(detailsViewModel)
|
||||||
mainActivity.setSupportActionBar(toolbar)
|
mainActivity.setSupportActionBar(toolbar)
|
||||||
toolbar.title = " "
|
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.applyOutlineColor
|
||||||
import code.name.monkey.retromusic.extensions.show
|
import code.name.monkey.retromusic.extensions.show
|
||||||
import code.name.monkey.retromusic.extensions.showToast
|
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.albums.AlbumClickListener
|
||||||
import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment
|
import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment
|
||||||
import code.name.monkey.retromusic.glide.ArtistGlideRequest
|
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.Result
|
||||||
import code.name.monkey.retromusic.network.model.LastFmArtist
|
import code.name.monkey.retromusic.network.model.LastFmArtist
|
||||||
import code.name.monkey.retromusic.repository.RealRepository
|
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.CustomArtistImageUtil
|
||||||
import code.name.monkey.retromusic.util.MusicUtil
|
import code.name.monkey.retromusic.util.MusicUtil
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
|
@ -47,6 +49,7 @@ import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.koin.android.ext.android.get
|
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.androidx.viewmodel.ext.android.viewModel
|
||||||
import org.koin.core.parameter.parametersOf
|
import org.koin.core.parameter.parametersOf
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -58,7 +61,7 @@ class ArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_artist_d
|
||||||
private val detailsViewModel: ArtistDetailsViewModel by viewModel {
|
private val detailsViewModel: ArtistDetailsViewModel by viewModel {
|
||||||
parametersOf(arguments.extraArtistId)
|
parametersOf(arguments.extraArtistId)
|
||||||
}
|
}
|
||||||
|
private val libraryViewModel by sharedViewModel<LibraryViewModel>()
|
||||||
private lateinit var artist: Artist
|
private lateinit var artist: Artist
|
||||||
private lateinit var songAdapter: SimpleSongAdapter
|
private lateinit var songAdapter: SimpleSongAdapter
|
||||||
private lateinit var albumAdapter: HorizontalAlbumAdapter
|
private lateinit var albumAdapter: HorizontalAlbumAdapter
|
||||||
|
@ -70,17 +73,17 @@ class ArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_artist_d
|
||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
super.onActivityCreated(savedInstanceState)
|
super.onActivityCreated(savedInstanceState)
|
||||||
setHasOptionsMenu(true)
|
setHasOptionsMenu(true)
|
||||||
|
libraryViewModel.setPanelState(NowPlayingPanelState.COLLAPSED_WITHOUT)
|
||||||
mainActivity.setSupportActionBar(toolbar)
|
mainActivity.setSupportActionBar(toolbar)
|
||||||
mainActivity.hideBottomBarVisibility(false)
|
|
||||||
toolbar.title = null
|
toolbar.title = null
|
||||||
setupRecyclerView()
|
setupRecyclerView()
|
||||||
|
|
||||||
postponeEnterTransition()
|
postponeEnterTransition()
|
||||||
detailsViewModel.getArtist().observe(viewLifecycleOwner, Observer {
|
detailsViewModel.getArtist().observe(viewLifecycleOwner, Observer {
|
||||||
showArtist(it)
|
|
||||||
startPostponedEnterTransition()
|
startPostponedEnterTransition()
|
||||||
|
showArtist(it)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
playAction.apply {
|
playAction.apply {
|
||||||
setOnClickListener { MusicPlayerRemote.openQueue(artist.songs, 0, true) }
|
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.R
|
||||||
import code.name.monkey.retromusic.adapter.song.SongAdapter
|
import code.name.monkey.retromusic.adapter.song.SongAdapter
|
||||||
import code.name.monkey.retromusic.extensions.dipToPix
|
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.fragments.base.AbsMainActivityFragment
|
||||||
import code.name.monkey.retromusic.helper.menu.GenreMenuHelper
|
import code.name.monkey.retromusic.helper.menu.GenreMenuHelper
|
||||||
import code.name.monkey.retromusic.model.Genre
|
import code.name.monkey.retromusic.model.Genre
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
|
import code.name.monkey.retromusic.state.NowPlayingPanelState
|
||||||
import kotlinx.android.synthetic.main.fragment_playlist_detail.*
|
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.androidx.viewmodel.ext.android.viewModel
|
||||||
import org.koin.core.parameter.parametersOf
|
import org.koin.core.parameter.parametersOf
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -26,7 +29,7 @@ class GenreDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playlist_
|
||||||
private val detailsViewModel: GenreDetailsViewModel by viewModel {
|
private val detailsViewModel: GenreDetailsViewModel by viewModel {
|
||||||
parametersOf(arguments.extraGenre)
|
parametersOf(arguments.extraGenre)
|
||||||
}
|
}
|
||||||
|
private val libraryViewModel by sharedViewModel<LibraryViewModel>()
|
||||||
private lateinit var genre: Genre
|
private lateinit var genre: Genre
|
||||||
private lateinit var songAdapter: SongAdapter
|
private lateinit var songAdapter: SongAdapter
|
||||||
|
|
||||||
|
@ -35,7 +38,7 @@ class GenreDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playlist_
|
||||||
setHasOptionsMenu(true)
|
setHasOptionsMenu(true)
|
||||||
mainActivity.addMusicServiceEventListener(detailsViewModel)
|
mainActivity.addMusicServiceEventListener(detailsViewModel)
|
||||||
mainActivity.setSupportActionBar(toolbar)
|
mainActivity.setSupportActionBar(toolbar)
|
||||||
mainActivity.hideBottomBarVisibility(false)
|
libraryViewModel.setPanelState(NowPlayingPanelState.COLLAPSED_WITHOUT)
|
||||||
progressIndicator.hide()
|
progressIndicator.hide()
|
||||||
setupRecyclerView()
|
setupRecyclerView()
|
||||||
detailsViewModel.getSongs().observe(viewLifecycleOwner, androidx.lifecycle.Observer {
|
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.PlaylistWithSongs
|
||||||
import code.name.monkey.retromusic.db.toSongs
|
import code.name.monkey.retromusic.db.toSongs
|
||||||
import code.name.monkey.retromusic.extensions.dipToPix
|
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.fragments.base.AbsMainActivityFragment
|
||||||
import code.name.monkey.retromusic.helper.menu.PlaylistMenuHelper
|
import code.name.monkey.retromusic.helper.menu.PlaylistMenuHelper
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
|
import code.name.monkey.retromusic.state.NowPlayingPanelState
|
||||||
import code.name.monkey.retromusic.util.PlaylistsUtil
|
import code.name.monkey.retromusic.util.PlaylistsUtil
|
||||||
import com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemAnimator
|
import com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemAnimator
|
||||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager
|
import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager
|
||||||
import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils
|
import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils
|
||||||
import kotlinx.android.synthetic.main.fragment_playlist_detail.*
|
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.androidx.viewmodel.ext.android.viewModel
|
||||||
import org.koin.core.parameter.parametersOf
|
import org.koin.core.parameter.parametersOf
|
||||||
|
|
||||||
|
@ -30,7 +33,7 @@ class PlaylistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playli
|
||||||
private val viewModel: PlaylistDetailsViewModel by viewModel {
|
private val viewModel: PlaylistDetailsViewModel by viewModel {
|
||||||
parametersOf(arguments.extraPlaylist)
|
parametersOf(arguments.extraPlaylist)
|
||||||
}
|
}
|
||||||
|
private val libraryViewModel by sharedViewModel<LibraryViewModel>()
|
||||||
private lateinit var playlist: PlaylistWithSongs
|
private lateinit var playlist: PlaylistWithSongs
|
||||||
private lateinit var adapter: SongAdapter
|
private lateinit var adapter: SongAdapter
|
||||||
|
|
||||||
|
@ -40,9 +43,9 @@ class PlaylistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playli
|
||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
super.onActivityCreated(savedInstanceState)
|
super.onActivityCreated(savedInstanceState)
|
||||||
setHasOptionsMenu(true)
|
setHasOptionsMenu(true)
|
||||||
|
libraryViewModel.setPanelState(NowPlayingPanelState.COLLAPSED_WITHOUT)
|
||||||
mainActivity.addMusicServiceEventListener(viewModel)
|
mainActivity.addMusicServiceEventListener(viewModel)
|
||||||
mainActivity.setSupportActionBar(toolbar)
|
mainActivity.setSupportActionBar(toolbar)
|
||||||
mainActivity.hideBottomBarVisibility(false)
|
|
||||||
|
|
||||||
playlist = arguments.extraPlaylist
|
playlist = arguments.extraPlaylist
|
||||||
toolbar.title = playlist.playlistEntity.playlistName
|
toolbar.title = playlist.playlistEntity.playlistName
|
||||||
|
|
|
@ -15,6 +15,6 @@ class SearchViewModel(private val realRepository: RealRepository) : ViewModel()
|
||||||
|
|
||||||
fun search(query: String?) = viewModelScope.launch(IO) {
|
fun search(query: String?) = viewModelScope.launch(IO) {
|
||||||
val result = realRepository.search(query)
|
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