pull/967/head
parent
d6564f30ed
commit
cbc30f1584
@ -1,92 +0,0 @@ |
||||
package io.legado.app.ui.widget.recycler |
||||
|
||||
import android.annotation.SuppressLint |
||||
import android.content.Context |
||||
import android.util.AttributeSet |
||||
import android.view.LayoutInflater |
||||
import android.view.MotionEvent |
||||
import android.view.View |
||||
import android.widget.LinearLayout |
||||
import androidx.recyclerview.widget.LinearLayoutManager |
||||
import io.legado.app.R |
||||
import io.legado.app.databinding.ViewRefreshRecyclerBinding |
||||
import io.legado.app.lib.theme.ATH |
||||
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility") |
||||
class RefreshRecyclerView(context: Context?, attrs: AttributeSet?) : LinearLayout(context, attrs) { |
||||
private var binding: ViewRefreshRecyclerBinding |
||||
private var durTouchX = -1000000f |
||||
private var durTouchY = -1000000f |
||||
|
||||
var onRefreshStart: (() -> Unit)? = null |
||||
|
||||
init { |
||||
orientation = VERTICAL |
||||
val view = LayoutInflater.from(context).inflate(R.layout.view_refresh_recycler, this, true) |
||||
binding = ViewRefreshRecyclerBinding.bind(view) |
||||
ATH.applyEdgeEffectColor(binding.recyclerView) |
||||
binding.recyclerView.setOnTouchListener(object : OnTouchListener { |
||||
@SuppressLint("ClickableViewAccessibility") |
||||
override fun onTouch(v: View?, event: MotionEvent?): Boolean { |
||||
when (event?.action) { |
||||
MotionEvent.ACTION_DOWN -> { |
||||
durTouchX = event.x |
||||
durTouchY = event.y |
||||
} |
||||
MotionEvent.ACTION_MOVE -> { |
||||
if (durTouchX == -1000000f) { |
||||
durTouchX = event.x |
||||
} |
||||
if (durTouchY == -1000000f) |
||||
durTouchY = event.y |
||||
|
||||
val dY = event.y - durTouchY //>0下拉 |
||||
durTouchY = event.y |
||||
if (!binding.refreshProgressBar.isAutoLoading && |
||||
binding.refreshProgressBar.getSecondDurProgress() == binding.refreshProgressBar.secondFinalProgress |
||||
) { |
||||
binding.recyclerView.adapter?.let { |
||||
if (it.itemCount > 0) { |
||||
if (0 == (binding.recyclerView.layoutManager as LinearLayoutManager).findFirstCompletelyVisibleItemPosition()) { |
||||
binding.refreshProgressBar.setSecondDurProgress((binding.refreshProgressBar.getSecondDurProgress() + dY / 2).toInt()) |
||||
} |
||||
} else { |
||||
binding.refreshProgressBar.setSecondDurProgress((binding.refreshProgressBar.getSecondDurProgress() + dY / 2).toInt()) |
||||
} |
||||
} |
||||
return binding.refreshProgressBar.getSecondDurProgress() > 0 |
||||
} |
||||
} |
||||
MotionEvent.ACTION_UP -> { |
||||
if (!binding.refreshProgressBar.isAutoLoading && |
||||
binding.refreshProgressBar.secondMaxProgress > 0 && |
||||
binding.refreshProgressBar.getSecondDurProgress() > 0 |
||||
) { |
||||
if (binding.refreshProgressBar.getSecondDurProgress() >= binding.refreshProgressBar.secondMaxProgress) { |
||||
binding.refreshProgressBar.isAutoLoading = true |
||||
onRefreshStart?.invoke() |
||||
} else { |
||||
binding.refreshProgressBar.setSecondDurProgressWithAnim(0) |
||||
} |
||||
} |
||||
durTouchX = -1000000f |
||||
durTouchY = -1000000f |
||||
} |
||||
} |
||||
return false |
||||
} |
||||
}) |
||||
} |
||||
|
||||
val recyclerView get() = binding.recyclerView |
||||
|
||||
fun startLoading() { |
||||
binding.refreshProgressBar.isAutoLoading = true |
||||
onRefreshStart?.invoke() |
||||
} |
||||
|
||||
fun stopLoading() { |
||||
binding.refreshProgressBar.isAutoLoading = false |
||||
} |
||||
} |
@ -1,109 +0,0 @@ |
||||
package io.legado.app.ui.widget.recycler |
||||
|
||||
import android.content.Context |
||||
import android.util.AttributeSet |
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import androidx.core.view.* |
||||
|
||||
class SwipeRefreshLayout @JvmOverloads constructor( |
||||
context: Context, |
||||
attrs: AttributeSet? = null |
||||
) : ViewGroup(context, attrs), NestedScrollingParent3, |
||||
NestedScrollingParent2, NestedScrollingChild3, NestedScrollingChild2, NestedScrollingParent, |
||||
NestedScrollingChild { |
||||
|
||||
init { |
||||
|
||||
} |
||||
|
||||
override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) { |
||||
TODO("Not yet implemented") |
||||
} |
||||
|
||||
override fun startNestedScroll(axes: Int, type: Int): Boolean { |
||||
TODO("Not yet implemented") |
||||
} |
||||
|
||||
override fun stopNestedScroll(type: Int) { |
||||
TODO("Not yet implemented") |
||||
} |
||||
|
||||
override fun hasNestedScrollingParent(type: Int): Boolean { |
||||
TODO("Not yet implemented") |
||||
} |
||||
|
||||
override fun dispatchNestedScroll( |
||||
dxConsumed: Int, |
||||
dyConsumed: Int, |
||||
dxUnconsumed: Int, |
||||
dyUnconsumed: Int, |
||||
offsetInWindow: IntArray?, |
||||
type: Int |
||||
): Boolean { |
||||
TODO("Not yet implemented") |
||||
} |
||||
|
||||
override fun dispatchNestedPreScroll( |
||||
dx: Int, |
||||
dy: Int, |
||||
consumed: IntArray?, |
||||
offsetInWindow: IntArray?, |
||||
type: Int |
||||
): Boolean { |
||||
TODO("Not yet implemented") |
||||
} |
||||
|
||||
override fun dispatchNestedScroll( |
||||
dxConsumed: Int, |
||||
dyConsumed: Int, |
||||
dxUnconsumed: Int, |
||||
dyUnconsumed: Int, |
||||
offsetInWindow: IntArray?, |
||||
type: Int, |
||||
consumed: IntArray |
||||
) { |
||||
TODO("Not yet implemented") |
||||
} |
||||
|
||||
override fun onStartNestedScroll(child: View, target: View, axes: Int, type: Int): Boolean { |
||||
TODO("Not yet implemented") |
||||
} |
||||
|
||||
override fun onNestedScrollAccepted(child: View, target: View, axes: Int, type: Int) { |
||||
TODO("Not yet implemented") |
||||
} |
||||
|
||||
override fun onStopNestedScroll(target: View, type: Int) { |
||||
TODO("Not yet implemented") |
||||
} |
||||
|
||||
override fun onNestedScroll( |
||||
target: View, |
||||
dxConsumed: Int, |
||||
dyConsumed: Int, |
||||
dxUnconsumed: Int, |
||||
dyUnconsumed: Int, |
||||
type: Int |
||||
) { |
||||
TODO("Not yet implemented") |
||||
} |
||||
|
||||
override fun onNestedPreScroll(target: View, dx: Int, dy: Int, consumed: IntArray, type: Int) { |
||||
TODO("Not yet implemented") |
||||
} |
||||
|
||||
override fun onNestedScroll( |
||||
target: View, |
||||
dxConsumed: Int, |
||||
dyConsumed: Int, |
||||
dxUnconsumed: Int, |
||||
dyUnconsumed: Int, |
||||
type: Int, |
||||
consumed: IntArray |
||||
) { |
||||
TODO("Not yet implemented") |
||||
} |
||||
|
||||
|
||||
} |
Loading…
Reference in new issue