Merge pull request #2451 from Bnyro/master

Theme the pull refresh progress
This commit is contained in:
Bnyro 2022-12-20 16:38:12 +01:00 committed by GitHub
commit 12313f1ae1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 8 deletions

View File

@ -1,22 +1,33 @@
package com.github.libretube.ui.views package com.github.libretube.ui.views
import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.view.MotionEvent import android.view.MotionEvent
import android.view.MotionEvent.ACTION_MOVE import android.view.MotionEvent.ACTION_MOVE
import android.view.ViewConfiguration import android.view.ViewConfiguration
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.github.libretube.R
import com.github.libretube.util.ThemeHelper
import kotlin.math.abs
class CustomSwipeToRefresh(context: Context?, attrs: AttributeSet?) : class CustomSwipeToRefresh(context: Context?, attrs: AttributeSet?) :
SwipeRefreshLayout(context!!, attrs) { SwipeRefreshLayout(context!!, attrs) {
private val mTouchSlop: Int private val mTouchSlop: Int = ViewConfiguration.get(this.context).scaledTouchSlop
private var mPrevX = 0f private var mPrevX = 0f
init {
setColorSchemeColors(ThemeHelper.getThemeColor(this.context, R.attr.colorPrimary))
setProgressBackgroundColorSchemeColor(ThemeHelper.getThemeColor(this.context, R.attr.colorSurface))
}
@SuppressLint("Recycle")
override fun onInterceptTouchEvent(event: MotionEvent): Boolean { override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
when (event.action) { when (event.action) {
MotionEvent.ACTION_DOWN -> mPrevX = MotionEvent.obtain(event).x MotionEvent.ACTION_DOWN -> mPrevX = MotionEvent.obtain(event).x
ACTION_MOVE -> { ACTION_MOVE -> {
val eventX = event.x val eventX = event.x
val xDiff = Math.abs(eventX - mPrevX) val xDiff = abs(eventX - mPrevX)
if (xDiff > mTouchSlop) { if (xDiff > mTouchSlop) {
return false return false
} }
@ -24,8 +35,4 @@ class CustomSwipeToRefresh(context: Context?, attrs: AttributeSet?) :
} }
return super.onInterceptTouchEvent(event) return super.onInterceptTouchEvent(event)
} }
init {
mTouchSlop = ViewConfiguration.get(this.context).scaledTouchSlop
}
} }

View File

@ -15,7 +15,7 @@
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout <com.github.libretube.ui.views.CustomSwipeToRefresh
android:id="@+id/home_refresh" android:id="@+id/home_refresh"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -30,6 +30,6 @@
app:layout_constraintTop_toBottomOf="@+id/progressBar" app:layout_constraintTop_toBottomOf="@+id/progressBar"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout> </com.github.libretube.ui.views.CustomSwipeToRefresh>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>