From 0261660df6f7cc43b964c4b9ec4eb80477a12e39 Mon Sep 17 00:00:00 2001 From: casey langen Date: Sun, 31 Mar 2019 22:58:45 -0700 Subject: [PATCH] Small progress/seek bug fixes. --- .../remote/ui/shared/extension/Extensions.kt | 9 ++++++--- .../ui/shared/fragment/TransportFragment.kt | 20 ++++++++++--------- .../shared/view/TouchInterceptFrameLayout.kt | 8 ++++---- .../main/res/layout/transport_fragment.xml | 2 +- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/extension/Extensions.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/extension/Extensions.kt index 6c7fc4291..03690051d 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/extension/Extensions.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/extension/Extensions.kt @@ -4,6 +4,7 @@ import android.app.SearchManager import android.content.Context import android.content.Intent import android.content.SharedPreferences +import android.content.res.Resources import android.os.Bundle import android.text.TextUtils import android.view.Menu @@ -164,9 +165,6 @@ fun BaseFragment.addFilterAction(menu: Menu, filterable: IFilterable?): Boolean return true } -fun AppCompatActivity.dpToPx(dp: Float): Float = dp * this.resources.displayMetrics.density - - fun AppCompatActivity.dialogVisible(tag: String): Boolean = this.supportFragmentManager.findFragmentByTag(tag) != null @@ -466,6 +464,11 @@ fun DialogFragment.hideKeyboard() = * */ +fun dpToPx(dp: Float): Float = dp * Resources.getSystem().displayMetrics.density + +fun dpToPx(dp: Int): Float = dpToPx(dp.toFloat()) + + fun letMany(p1: T1?, p2: T2?, block: (T1, T2) -> R?): R? { return if (p1 != null && p2 != null) block(p1, p2) else null } diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/fragment/TransportFragment.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/fragment/TransportFragment.kt index edaee6765..32fb8c2e6 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/fragment/TransportFragment.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/fragment/TransportFragment.kt @@ -11,6 +11,7 @@ import io.casey.musikcube.remote.service.playback.PlaybackState import io.casey.musikcube.remote.ui.home.activity.MainActivity import io.casey.musikcube.remote.ui.navigation.Navigate import io.casey.musikcube.remote.ui.playqueue.fragment.PlayQueueFragment +import io.casey.musikcube.remote.ui.shared.extension.dpToPx import io.casey.musikcube.remote.ui.shared.extension.fallback import io.casey.musikcube.remote.ui.shared.extension.getColorCompat import io.casey.musikcube.remote.ui.shared.extension.topOfStack @@ -93,8 +94,8 @@ class TransportFragment: BaseFragment() { } titleBar?.setOnInterceptTouchEventListener(object: InterceptTouchFrameLayout.OnInterceptTouchEventListener { - override fun onInterceptTouchEvent(view: InterceptTouchFrameLayout, ev: MotionEvent, disallowIntercept: Boolean): Boolean { - return when (ev.action) { + override fun onInterceptTouchEvent(view: InterceptTouchFrameLayout, event: MotionEvent, disallowIntercept: Boolean): Boolean { + return when (event.action) { MotionEvent.ACTION_DOWN, MotionEvent.ACTION_MOVE, MotionEvent.ACTION_CANCEL, @@ -103,10 +104,10 @@ class TransportFragment: BaseFragment() { } } - override fun onTouchEvent(view: InterceptTouchFrameLayout, ev: MotionEvent): Boolean { - seekTracker.update(ev) + override fun onTouchEvent(view: InterceptTouchFrameLayout, event: MotionEvent): Boolean { + seekTracker.update(event) if (seekTracker.processed) { - when (ev.action) { + when (event.action) { MotionEvent.ACTION_MOVE -> { seekOverride = ( seekTracker.lastX.toFloat() / @@ -122,7 +123,7 @@ class TransportFragment: BaseFragment() { } } } - view.defaultOnTouchEvent(ev) + view.defaultOnTouchEvent(event) return true } }) @@ -157,7 +158,7 @@ class TransportFragment: BaseFragment() { val buffered = playback.service.bufferedTime.toInt() val total = playback.service.duration.toInt() progress.max = total - progress.secondaryProgress = if (buffered >= 100) 0 else buffered + progress.secondaryProgress = if (buffered >= total) 0 else buffered progress.progress = if (seekTracker.down && seekOverride >= 0) { seekOverride @@ -175,7 +176,7 @@ class TransportFragment: BaseFragment() { val playing = state == PlaybackState.Playing val buffering = state == PlaybackState.Buffering - this.playPause.setText(if (playing) R.string.button_pause else R.string.button_play) + this.playPause.setText(if (playing || buffering) R.string.button_pause else R.string.button_play) this.buffering.visibility = if (buffering) View.VISIBLE else View.GONE if (state == PlaybackState.Stopped) { @@ -253,11 +254,12 @@ class TransportFragment: BaseFragment() { } val processed: Boolean - get() { return totalDx >= 24 } + get() { return dpToPx(SEEK_SLOP_PX) >= 24 } } companion object { const val TAG = "TransportFragment" + private const val SEEK_SLOP_PX = 24 fun create(): TransportFragment = TransportFragment() } } diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/view/TouchInterceptFrameLayout.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/view/TouchInterceptFrameLayout.kt index e9a94e29d..14b8136fc 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/view/TouchInterceptFrameLayout.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/shared/view/TouchInterceptFrameLayout.kt @@ -10,7 +10,7 @@ class InterceptTouchFrameLayout : FrameLayout { private var interceptor: OnInterceptTouchEventListener = DEFAULT_INTERCEPTOR interface OnInterceptTouchEventListener { - fun onInterceptTouchEvent(view: InterceptTouchFrameLayout, ev: MotionEvent, disallowIntercept: Boolean): Boolean + fun onInterceptTouchEvent(view: InterceptTouchFrameLayout, event: MotionEvent, disallowIntercept: Boolean): Boolean fun onTouchEvent(view: InterceptTouchFrameLayout, event: MotionEvent): Boolean } @@ -30,8 +30,8 @@ class InterceptTouchFrameLayout : FrameLayout { } override fun onInterceptTouchEvent(ev: MotionEvent): Boolean { - val stealTouchEvent = interceptor.onInterceptTouchEvent(this, ev, disallowIntercept) - return stealTouchEvent && !disallowIntercept || super.onInterceptTouchEvent(ev) + val eatTouchEvent = interceptor.onInterceptTouchEvent(this, ev, disallowIntercept) + return eatTouchEvent && !disallowIntercept || super.onInterceptTouchEvent(ev) } override fun onTouchEvent(ev: MotionEvent): Boolean { @@ -44,7 +44,7 @@ class InterceptTouchFrameLayout : FrameLayout { companion object { private val DEFAULT_INTERCEPTOR = object: OnInterceptTouchEventListener { - override fun onInterceptTouchEvent(view: InterceptTouchFrameLayout, ev: MotionEvent, disallowIntercept: Boolean): Boolean = false + override fun onInterceptTouchEvent(view: InterceptTouchFrameLayout, event: MotionEvent, disallowIntercept: Boolean): Boolean = false override fun onTouchEvent(view: InterceptTouchFrameLayout, event: MotionEvent): Boolean = false } } diff --git a/src/musikdroid/app/src/main/res/layout/transport_fragment.xml b/src/musikdroid/app/src/main/res/layout/transport_fragment.xml index ca934dec4..2f4dfcc24 100644 --- a/src/musikdroid/app/src/main/res/layout/transport_fragment.xml +++ b/src/musikdroid/app/src/main/res/layout/transport_fragment.xml @@ -56,7 +56,7 @@ android:id="@+id/title_bar" android:layout_width="match_parent" android:layout_height="wrap_content" - android:minHeight="28dp" + android:minHeight="24dp" android:background="@drawable/category_button" android:transitionName="play_queue_transition">