Now Playing view: do not cancel fling event on touch, disable view behind it when opened.
This commit is contained in:
parent
b0640cf1b2
commit
1e62cc1f4e
|
@ -29,6 +29,7 @@ import com.github.apognu.otter.repositories.FavoritedRepository
|
||||||
import com.github.apognu.otter.repositories.FavoritesRepository
|
import com.github.apognu.otter.repositories.FavoritesRepository
|
||||||
import com.github.apognu.otter.repositories.Repository
|
import com.github.apognu.otter.repositories.Repository
|
||||||
import com.github.apognu.otter.utils.*
|
import com.github.apognu.otter.utils.*
|
||||||
|
import com.github.apognu.otter.views.DisableableFrameLayout
|
||||||
import com.github.kittinunf.fuel.Fuel
|
import com.github.kittinunf.fuel.Fuel
|
||||||
import com.github.kittinunf.fuel.coroutines.awaitStringResponse
|
import com.github.kittinunf.fuel.coroutines.awaitStringResponse
|
||||||
import com.google.android.exoplayer2.Player
|
import com.google.android.exoplayer2.Player
|
||||||
|
@ -77,6 +78,17 @@ class MainActivity : AppCompatActivity() {
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
|
||||||
|
(container as? DisableableFrameLayout)?.callback = object : DisableableFrameLayout.Callback {
|
||||||
|
override fun shouldRegisterTouch(): Boolean {
|
||||||
|
if (now_playing.isOpened()) {
|
||||||
|
now_playing.close()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
favoritedRepository.update(this, lifecycleScope)
|
favoritedRepository.update(this, lifecycleScope)
|
||||||
|
|
||||||
startService(Intent(this, PlayerService::class.java))
|
startService(Intent(this, PlayerService::class.java))
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.github.apognu.otter.views
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.MotionEvent
|
||||||
|
import android.widget.FrameLayout
|
||||||
|
|
||||||
|
class DisableableFrameLayout : FrameLayout {
|
||||||
|
interface Callback {
|
||||||
|
fun shouldRegisterTouch(): Boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
var callback: Callback? = null
|
||||||
|
|
||||||
|
constructor(context: Context) : super(context)
|
||||||
|
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||||
|
constructor(context: Context, attrs: AttributeSet?, style: Int) : super(context, attrs, style)
|
||||||
|
|
||||||
|
override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
|
||||||
|
callback?.let {
|
||||||
|
return !it.shouldRegisterTouch()
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
|
@ -72,7 +72,7 @@ class NowPlayingView : MaterialCardView {
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class OnGestureDetection : GestureDetector.SimpleOnGestureListener() {
|
inner class OnGestureDetection : GestureDetector.SimpleOnGestureListener() {
|
||||||
var maxHeight = 0
|
private var maxHeight = 0
|
||||||
private var minHeight = 0
|
private var minHeight = 0
|
||||||
private var maxMargin = 0
|
private var maxMargin = 0
|
||||||
|
|
||||||
|
@ -100,8 +100,6 @@ class NowPlayingView : MaterialCardView {
|
||||||
initialTouchY = e.rawY
|
initialTouchY = e.rawY
|
||||||
lastTouchY = e.rawY
|
lastTouchY = e.rawY
|
||||||
|
|
||||||
flingAnimator?.cancel()
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<FrameLayout
|
<com.github.apognu.otter.views.DisableableFrameLayout
|
||||||
android:id="@+id/container"
|
android:id="@+id/container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
|
Loading…
Reference in New Issue