| | |
| | | package com.dayu.qiheonlinelibrary.net; |
| | | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | |
| | | import android.text.TextUtils; |
| | | |
| | | import com.dayu.baselibrary.business.BusinessProvider; |
| | | import com.dayu.qiheonlinelibrary.net.subscribers.BaseProgressSubscriber; |
| | | import com.dayu.qiheonlinelibrary.net.subscribers.ProgressSubscriber; |
| | | import com.dayu.qiheonlinelibrary.net.subscribers.SubscriberListener; |
| | | import com.dayu.baselibrary.net.subscribers.BaseProgressSubscriber; |
| | | import com.dayu.baselibrary.net.subscribers.ProgressSubscriber; |
| | | import com.dayu.baselibrary.net.subscribers.SubscriberListener; |
| | | import com.dayu.qiheonlinelibrary.bean.BaseResult; |
| | | |
| | | import com.dayu.qiheonlinelibrary.utils.MyJsonParser; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileNotFoundException; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; |
| | | import io.reactivex.rxjava3.annotations.NonNull; |
| | | import io.reactivex.rxjava3.core.Observable; |
| | | import io.reactivex.rxjava3.core.Observer; |
| | | import io.reactivex.rxjava3.disposables.Disposable; |
| | | import io.reactivex.rxjava3.functions.Function; |
| | | import io.reactivex.rxjava3.schedulers.Schedulers; |
| | | import okhttp3.MediaType; |
| | | import okhttp3.MultipartBody; |
| | | import okhttp3.RequestBody; |
| | | import okhttp3.ResponseBody; |
| | | import retrofit2.Call; |
| | | import retrofit2.Callback; |
| | | import retrofit2.Response; |
| | | |
| | | |
| | | /** |
| | |
| | | public class ApiManager { |
| | | |
| | | static ApiManager apiManager; |
| | | //文件上传失败重复次数 |
| | | int uplodFilerepeatSize = 3; |
| | | |
| | | ApiService apiService; |
| | | |
| | |
| | | BaseResponse tem = (BaseResponse) o; |
| | | BaseResponse<T> response = new BaseResponse<>(); |
| | | //未登录或登录超时,请重新登录 |
| | | if (tem.getCode()==100401){ |
| | | if (BusinessProvider.getBusinessProvider()!=null){ |
| | | if (tem.getCode() == 100401) { |
| | | if (BusinessProvider.getBusinessProvider() != null) { |
| | | BusinessProvider.getBusinessProvider().startLoginNavigotor.navigateToLogin(context); |
| | | } |
| | | |
| | | } |
| | | |
| | | response.setCode(tem.getCode()); |
| | | response.setMsg(tem.getMsg()); |
| | | if (tClass!= null) { |
| | | if ( tem.getData() instanceof Map) { |
| | | try { |
| | | if (tClass != null) { |
| | | if (TextUtils.isEmpty(tem.getData().toString()) && BaseResult.class.isAssignableFrom(tClass)) { |
| | | response.setData(null); |
| | | return response; |
| | | } |
| | | if (tem.getData() instanceof Map) { |
| | | try { |
| | | // response.setData(MyJsonParser.getBeanFromMap((Map<String, Object>) tem.getData(), tClass)); |
| | | String jsonData = MyJsonParser.getJsontoMap((Map) tem.getData()); |
| | | response.setData(MyJsonParser.getBeanFromJson(jsonData, tClass)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } else if ( tem.getData() instanceof List) { |
| | | try { |
| | | response.setData((T) MyJsonParser.getListByJson(MyJsonParser.getJsonbyList((List) tem.getData()), tClass)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } else if ( tem.getData() instanceof Integer) { |
| | | response.setData((T) tem.getData()); |
| | | } else if (tem.getData() instanceof Boolean){ |
| | | response.setData((T) tem.getData()); |
| | | } |
| | | if ( tClass.getName() instanceof String && tem.getData() instanceof String) { |
| | | try { |
| | | String jsonData = MyJsonParser.getJsontoMap((Map) tem.getData()); |
| | | response.setData(MyJsonParser.getBeanFromJson(jsonData, tClass)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } else if (tem.getData() instanceof List) { |
| | | try { |
| | | response.setData((T) MyJsonParser.getListByJson(MyJsonParser.getJsonbyList((List) tem.getData()), tClass)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } else if (tem.getData() instanceof Integer) { |
| | | response.setData((T) tem.getData()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } else if (tem.getData() instanceof Boolean) { |
| | | response.setData((T) tem.getData()); |
| | | } |
| | | if (tClass.getName() instanceof String && tem.getData() instanceof String) { |
| | | try { |
| | | response.setData((T) tem.getData()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return response; |
| | | } |
| | | return response; |
| | | }} |
| | | } |
| | | |
| | | return null; |
| | | } |