From 1b3568664b8b42ee79b8717b99cd9048b7e60a1b Mon Sep 17 00:00:00 2001 From: lijia Date: Fri, 12 Apr 2024 17:08:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=A4=B1=E8=B4=A5=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E5=8F=96=E6=B6=88=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dahe/gldriver/net/RxHttpCallBack.kt | 22 +++++++++++++++++-- .../com/dahe/gldriver/ui/mine/MineFragment.kt | 4 ++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/dahe/gldriver/net/RxHttpCallBack.kt b/app/src/main/java/com/dahe/gldriver/net/RxHttpCallBack.kt index 123950a..56c7afd 100644 --- a/app/src/main/java/com/dahe/gldriver/net/RxHttpCallBack.kt +++ b/app/src/main/java/com/dahe/gldriver/net/RxHttpCallBack.kt @@ -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 { // 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 { initDialog(activity, "网络请求中......") } + constructor(smartRefresh: SmartRefreshLayout) { + smartRefreshLayout = smartRefresh + } + constructor() {} /** @@ -72,6 +78,10 @@ abstract class RxHttpCallBack { if (dialog != null && dialog!!.isShow) { dialog!!.dismiss() } + smartRefreshLayout?.let { + if (it.isRefreshing) + it.finishRefresh() + } } /** @@ -84,13 +94,17 @@ abstract class RxHttpCallBack { 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 { 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 { // 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) diff --git a/app/src/main/java/com/dahe/gldriver/ui/mine/MineFragment.kt b/app/src/main/java/com/dahe/gldriver/ui/mine/MineFragment.kt index 280f594..fbe7d6b 100644 --- a/app/src/main/java/com/dahe/gldriver/ui/mine/MineFragment.kt +++ b/app/src/main/java/com/dahe/gldriver/ui/mine/MineFragment.kt @@ -190,13 +190,13 @@ class MineFragment : BaseFragment(), View.OnClickListener, DataManager.getInstance().getUserInfo() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(BaseObserver(mContext, object : RxHttpCallBack() { + .subscribe(BaseObserver(mContext, object : RxHttpCallBack(binding.refresh) { override fun onSuccess(t: CommonResponseBean) { super.onSuccess(t) + binding.refresh.finishRefresh() if (t==null||t.data==null) return UserUtils.instance.updateUser(mContext, t.data) - binding.refresh.finishRefresh() refreshView() } }))