| | |
| | | /** |
| | | * Created on 2018/4/12. |
| | | */ |
| | | |
| | | inline fun <reified O, I : ResultData<O>> Flowable<I>.request(activity: BaseActivity, showToast: Boolean = true, crossinline success: (msg:String?, t: O?) -> Unit, crossinline error : (code: Int, msg: String) -> Unit) { |
| | | this.defaultScheduler().subscribe(object : ResultDataSubscriber<O>(activity){ |
| | | inline fun <reified O, I : ResultData<O>> Flowable<I>.request( |
| | | activity: BaseActivity, |
| | | showToast: Boolean = true, |
| | | showDialog: Boolean = false, |
| | | crossinline success: (msg: String?, t: O?) -> Unit, |
| | | crossinline error: (code: Int, msg: String) -> Unit |
| | | ) { |
| | | if (showDialog) { |
| | | activity.showDialog() |
| | | } |
| | | this.defaultScheduler().subscribe(object : ResultDataSubscriber<O>(activity) { |
| | | override fun onSuccess(msg: String?, data: O?) { |
| | | success(msg,data) |
| | | activity.dismissDialog() |
| | | success(msg, data) |
| | | } |
| | | |
| | | override fun isShowToast() = showToast |
| | | |
| | | override fun onError(code: Int, msg: String) { |
| | | if (code == 600){//token无效 |
| | | super.onError(code, when(SPUtils.instance().getString("language","en")){ |
| | | "ch"->"您的身份已过期,请重新登录" |
| | | "fr"->"Votre identité a expiré, veuillez vous reconnecter" |
| | | else->"Your identity has expired, please log in again" |
| | | }) |
| | | SPUtils.instance().remove(Const.User.TOKEN).remove(Const.User.USER_ID).remove(Const.User.NO_PHONE).remove(Const.User.EMAIL).apply() |
| | | activity.dismissDialog() |
| | | if (code == 600) {//token无效 |
| | | super.onError( |
| | | code, when (SPUtils.instance().getString("language", "en")) { |
| | | "ch" -> "您的身份已过期,请重新登录" |
| | | "fr" -> "Votre identité a expiré, veuillez vous reconnecter" |
| | | else -> "Your identity has expired, please log in again" |
| | | } |
| | | ) |
| | | SPUtils.instance().remove(Const.User.TOKEN).remove(Const.User.USER_ID) |
| | | .remove(Const.User.NO_PHONE).remove(Const.User.EMAIL).apply() |
| | | activity.gotoLogin() |
| | | }else{ |
| | | } else { |
| | | super.onError(code, msg) |
| | | error(code,msg) |
| | | error(code, msg) |
| | | } |
| | | activity.dismissDialog() |
| | | } |
| | | }) |
| | | } |
| | | inline fun <reified O, I : ResultData<O>> Flowable<I>.request(activity: BaseActivity, showToast: Boolean = true, crossinline success: (msg:String?, t: O?) -> Unit) { |
| | | request(activity,showToast,success){_,_->} |
| | | |
| | | inline fun <reified O, I : ResultData<O>> Flowable<I>.request( |
| | | activity: BaseActivity, |
| | | showToast: Boolean = true, |
| | | crossinline success: (msg: String?, t: O?) -> Unit, |
| | | crossinline error: (code: Int, msg: String) -> Unit |
| | | ) { |
| | | request(activity, showToast, false, success, error) |
| | | } |
| | | |
| | | inline fun <reified O, I : ResultData<O>> Flowable<I>.requestByF(fragment: BaseFragment, showToast: Boolean = true, crossinline success: (msg:String?, t: O?) -> Unit, crossinline error : (code: Int, msg: String) -> Unit) { |
| | | this.defaultScheduler().subscribe(object : ResultDataSubscriber<O>(fragment){ |
| | | inline fun <reified O, I : ResultData<O>> Flowable<I>.request( |
| | | activity: BaseActivity, |
| | | showToast: Boolean = true, |
| | | showDialog: Boolean = false, |
| | | crossinline success: (msg: String?, t: O?) -> Unit |
| | | ) { |
| | | request(activity, showToast, showDialog, success) { _, _ -> } |
| | | } |
| | | |
| | | inline fun <reified O, I : ResultData<O>> Flowable<I>.requestByF( |
| | | fragment: BaseFragment, |
| | | showToast: Boolean = true, |
| | | showDialog: Boolean = false, |
| | | crossinline success: (msg: String?, t: O?) -> Unit, |
| | | crossinline error: (code: Int, msg: String) -> Unit |
| | | ) { |
| | | if (showDialog) { |
| | | fragment.showDialog() |
| | | } |
| | | this.defaultScheduler().subscribe(object : ResultDataSubscriber<O>(fragment) { |
| | | override fun onSuccess(msg: String?, data: O?) { |
| | | fragment.dismissDialog() |
| | | success(msg,data) |
| | | success(msg, data) |
| | | } |
| | | |
| | | override fun isShowToast() = showToast |
| | | |
| | | override fun onError(code: Int, msg: String) { |
| | | fragment.dismissDialog() |
| | | if (code == 600){//token无效 |
| | | if (code == 600) {//token无效 |
| | | // super.onError(code, "您的身份已过期,请重新登录") |
| | | SPUtils.instance().remove(Const.User.TOKEN).remove(Const.User.USER_ID).remove(Const.User.NO_PHONE).remove(Const.User.EMAIL).apply() |
| | | SPUtils.instance().remove(Const.User.TOKEN).remove(Const.User.USER_ID) |
| | | .remove(Const.User.NO_PHONE).remove(Const.User.EMAIL).apply() |
| | | fragment.gotoLogin() |
| | | }else{ |
| | | } else { |
| | | super.onError(code, msg) |
| | | error(code,msg) |
| | | error(code, msg) |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | inline fun <reified O, I : ResultData<O>> Flowable<I>.requestByF(fragment: BaseFragment, showToast: Boolean = true, crossinline success: (msg:String?, t: O?) -> Unit) { |
| | | requestByF(fragment,showToast,success){_,_->} |
| | | |
| | | inline fun <reified O, I : ResultData<O>> Flowable<I>.requestByF( |
| | | fragment: BaseFragment, |
| | | showToast: Boolean = true, |
| | | crossinline success: (msg: String?, t: O?) -> Unit, |
| | | crossinline error: (code: Int, msg: String) -> Unit |
| | | ) { |
| | | requestByF(fragment, showToast, false, success, error) |
| | | } |
| | | |
| | | inline fun <reified O, I : ResultData<O>> Flowable<I>.requestByF( |
| | | fragment: BaseFragment, |
| | | showToast: Boolean = true, |
| | | crossinline success: (msg: String?, t: O?) -> Unit |
| | | ) { |
| | | requestByF(fragment, showToast, success) { _, _ -> } |
| | | } |
| | | |