| | |
| | | package com.dayu.qiheonlinelibrary.net |
| | | package com.dayu.general.net |
| | | |
| | | import android.content.Context |
| | | import android.util.Log |
| | | import com.dayu.baselibrary.net.subscribers.ProgressSubscriber |
| | | import com.dayu.baselibrary.net.subscribers.SubscriberListener |
| | | import com.dayu.general.net.ApiService |
| | | import com.dayu.general.net.BaseResponse |
| | | import com.dayu.general.net.MyJsonParser |
| | | import com.dayu.general.net.NetConstans |
| | | import com.dayu.general.net.RetrofitClient |
| | | import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers |
| | | import io.reactivex.rxjava3.functions.Function |
| | | import io.reactivex.rxjava3.schedulers.Schedulers |
| | |
| | | @Volatile |
| | | private var apiManager: ApiManager? = null |
| | | |
| | | fun init() { |
| | | if (apiManager == null) { |
| | | synchronized(ApiManager::class) { |
| | | if (apiManager == null) { |
| | | apiManager = ApiManager() |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | fun getInstance(): ApiManager { |
| | | return apiManager ?: throw IllegalStateException("ApiManager not initialized") |
| | | return apiManager ?: synchronized(this) { |
| | | apiManager ?: ApiManager().also { apiManager = it } |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | val mySubscriber = ProgressSubscriber<BaseResponse<T>>(context, hideLoading, listener); |
| | | |
| | | observable |
| | | ?.subscribeOn(Schedulers.io()) |
| | | ?.map(mapResponse(tClass)) |
| | | ?.unsubscribeOn(Schedulers.newThread()) |
| | | ?.observeOn(AndroidSchedulers.mainThread()) |
| | | ?.subscribe(mySubscriber) |
| | | .subscribeOn(Schedulers.io()) |
| | | .map(mapResponse(tClass)) |
| | | .unsubscribeOn(Schedulers.newThread()) |
| | | .observeOn(AndroidSchedulers.mainThread()) |
| | | .subscribe(mySubscriber) |
| | | } |
| | | |
| | | private fun <T> mapResponse(tClass: Class<T>): Function<Any, BaseResponse<T>> { |