Browse Source

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

housekeeping/remove-warnings
Antoine POPINEAU 4 years ago
parent
commit
1e62cc1f4e
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 12
      app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt
  2. 26
      app/src/main/java/com/github/apognu/otter/views/InterceptedFrameLayout.kt
  3. 4
      app/src/main/java/com/github/apognu/otter/views/NowPlayingView.kt
  4. 2
      app/src/main/res/layout/activity_main.xml

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

@ -29,6 +29,7 @@ import com.github.apognu.otter.repositories.FavoritedRepository @@ -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() { @@ -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))

26
app/src/main/java/com/github/apognu/otter/views/InterceptedFrameLayout.kt

@ -0,0 +1,26 @@ @@ -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
}
}

4
app/src/main/java/com/github/apognu/otter/views/NowPlayingView.kt

@ -72,7 +72,7 @@ class NowPlayingView : MaterialCardView { @@ -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 { @@ -100,8 +100,6 @@ class NowPlayingView : MaterialCardView {
initialTouchY = e.rawY
lastTouchY = e.rawY
flingAnimator?.cancel()
return true
}

2
app/src/main/res/layout/activity_main.xml

@ -5,7 +5,7 @@ @@ -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"

Loading…
Cancel
Save