Browse Source

Cleaned up DisableableFrameLayout.

housekeeping/remove-warnings
Antoine POPINEAU 4 years ago
parent
commit
85e9f14e2a
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 13
      app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt
  2. 14
      app/src/main/java/com/github/apognu/otter/views/DisableableFrameLayout.kt

13
app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt

@ -78,15 +78,14 @@ class MainActivity : AppCompatActivity() { @@ -78,15 +78,14 @@ 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
}
(container as? DisableableFrameLayout)?.setShouldRegisterTouch { _ ->
if (now_playing.isOpened()) {
now_playing.close()
return true
return@setShouldRegisterTouch false
}
true
}
favoritedRepository.update(this, lifecycleScope)

14
app/src/main/java/com/github/apognu/otter/views/InterceptedFrameLayout.kt → app/src/main/java/com/github/apognu/otter/views/DisableableFrameLayout.kt

@ -6,21 +6,21 @@ import android.view.MotionEvent @@ -6,21 +6,21 @@ import android.view.MotionEvent
import android.widget.FrameLayout
class DisableableFrameLayout : FrameLayout {
interface Callback {
fun shouldRegisterTouch(): Boolean
}
var callback: Callback? = null
var callback: ((MotionEvent?) -> Boolean)? = 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 {
override fun onInterceptTouchEvent(event: MotionEvent?): Boolean {
callback?.let {
return !it.shouldRegisterTouch()
return !it(event)
}
return false
}
fun setShouldRegisterTouch(callback: (event: MotionEvent?) -> Boolean) {
this.callback = callback
}
}
Loading…
Cancel
Save