| | |
| | | |
| | | import android.content.Context |
| | | import android.util.Log |
| | | import com.dayu.baselibrary.business.BusinessProvider |
| | | import com.dayu.baselibrary.net.subscribers.ProgressSubscriber |
| | | import com.dayu.baselibrary.net.subscribers.SubscriberListener |
| | | import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers |
| | |
| | | |
| | | observable |
| | | .subscribeOn(Schedulers.io()) |
| | | .map(mapResponse(tClass)) |
| | | .map(mapResponse(context, tClass)) |
| | | .unsubscribeOn(Schedulers.newThread()) |
| | | .observeOn(AndroidSchedulers.mainThread()) |
| | | .subscribe(mySubscriber) |
| | | } |
| | | |
| | | private fun <T> mapResponse(tClass: Class<T>): Function<Any, BaseResponse<T>> { |
| | | private fun <T> mapResponse(context: Context, tClass: Class<T>): Function<Any, BaseResponse<T>> { |
| | | return Function { rawResponse -> |
| | | when (rawResponse) { |
| | | is BaseResponse<*> -> { |
| | |
| | | // 处理token失效的情况 |
| | | if (temp.code == NetConstans.TOKEN_INVALID) { |
| | | // 可以在这里添加重定向到登录页面的逻辑 |
| | | // redirectToLogin() |
| | | BusinessProvider.getBusinessProvider().startLoginNavigotor.navigateToLogin(context) |
| | | return@Function response |
| | | } |
| | | |