|
@@ -9,10 +9,14 @@ package com.drake.net.observer
|
|
|
|
|
|
import android.view.View
|
|
|
import android.view.View.OnAttachStateChangeListener
|
|
|
+import com.drake.brv.BindingAdapter
|
|
|
import com.drake.brv.PageRefreshLayout
|
|
|
+import com.drake.net.BuildConfig
|
|
|
import com.drake.net.NetConfig
|
|
|
import com.drake.net.R
|
|
|
-import com.drake.net.error.*
|
|
|
+import com.drake.net.error.RequestParamsException
|
|
|
+import com.drake.net.error.ResponseException
|
|
|
+import com.drake.net.error.ServerResponseException
|
|
|
import com.drake.net.toast
|
|
|
import com.yanzhenjie.kalle.exception.*
|
|
|
import io.reactivex.observers.DefaultObserver
|
|
@@ -32,30 +36,30 @@ abstract class PageObserver<M>(val pageRefreshLayout: PageRefreshLayout) : Defau
|
|
|
is URLError -> NetConfig.app.getString(R.string.url_error)
|
|
|
is HostError -> NetConfig.app.getString(R.string.host_error)
|
|
|
is ConnectTimeoutError -> NetConfig.app.getString(R.string.connect_timeout_error)
|
|
|
- is ConnectException -> NetConfig.app.getString(R.string.connect_exception)
|
|
|
+ is ReadException -> NetConfig.app.getString(R.string.read_exception)
|
|
|
is WriteException -> NetConfig.app.getString(R.string.write_exception)
|
|
|
+ is ConnectException -> NetConfig.app.getString(R.string.connect_exception)
|
|
|
is ReadTimeoutError -> NetConfig.app.getString(R.string.read_timeout_error)
|
|
|
is DownloadError -> NetConfig.app.getString(R.string.download_error)
|
|
|
is NoCacheError -> NetConfig.app.getString(R.string.no_cache_error)
|
|
|
- is ReadException -> NetConfig.app.getString(R.string.read_exception)
|
|
|
is ParseError -> NetConfig.app.getString(R.string.parse_error)
|
|
|
- is ParseJsonException -> NetConfig.app.getString(R.string.parse_json_error)
|
|
|
- is JsonStructureException -> NetConfig.app.getString(R.string.json_structure_error)
|
|
|
is RequestParamsException -> NetConfig.app.getString(R.string.request_error)
|
|
|
is ServerResponseException -> NetConfig.app.getString(R.string.server_error)
|
|
|
is ResponseException -> msg
|
|
|
else -> {
|
|
|
- printStackTrace()
|
|
|
NetConfig.app.getString(R.string.other_error)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- when (this) {
|
|
|
- is ParseError, is ParseJsonException, is ResponseException, is RequestParamsException, is ServerResponseException -> NetConfig.app.toast(
|
|
|
- message
|
|
|
- )
|
|
|
+ if (BuildConfig.DEBUG) {
|
|
|
+ printStackTrace()
|
|
|
}
|
|
|
|
|
|
+ when (this) {
|
|
|
+ is ParseError, is ResponseException -> {
|
|
|
+ NetConfig.app.toast(message)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -77,17 +81,11 @@ abstract class PageObserver<M>(val pageRefreshLayout: PageRefreshLayout) : Defau
|
|
|
* @param e 包括错误信息
|
|
|
*/
|
|
|
override fun onError(e: Throwable) {
|
|
|
- if (pageRefreshLayout.stateEnabled) {
|
|
|
- pageRefreshLayout.showError()
|
|
|
- } else pageRefreshLayout.finish(false)
|
|
|
-
|
|
|
+ pageRefreshLayout.showError()
|
|
|
onPageError.invoke(e, pageRefreshLayout)
|
|
|
}
|
|
|
|
|
|
override fun onComplete() {
|
|
|
- if (pageRefreshLayout.stateEnabled) {
|
|
|
- pageRefreshLayout.showContent()
|
|
|
- } else pageRefreshLayout.finish(true)
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -95,7 +93,7 @@ abstract class PageObserver<M>(val pageRefreshLayout: PageRefreshLayout) : Defau
|
|
|
*
|
|
|
* @param data 要添加的数据集
|
|
|
*/
|
|
|
- fun addData(data: List<Any>, hasMore: PageRefreshLayout.() -> Boolean) {
|
|
|
+ fun addData(data: List<Any>, hasMore: BindingAdapter.() -> Boolean) {
|
|
|
pageRefreshLayout.addData(data, hasMore)
|
|
|
}
|
|
|
|