riku
2025-07-02 3013b813e5df6977c0be921928f73b1a3adde290
app/src/main/java/cn/flightfeather/thirdappmodule/common/net/RetrofitFactory.kt
@@ -18,36 +18,41 @@
 * Date: 2019/7/22
 * 网络请求
 */
class RetrofitFactory constructor(val application: CommonApplication){
class RetrofitFactory constructor(val application: CommonApplication) {
    // 本系统飞羽监管后端接口ip
    val retrofit: Retrofit = application.retrofit
    val retrofitImage: Retrofit = application.retrofitImage
    private fun newOkHttpClient(list: List<Interceptor>): OkHttpClient =
            OkHttpClient.Builder()
                    .connectTimeout(20 * 1000L, TimeUnit.MILLISECONDS)
                    .apply {
                        list.forEach {
                            addInterceptor(it)
                        }
                    }
                    .build()
    // 飞羽环境系统后端接口ip
    lateinit var retrofit2: Retrofit
    private fun newRetrofit(mOkHttpClient: OkHttpClient): Retrofit =
            Retrofit.Builder()
                    .apply {
                        baseUrl(application.ROOT_URL_RELEASE)
                    }
                    .addConverterFactory(
                            GsonConverterFactory.create(
                                    GsonBuilder()
                                            .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
                                            .create()
                            )
                    )
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .client(mOkHttpClient)
                    .build()
    init {
        retrofit2 = newRetrofit(application.ROOT_URL_RELEASE_2)
    }
    private fun newOkHttpClient(list: List<Interceptor>): OkHttpClient =
        OkHttpClient.Builder()
            .connectTimeout(20 * 1000L, TimeUnit.MILLISECONDS)
            .apply {
                list.forEach {
                    addInterceptor(it)
                }
            }
            .build()
    private fun newRetrofit(url: String, mOkHttpClient: OkHttpClient? = null): Retrofit =
        Retrofit.Builder()
            .baseUrl(url)
            .addConverterFactory(
                GsonConverterFactory.create(
                    GsonBuilder()
                        .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
                        .create()
                )
            )
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .apply { mOkHttpClient?.let { client(it) } }
            .build()
    companion object {
@@ -65,8 +70,8 @@
         */
        fun <T> executeResult(observable: Observable<Response<T>>, subscriber: ResultObserver<T>) {
            observable.subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(subscriber)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber)
        }
        fun withProgressListeningRetrofit(listener: NetWorkProgressListener?): Retrofit {
@@ -74,7 +79,7 @@
                instance.retrofit
            } else {
                val c = instance.newOkHttpClient(listOf(NetWorkProgressInterceptor(listener)))
                instance.newRetrofit(c)
                instance.newRetrofit(instance.application.ROOT_URL_RELEASE, c)
            }
        }
    }