[Player] Fixed Show now playing not working

main
Prathamesh More 2021-12-03 19:53:43 +05:30
parent 93277b8de7
commit ba9c928588
5 changed files with 48 additions and 22 deletions

View File

@ -134,6 +134,8 @@ class MainActivity : AbsCastActivity(), OnSharedPreferenceChangeListener {
PreferenceUtil.registerOnSharedPreferenceChangedListener(this)
val expand = extra<Boolean>(EXPAND_PANEL).value ?: false
if (expand && PreferenceUtil.isExpandPanel) {
fromNotification = true
slidingPanel.bringToFront()
expandPanel()
intent.removeExtra(EXPAND_PANEL)
}

View File

@ -24,6 +24,7 @@ import android.widget.FrameLayout
import androidx.core.animation.doOnEnd
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.commit
@ -68,6 +69,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
val TAG: String = AbsSlidingMusicPanelActivity::class.java.simpleName
}
var fromNotification = false
private var windowInsets: WindowInsetsCompat? = null
protected val libraryViewModel by viewModel<LibraryViewModel>()
private lateinit var bottomSheetBehavior: RetroBottomSheetBehavior<FrameLayout>
@ -90,12 +92,19 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
when (newState) {
STATE_EXPANDED -> {
onPanelExpanded()
}
STATE_COLLAPSED -> {
onPanelCollapsed()
}
STATE_SETTLING, STATE_DRAGGING -> {
if (fromNotification) {
binding.bottomNavigationView.bringToFront()
fromNotification = false
}
}
else -> {
println("Do something")
println("Do a flip")
}
}
}
@ -163,7 +172,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
if (progress < 0) return
val alpha = 1 - progress
miniPlayerFragment?.view?.alpha = 1 - (progress / 0.2F)
miniPlayerFragment?.view?.visibility = if (alpha == 0f) View.GONE else View.VISIBLE
miniPlayerFragment?.view?.isGone = alpha == 0f
binding.bottomNavigationView.translationY = progress * 500
binding.bottomNavigationView.alpha = alpha
binding.playerFragmentContainer.alpha = (progress - 0.2F) / 0.2F
@ -205,6 +214,8 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
val bottomNavigationView get() = binding.bottomNavigationView
val slidingPanel get() = binding.slidingPanel
override fun onServiceConnected() {
super.onServiceConnected()
if (MusicPlayerRemote.playingQueue.isNotEmpty()) {
@ -239,7 +250,6 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
collapsePanel()
return true
}
return false
}
@ -307,17 +317,26 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
}
fun setBottomNavVisibility(visible: Boolean, animate: Boolean = false) {
binding.bottomNavigationView.translateYAnimate(if (visible) 0F else dip(R.dimen.bottom_nav_height).toFloat() + windowInsets.safeGetBottomInsets())
.apply {
doOnEnd {
val translationY =
if (visible) 0F else dip(R.dimen.bottom_nav_height).toFloat() + windowInsets.safeGetBottomInsets()
if (animate) {
binding.bottomNavigationView.translateYAnimate(translationY).doOnEnd {
if (visible && bottomSheetBehavior.state != STATE_EXPANDED) {
binding.bottomNavigationView.bringToFront()
}
hideBottomSheet(
hide = MusicPlayerRemote.playingQueue.isEmpty(),
animate = animate,
isBottomNavVisible = visible
)
}
} else {
binding.bottomNavigationView.translationY =
translationY
if (visible && bottomSheetBehavior.state != STATE_EXPANDED) {
binding.bottomNavigationView.bringToFront()
}
}
hideBottomSheet(
hide = MusicPlayerRemote.playingQueue.isEmpty(),
animate = animate,
isBottomNavVisible = visible
)
}
fun hideBottomSheet(
@ -346,7 +365,6 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
} else {
bottomSheetBehavior.peekHeight = heightOfBarWithTabs
}
binding.bottomNavigationView.bringToFront()
libraryViewModel.setFabMargin(dip(R.dimen.mini_player_height_expanded))
} else {
println("Details")

View File

@ -1,7 +1,9 @@
package code.name.monkey.retromusic.extensions
import androidx.core.view.WindowInsetsCompat
import code.name.monkey.retromusic.util.RetroUtil
fun WindowInsetsCompat?.safeGetBottomInsets(): Int {
return this?.getInsets(WindowInsetsCompat.Type.systemBars())?.bottom ?: 0
// Get Navbar heights if insets are null
return (this?.getInsets(WindowInsetsCompat.Type.systemBars())?.bottom ?: RetroUtil.getNavigationBarHeight())
}

View File

@ -69,6 +69,7 @@ fun View.translateYAnimate(value: Float): Animator {
duration = 300
doOnStart {
show()
bringToFront()
}
doOnEnd {
if (value != 0f) {

View File

@ -71,10 +71,13 @@ class PlayingNotificationImpl : PlayingNotification(), KoinComponent {
action.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
val clickIntent =
PendingIntent.getActivity(
service, 0, action, if (VersionUtils.hasMarshmallow())
PendingIntent.FLAG_IMMUTABLE
else 0 or PendingIntent.FLAG_UPDATE_CURRENT
)
service,
0,
action,
PendingIntent.FLAG_UPDATE_CURRENT or if (VersionUtils.hasMarshmallow())
PendingIntent.FLAG_IMMUTABLE
else 0
)
val serviceName = ComponentName(service, MusicService::class.java)
val intent = Intent(ACTION_QUIT)
@ -83,9 +86,9 @@ class PlayingNotificationImpl : PlayingNotification(), KoinComponent {
service,
0,
intent,
if (VersionUtils.hasMarshmallow())
PendingIntent.FLAG_UPDATE_CURRENT or (if (VersionUtils.hasMarshmallow())
PendingIntent.FLAG_IMMUTABLE
else 0 or PendingIntent.FLAG_UPDATE_CURRENT
else 0)
)
val bigNotificationImageSize = service.resources
.getDimensionPixelSize(R.dimen.notification_big_image_size)
@ -201,9 +204,9 @@ class PlayingNotificationImpl : PlayingNotification(), KoinComponent {
val intent = Intent(action)
intent.component = serviceName
return PendingIntent.getService(
service, 0, intent,
if (VersionUtils.hasMarshmallow()) PendingIntent.FLAG_IMMUTABLE
else 0 or PendingIntent.FLAG_UPDATE_CURRENT
service, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or
if (VersionUtils.hasMarshmallow()) PendingIntent.FLAG_IMMUTABLE
else 0
)
}
}