mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Merge pull request #2451 from Bnyro/master
Theme the pull refresh progress
This commit is contained in:
commit
12313f1ae1
@ -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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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>
|
Loading…
Reference in New Issue
Block a user