Now Playing view: do not cancel fling event on touch, disable view behind it when opened.

This commit is contained in:
Antoine POPINEAU 2020-07-12 18:55:52 +02:00
parent b0640cf1b2
commit 1e62cc1f4e
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
4 changed files with 40 additions and 4 deletions

View File

@ -29,6 +29,7 @@ import com.github.apognu.otter.repositories.FavoritedRepository
import com.github.apognu.otter.repositories.FavoritesRepository
import com.github.apognu.otter.repositories.Repository
import com.github.apognu.otter.utils.*
import com.github.apognu.otter.views.DisableableFrameLayout
import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.fuel.coroutines.awaitStringResponse
import com.google.android.exoplayer2.Player
@ -77,6 +78,17 @@ class MainActivity : AppCompatActivity() {
override fun 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)
startService(Intent(this, PlayerService::class.java))

View File

@ -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
}
}

View File

@ -72,7 +72,7 @@ class NowPlayingView : MaterialCardView {
}
inner class OnGestureDetection : GestureDetector.SimpleOnGestureListener() {
var maxHeight = 0
private var maxHeight = 0
private var minHeight = 0
private var maxMargin = 0
@ -100,8 +100,6 @@ class NowPlayingView : MaterialCardView {
initialTouchY = e.rawY
lastTouchY = e.rawY
flingAnimator?.cancel()
return true
}

View File

@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
<com.github.apognu.otter.views.DisableableFrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"