|
@@ -11,7 +11,6 @@ import android.view.View
|
|
import com.drake.brv.BindingAdapter
|
|
import com.drake.brv.BindingAdapter
|
|
import com.drake.brv.PageRefreshLayout
|
|
import com.drake.brv.PageRefreshLayout
|
|
import com.drake.net.NetConfig
|
|
import com.drake.net.NetConfig
|
|
-import com.scwang.smart.refresh.layout.constant.RefreshState
|
|
|
|
import kotlinx.coroutines.cancel
|
|
import kotlinx.coroutines.cancel
|
|
|
|
|
|
@Suppress("unused", "MemberVisibilityCanBePrivate", "NAME_SHADOWING")
|
|
@Suppress("unused", "MemberVisibilityCanBePrivate", "NAME_SHADOWING")
|
|
@@ -20,8 +19,7 @@ class PageCoroutineScope(
|
|
) : AndroidScope() {
|
|
) : AndroidScope() {
|
|
|
|
|
|
val index get() = page.index
|
|
val index get() = page.index
|
|
-
|
|
|
|
- private var manual = false
|
|
|
|
|
|
+ var manual = false
|
|
|
|
|
|
init {
|
|
init {
|
|
page.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
|
|
page.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
|
|
@@ -37,9 +35,7 @@ class PageCoroutineScope(
|
|
|
|
|
|
override fun catch(e: Throwable) {
|
|
override fun catch(e: Throwable) {
|
|
super.catch(e)
|
|
super.catch(e)
|
|
- if (page.state == RefreshState.Refreshing) {
|
|
|
|
- page.showError()
|
|
|
|
- } else page.finish(false)
|
|
|
|
|
|
+ if (page.stateEnabled) page.showError() else page.finish(false)
|
|
}
|
|
}
|
|
|
|
|
|
override fun finally(e: Throwable?) {
|
|
override fun finally(e: Throwable?) {
|
|
@@ -55,6 +51,7 @@ class PageCoroutineScope(
|
|
|
|
|
|
/**
|
|
/**
|
|
* 自动判断是添加数据还是覆盖数据, 以及数据为空或者NULL时[showEmpty]
|
|
* 自动判断是添加数据还是覆盖数据, 以及数据为空或者NULL时[showEmpty]
|
|
|
|
+ *
|
|
* @param hasMore 如果不传数据, 默认已加载完全部(建议此时可以关闭[PageRefreshLayout]的加载更多功能)
|
|
* @param hasMore 如果不传数据, 默认已加载完全部(建议此时可以关闭[PageRefreshLayout]的加载更多功能)
|
|
*/
|
|
*/
|
|
fun addData(
|
|
fun addData(
|
|
@@ -68,29 +65,34 @@ class PageCoroutineScope(
|
|
|
|
|
|
/**
|
|
/**
|
|
* 显示空缺省页
|
|
* 显示空缺省页
|
|
- * 此操作会导致观察者取消订阅
|
|
|
|
*/
|
|
*/
|
|
fun showEmpty() {
|
|
fun showEmpty() {
|
|
page.showEmpty()
|
|
page.showEmpty()
|
|
|
|
+ manual = true
|
|
cancel()
|
|
cancel()
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 显示内容缺省页
|
|
* 显示内容缺省页
|
|
- * 默认情况会自动执行不需要手动调用
|
|
|
|
|
|
+ *
|
|
|
|
+ * 一般情况会自动执行不需要手动调用
|
|
*/
|
|
*/
|
|
fun showContent() {
|
|
fun showContent() {
|
|
page.showContent()
|
|
page.showContent()
|
|
|
|
+ manual = true
|
|
cancel()
|
|
cancel()
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 结束刷新或者加载
|
|
* 结束刷新或者加载
|
|
- * 默认情况会自动执行不需要手动调用
|
|
|
|
|
|
+ *
|
|
|
|
+ * 一般情况会自动执行不需要手动调用
|
|
|
|
+ *
|
|
* @param success 是否成功
|
|
* @param success 是否成功
|
|
*/
|
|
*/
|
|
fun finish(success: Boolean = true) {
|
|
fun finish(success: Boolean = true) {
|
|
page.finish(success)
|
|
page.finish(success)
|
|
|
|
+ manual = true
|
|
cancel()
|
|
cancel()
|
|
}
|
|
}
|
|
|
|
|