diff --git a/app/src/main/java/com/github/libretube/ui/views/CustomSwipeToRefresh.kt b/app/src/main/java/com/github/libretube/ui/views/CustomSwipeToRefresh.kt index 13a2ac5db..e5a037def 100644 --- a/app/src/main/java/com/github/libretube/ui/views/CustomSwipeToRefresh.kt +++ b/app/src/main/java/com/github/libretube/ui/views/CustomSwipeToRefresh.kt @@ -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 - } } diff --git a/app/src/main/res/layout/fragment_trends.xml b/app/src/main/res/layout/fragment_trends.xml index 039e85007..5d77c3ea6 100644 --- a/app/src/main/res/layout/fragment_trends.xml +++ b/app/src/main/res/layout/fragment_trends.xml @@ -15,7 +15,7 @@ app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> - @@ -30,6 +30,6 @@ app:layout_constraintTop_toBottomOf="@+id/progressBar" app:layout_constraintTop_toTopOf="parent" /> - + \ No newline at end of file