2019-04-20 05:29:45 +00:00
|
|
|
package code.name.monkey.retromusic.activities
|
2018-12-06 08:52:57 +00:00
|
|
|
|
2019-03-25 12:43:43 +00:00
|
|
|
import android.content.res.ColorStateList
|
2018-12-06 08:52:57 +00:00
|
|
|
import android.os.Bundle
|
2019-05-22 15:15:17 +00:00
|
|
|
import android.view.MenuItem
|
2018-12-06 08:52:57 +00:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
import code.name.monkey.appthemehelper.ThemeStore
|
2019-10-09 13:46:25 +00:00
|
|
|
import code.name.monkey.appthemehelper.util.ATHUtil
|
2019-03-25 12:43:43 +00:00
|
|
|
import code.name.monkey.appthemehelper.util.ColorUtil
|
|
|
|
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
2018-12-06 08:52:57 +00:00
|
|
|
import code.name.monkey.retromusic.R
|
2019-04-20 05:29:45 +00:00
|
|
|
import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity
|
|
|
|
import code.name.monkey.retromusic.adapter.song.PlayingQueueAdapter
|
2019-05-20 19:38:43 +00:00
|
|
|
import code.name.monkey.retromusic.extensions.applyToolbar
|
|
|
|
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
2018-12-06 08:52:57 +00:00
|
|
|
import code.name.monkey.retromusic.util.MusicUtil
|
2019-11-12 17:35:17 +00:00
|
|
|
import code.name.monkey.retromusic.util.ViewUtil
|
2018-12-06 08:52:57 +00:00
|
|
|
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.activity_playing_queue.*
|
|
|
|
|
|
|
|
|
2019-10-29 16:16:05 +00:00
|
|
|
open class PlayingQueueActivity : AbsMusicServiceActivity() {
|
2018-12-06 08:52:57 +00:00
|
|
|
|
|
|
|
private var wrappedAdapter: RecyclerView.Adapter<*>? = null
|
|
|
|
private var recyclerViewDragDropManager: RecyclerViewDragDropManager? = null
|
|
|
|
private var playingQueueAdapter: PlayingQueueAdapter? = null
|
2018-12-08 03:33:02 +00:00
|
|
|
private lateinit var linearLayoutManager: LinearLayoutManager
|
2018-12-06 08:52:57 +00:00
|
|
|
|
2019-09-03 17:54:14 +00:00
|
|
|
|
2019-10-29 16:16:05 +00:00
|
|
|
private fun getUpNextAndQueueTime(): String {
|
2019-09-03 17:54:14 +00:00
|
|
|
val duration = MusicPlayerRemote.getQueueDurationMillis(MusicPlayerRemote.position)
|
|
|
|
|
|
|
|
return MusicUtil.buildInfoString(
|
|
|
|
resources.getString(R.string.up_next),
|
|
|
|
MusicUtil.getReadableDurationString(duration)
|
|
|
|
)
|
|
|
|
}
|
2018-12-06 08:52:57 +00:00
|
|
|
|
2019-08-05 17:44:05 +00:00
|
|
|
override fun onCreate(
|
|
|
|
savedInstanceState: Bundle?
|
|
|
|
) {
|
2018-12-06 08:52:57 +00:00
|
|
|
super.onCreate(savedInstanceState)
|
2019-09-28 17:52:49 +00:00
|
|
|
setContentView(R.layout.activity_playing_queue)
|
2018-12-06 08:52:57 +00:00
|
|
|
|
|
|
|
setStatusbarColorAuto()
|
2019-09-28 17:52:49 +00:00
|
|
|
setNavigationBarColorPrimary()
|
2018-12-06 08:52:57 +00:00
|
|
|
setTaskDescriptionColorAuto()
|
|
|
|
setLightNavigationBar(true)
|
|
|
|
|
|
|
|
setupToolbar()
|
|
|
|
setUpRecyclerView()
|
|
|
|
|
|
|
|
clearQueue.setOnClickListener {
|
|
|
|
MusicPlayerRemote.clearQueue()
|
|
|
|
}
|
2019-10-29 16:16:05 +00:00
|
|
|
checkForPadding()
|
2018-12-06 08:52:57 +00:00
|
|
|
}
|
|
|
|
|
2019-05-22 15:15:17 +00:00
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
|
|
return when (item.itemId) {
|
|
|
|
android.R.id.home -> {
|
|
|
|
onBackPressed()
|
|
|
|
true
|
|
|
|
}
|
|
|
|
else -> super.onOptionsItemSelected(item)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 08:52:57 +00:00
|
|
|
private fun setUpRecyclerView() {
|
|
|
|
recyclerViewDragDropManager = RecyclerViewDragDropManager()
|
|
|
|
val animator = RefactoredDefaultItemAnimator()
|
|
|
|
|
|
|
|
playingQueueAdapter = PlayingQueueAdapter(
|
|
|
|
this,
|
|
|
|
MusicPlayerRemote.playingQueue,
|
|
|
|
MusicPlayerRemote.position,
|
2019-10-10 18:57:44 +00:00
|
|
|
R.layout.item_queue)
|
2019-10-29 16:16:05 +00:00
|
|
|
wrappedAdapter = recyclerViewDragDropManager?.createWrappedAdapter(playingQueueAdapter!!)
|
2018-12-06 08:52:57 +00:00
|
|
|
|
2018-12-08 03:33:02 +00:00
|
|
|
linearLayoutManager = LinearLayoutManager(this)
|
2018-12-06 08:52:57 +00:00
|
|
|
|
|
|
|
recyclerView.apply {
|
2018-12-08 03:33:02 +00:00
|
|
|
layoutManager = linearLayoutManager
|
2018-12-06 08:52:57 +00:00
|
|
|
adapter = wrappedAdapter
|
|
|
|
itemAnimator = animator
|
2019-10-29 16:16:05 +00:00
|
|
|
recyclerViewDragDropManager?.attachRecyclerView(this)
|
2018-12-06 08:52:57 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 03:33:02 +00:00
|
|
|
linearLayoutManager.scrollToPositionWithOffset(MusicPlayerRemote.position + 1, 0)
|
2018-12-06 08:52:57 +00:00
|
|
|
|
|
|
|
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
|
|
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
|
|
|
super.onScrolled(recyclerView, dx, dy)
|
|
|
|
if (dy > 0) {
|
2019-09-28 17:52:49 +00:00
|
|
|
clearQueue.shrink()
|
2018-12-06 08:52:57 +00:00
|
|
|
} else if (dy < 0) {
|
2019-09-28 17:52:49 +00:00
|
|
|
clearQueue.extend()
|
2018-12-06 08:52:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2019-11-12 17:35:17 +00:00
|
|
|
ViewUtil.setUpFastScrollRecyclerViewColor(this, recyclerView)
|
2018-12-06 08:52:57 +00:00
|
|
|
}
|
|
|
|
|
2019-10-29 16:16:05 +00:00
|
|
|
private fun checkForPadding() {
|
2019-11-13 13:07:44 +00:00
|
|
|
|
2019-10-29 16:16:05 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 08:52:57 +00:00
|
|
|
override fun onQueueChanged() {
|
|
|
|
if (MusicPlayerRemote.playingQueue.isEmpty()) {
|
|
|
|
finish()
|
|
|
|
return
|
|
|
|
}
|
2019-10-29 16:16:05 +00:00
|
|
|
checkForPadding()
|
2018-12-06 08:52:57 +00:00
|
|
|
updateQueue()
|
|
|
|
updateCurrentSong()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onMediaStoreChanged() {
|
|
|
|
updateQueue()
|
|
|
|
updateCurrentSong()
|
|
|
|
}
|
|
|
|
|
2019-09-03 17:54:14 +00:00
|
|
|
private fun updateCurrentSong() {
|
|
|
|
playerQueueSubHeader.text = getUpNextAndQueueTime()
|
|
|
|
}
|
2018-12-06 08:52:57 +00:00
|
|
|
|
|
|
|
override fun onPlayingMetaChanged() {
|
|
|
|
updateQueuePosition()
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun updateQueuePosition() {
|
2019-10-29 16:16:05 +00:00
|
|
|
playingQueueAdapter?.setCurrent(MusicPlayerRemote.position)
|
2018-12-06 08:52:57 +00:00
|
|
|
resetToCurrentPosition()
|
2019-09-03 17:54:14 +00:00
|
|
|
playerQueueSubHeader.text = getUpNextAndQueueTime()
|
2018-12-06 08:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun updateQueue() {
|
2019-10-29 16:16:05 +00:00
|
|
|
playingQueueAdapter?.swapDataSet(MusicPlayerRemote.playingQueue, MusicPlayerRemote.position)
|
2018-12-06 08:52:57 +00:00
|
|
|
resetToCurrentPosition()
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun resetToCurrentPosition() {
|
|
|
|
recyclerView.stopScroll()
|
2018-12-08 03:33:02 +00:00
|
|
|
linearLayoutManager.scrollToPositionWithOffset(MusicPlayerRemote.position + 1, 0)
|
2018-12-06 08:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onPause() {
|
|
|
|
if (recyclerViewDragDropManager != null) {
|
|
|
|
recyclerViewDragDropManager!!.cancelDrag()
|
|
|
|
}
|
|
|
|
super.onPause()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onDestroy() {
|
|
|
|
if (recyclerViewDragDropManager != null) {
|
|
|
|
recyclerViewDragDropManager!!.release()
|
|
|
|
recyclerViewDragDropManager = null
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wrappedAdapter != null) {
|
|
|
|
WrapperAdapterUtils.releaseAll(wrappedAdapter)
|
|
|
|
wrappedAdapter = null
|
|
|
|
}
|
|
|
|
playingQueueAdapter = null
|
|
|
|
super.onDestroy()
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun setupToolbar() {
|
2019-09-03 17:54:14 +00:00
|
|
|
playerQueueSubHeader.text = getUpNextAndQueueTime()
|
2018-12-06 08:52:57 +00:00
|
|
|
playerQueueSubHeader.setTextColor(ThemeStore.accentColor(this))
|
|
|
|
|
2019-05-20 19:38:43 +00:00
|
|
|
applyToolbar(toolbar)
|
2019-10-09 13:46:25 +00:00
|
|
|
appBarLayout.setBackgroundColor(ATHUtil.resolveColor(this, R.attr.colorPrimary))
|
2019-03-25 12:43:43 +00:00
|
|
|
|
|
|
|
clearQueue.backgroundTintList = ColorStateList.valueOf(ThemeStore.accentColor(this))
|
|
|
|
ColorStateList.valueOf(MaterialValueHelper.getPrimaryTextColor(this, ColorUtil.isColorLight(ThemeStore.accentColor(this)))).apply {
|
|
|
|
clearQueue.setTextColor(this)
|
|
|
|
clearQueue.iconTint = this
|
|
|
|
}
|
2018-12-06 08:52:57 +00:00
|
|
|
}
|
|
|
|
}
|