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
import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.MotionEvent.ACTION_MOVE
import android.view.ViewConfiguration
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?) :
SwipeRefreshLayout(context!!, attrs) {
private val mTouchSlop: Int
private val mTouchSlop: Int = ViewConfiguration.get(this.context).scaledTouchSlop
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 {
when (event.action) {
MotionEvent.ACTION_DOWN -> mPrevX = MotionEvent.obtain(event).x
ACTION_MOVE -> {
val eventX = event.x
val xDiff = Math.abs(eventX - mPrevX)
val xDiff = abs(eventX - mPrevX)
if (xDiff > mTouchSlop) {
return false
}
@ -24,8 +35,4 @@ class CustomSwipeToRefresh(context: Context?, attrs: AttributeSet?) :
}
return super.onInterceptTouchEvent(event)
}
init {
mTouchSlop = ViewConfiguration.get(this.context).scaledTouchSlop
}
}

View File

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