请求失败刷新取消优化

This commit is contained in:
lijia 2024-04-12 17:08:20 +08:00
parent 548003a5d9
commit 1b3568664b
2 changed files with 22 additions and 4 deletions

View File

@ -10,6 +10,7 @@ import com.dahe.mylibrary.net.ResultException
import com.dahe.mylibrary.utils.LoadingUtils
import com.dahe.mylibrary.utils.ToastUtils
import com.lxj.xpopup.impl.LoadingPopupView
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import org.json.JSONException
import java.net.ConnectException
import java.net.SocketTimeoutException
@ -23,6 +24,7 @@ import javax.net.ssl.SSLException
abstract class RxHttpCallBack<T> {
// private var dialog: ProgressDialog? = null
private var dialog: LoadingPopupView? = null
private var smartRefreshLayout: SmartRefreshLayout? = null
private fun initDialog(activity: AppCompatActivity?, dialogMessage: String) {
// dialog = ProgressDialog(activity)
// dialog!!.requestWindowFeature(Window.FEATURE_NO_TITLE)
@ -45,6 +47,10 @@ abstract class RxHttpCallBack<T> {
initDialog(activity, "网络请求中......")
}
constructor(smartRefresh: SmartRefreshLayout) {
smartRefreshLayout = smartRefresh
}
constructor() {}
/**
@ -72,6 +78,10 @@ abstract class RxHttpCallBack<T> {
if (dialog != null && dialog!!.isShow) {
dialog!!.dismiss()
}
smartRefreshLayout?.let {
if (it.isRefreshing)
it.finishRefresh()
}
}
/**
@ -84,13 +94,17 @@ abstract class RxHttpCallBack<T> {
if (dialog != null && dialog!!.isShow) {
dialog!!.dismiss()
}
smartRefreshLayout?.let {
if (it.isRefreshing)
it.finishRefresh()
}
if (t.code == 401) {
// instance.loginOut(mContext!!)
// Intent intent = new Intent(mContext, LoginActivity.class);
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
// mContext.startActivity(intent);
ToastUtils.showToast(mContext, "您的账号再异地登录,请重新登录")
} else {
} else {
ToastUtils.showToast(mContext, t.msg)
}
@ -111,6 +125,10 @@ abstract class RxHttpCallBack<T> {
if (dialog != null && dialog!!.isShow) {
dialog!!.dismiss()
}
smartRefreshLayout?.let {
if (it.isRefreshing)
it.finishRefresh()
}
if (e is ConnectException
|| e is TimeoutException
|| e is SocketTimeoutException
@ -127,7 +145,7 @@ abstract class RxHttpCallBack<T> {
// System.out.println("---------errorCode------->"+((ResultException) e).getErrCode());
} else if (e is SSLException) {
ToastUtils.showToast(mContext, "网络连接终端,请检查您的网络~")
}else if (e is JSONException) {
} else if (e is JSONException) {
ToastUtils.showToast(mContext, "数据格式转换异常~")
} else {
ToastUtils.showToast(mContext, e.message)

View File

@ -190,13 +190,13 @@ class MineFragment : BaseFragment<FragmentMineBinding>(), View.OnClickListener,
DataManager.getInstance().getUserInfo()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(BaseObserver(mContext, object : RxHttpCallBack<UserBean>() {
.subscribe(BaseObserver(mContext, object : RxHttpCallBack<UserBean>(binding.refresh) {
override fun onSuccess(t: CommonResponseBean<UserBean>) {
super.onSuccess(t)
binding.refresh.finishRefresh()
if (t==null||t.data==null)
return
UserUtils.instance.updateUser(mContext, t.data)
binding.refresh.finishRefresh()
refreshView()
}
}))