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() } }))