请求失败刷新取消优化
This commit is contained in:
parent
548003a5d9
commit
1b3568664b
@ -10,6 +10,7 @@ import com.dahe.mylibrary.net.ResultException
|
|||||||
import com.dahe.mylibrary.utils.LoadingUtils
|
import com.dahe.mylibrary.utils.LoadingUtils
|
||||||
import com.dahe.mylibrary.utils.ToastUtils
|
import com.dahe.mylibrary.utils.ToastUtils
|
||||||
import com.lxj.xpopup.impl.LoadingPopupView
|
import com.lxj.xpopup.impl.LoadingPopupView
|
||||||
|
import com.scwang.smart.refresh.layout.SmartRefreshLayout
|
||||||
import org.json.JSONException
|
import org.json.JSONException
|
||||||
import java.net.ConnectException
|
import java.net.ConnectException
|
||||||
import java.net.SocketTimeoutException
|
import java.net.SocketTimeoutException
|
||||||
@ -23,6 +24,7 @@ import javax.net.ssl.SSLException
|
|||||||
abstract class RxHttpCallBack<T> {
|
abstract class RxHttpCallBack<T> {
|
||||||
// private var dialog: ProgressDialog? = null
|
// private var dialog: ProgressDialog? = null
|
||||||
private var dialog: LoadingPopupView? = null
|
private var dialog: LoadingPopupView? = null
|
||||||
|
private var smartRefreshLayout: SmartRefreshLayout? = null
|
||||||
private fun initDialog(activity: AppCompatActivity?, dialogMessage: String) {
|
private fun initDialog(activity: AppCompatActivity?, dialogMessage: String) {
|
||||||
// dialog = ProgressDialog(activity)
|
// dialog = ProgressDialog(activity)
|
||||||
// dialog!!.requestWindowFeature(Window.FEATURE_NO_TITLE)
|
// dialog!!.requestWindowFeature(Window.FEATURE_NO_TITLE)
|
||||||
@ -45,6 +47,10 @@ abstract class RxHttpCallBack<T> {
|
|||||||
initDialog(activity, "网络请求中......")
|
initDialog(activity, "网络请求中......")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor(smartRefresh: SmartRefreshLayout) {
|
||||||
|
smartRefreshLayout = smartRefresh
|
||||||
|
}
|
||||||
|
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,6 +78,10 @@ abstract class RxHttpCallBack<T> {
|
|||||||
if (dialog != null && dialog!!.isShow) {
|
if (dialog != null && dialog!!.isShow) {
|
||||||
dialog!!.dismiss()
|
dialog!!.dismiss()
|
||||||
}
|
}
|
||||||
|
smartRefreshLayout?.let {
|
||||||
|
if (it.isRefreshing)
|
||||||
|
it.finishRefresh()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,13 +94,17 @@ abstract class RxHttpCallBack<T> {
|
|||||||
if (dialog != null && dialog!!.isShow) {
|
if (dialog != null && dialog!!.isShow) {
|
||||||
dialog!!.dismiss()
|
dialog!!.dismiss()
|
||||||
}
|
}
|
||||||
|
smartRefreshLayout?.let {
|
||||||
|
if (it.isRefreshing)
|
||||||
|
it.finishRefresh()
|
||||||
|
}
|
||||||
if (t.code == 401) {
|
if (t.code == 401) {
|
||||||
// instance.loginOut(mContext!!)
|
// instance.loginOut(mContext!!)
|
||||||
// Intent intent = new Intent(mContext, LoginActivity.class);
|
// Intent intent = new Intent(mContext, LoginActivity.class);
|
||||||
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
|
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
// mContext.startActivity(intent);
|
// mContext.startActivity(intent);
|
||||||
ToastUtils.showToast(mContext, "您的账号再异地登录,请重新登录")
|
ToastUtils.showToast(mContext, "您的账号再异地登录,请重新登录")
|
||||||
} else {
|
} else {
|
||||||
ToastUtils.showToast(mContext, t.msg)
|
ToastUtils.showToast(mContext, t.msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,6 +125,10 @@ abstract class RxHttpCallBack<T> {
|
|||||||
if (dialog != null && dialog!!.isShow) {
|
if (dialog != null && dialog!!.isShow) {
|
||||||
dialog!!.dismiss()
|
dialog!!.dismiss()
|
||||||
}
|
}
|
||||||
|
smartRefreshLayout?.let {
|
||||||
|
if (it.isRefreshing)
|
||||||
|
it.finishRefresh()
|
||||||
|
}
|
||||||
if (e is ConnectException
|
if (e is ConnectException
|
||||||
|| e is TimeoutException
|
|| e is TimeoutException
|
||||||
|| e is SocketTimeoutException
|
|| e is SocketTimeoutException
|
||||||
@ -127,7 +145,7 @@ abstract class RxHttpCallBack<T> {
|
|||||||
// System.out.println("---------errorCode------->"+((ResultException) e).getErrCode());
|
// System.out.println("---------errorCode------->"+((ResultException) e).getErrCode());
|
||||||
} else if (e is SSLException) {
|
} else if (e is SSLException) {
|
||||||
ToastUtils.showToast(mContext, "网络连接终端,请检查您的网络~")
|
ToastUtils.showToast(mContext, "网络连接终端,请检查您的网络~")
|
||||||
}else if (e is JSONException) {
|
} else if (e is JSONException) {
|
||||||
ToastUtils.showToast(mContext, "数据格式转换异常~")
|
ToastUtils.showToast(mContext, "数据格式转换异常~")
|
||||||
} else {
|
} else {
|
||||||
ToastUtils.showToast(mContext, e.message)
|
ToastUtils.showToast(mContext, e.message)
|
||||||
|
@ -190,13 +190,13 @@ class MineFragment : BaseFragment<FragmentMineBinding>(), View.OnClickListener,
|
|||||||
DataManager.getInstance().getUserInfo()
|
DataManager.getInstance().getUserInfo()
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(BaseObserver(mContext, object : RxHttpCallBack<UserBean>() {
|
.subscribe(BaseObserver(mContext, object : RxHttpCallBack<UserBean>(binding.refresh) {
|
||||||
override fun onSuccess(t: CommonResponseBean<UserBean>) {
|
override fun onSuccess(t: CommonResponseBean<UserBean>) {
|
||||||
super.onSuccess(t)
|
super.onSuccess(t)
|
||||||
|
binding.refresh.finishRefresh()
|
||||||
if (t==null||t.data==null)
|
if (t==null||t.data==null)
|
||||||
return
|
return
|
||||||
UserUtils.instance.updateUser(mContext, t.data)
|
UserUtils.instance.updateUser(mContext, t.data)
|
||||||
binding.refresh.finishRefresh()
|
|
||||||
refreshView()
|
refreshView()
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
Loading…
Reference in New Issue
Block a user