导航菜单

页面标题

页面副标题

Biko v2.0.23 - RetrofitInstance.java 源代码

正在查看: Biko v2.0.23 应用的 RetrofitInstance.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package app.callpe.service;

import android.content.Context;
import app.callpe.common.utils.Helper;
import app.callpe.common.utils.helper_functions.LocaleHelper;
import app.callpe.common.utils.sharedpref.PrefKeys;
import app.callpe.common.utils.sharedpref.SharedPref;
import app.callpe.service.RetrofitInstance;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okio.GzipSource;
import okio.Okio;
import retrofit2.Converter;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import timber.log.Timber;

public class RetrofitInstance {
    private static final String BASE_URL = "https://prod.myfriendapp.in:9090/";
    private static Retrofit retrofitLogin;

    public static ApiService getLoginService(final Context context) {
        if (retrofitLogin == null) {
            final String language = LocaleHelper.getLanguage(context);
            retrofitLogin = new Retrofit.Builder().baseUrl("https://prod.myfriendapp.in:9090/").client(new OkHttpClient.Builder().addInterceptor(new Interceptor() {
                public final Response intercept(Interceptor.Chain chain) {
                    return RetrofitInstance.lambda$getLoginService$0(context, language, chain);
                }
            }).build()).addConverterFactory(new NullOnEmptyConverterFactory()).addConverterFactory(GsonConverterFactory.create()).build();
        }
        return (ApiService) retrofitLogin.create(ApiService.class);
    }

    static Response lambda$getLoginService$0(Context context, String str, Interceptor.Chain chain) throws IOException {
        ResponseBody body;
        String string = SharedPref.getString(context, PrefKeys.AUTH_TOKEN, null);
        Request.Builder header = chain.request().newBuilder().addHeader("User-Device-Details", Helper.getUserDeviceDetails(context)).addHeader("User-Language", Helper.getLanguage(str)).addHeader("Accept-Encoding", "gzip, deflat").header("app-version", String.valueOf(Helper.getVersionCode(context))).addHeader("User-Device-Id", Helper.getDeviceId(context)).header("PackageId", "app.b1k0").header("SOURCE", "app, app.b1k0");
        if (string != null && !string.isEmpty()) {
            header.addHeader("Authorization", "Bearer " + string);
        }
        Response proceed = chain.proceed(header.build());
        return (!"gzip".equalsIgnoreCase(proceed.header("Content-Encoding")) || (body = proceed.body()) == null) ? proceed : proceed.newBuilder().body(ResponseBody.create(Okio.buffer(new GzipSource(body.source())).readUtf8(), body.contentType())).removeHeader("Content-Encoding").build();
    }

    public static void setLoginRetrofit(Retrofit retrofit) {
        retrofitLogin = retrofit;
    }

    public static class NullOnEmptyConverterFactory extends Converter.Factory {
        public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
            final Converter nextResponseBodyConverter = retrofit.nextResponseBodyConverter(this, type, annotations);
            return new Converter() {
                public final Object convert(Object obj) {
                    return RetrofitInstance.NullOnEmptyConverterFactory.lambda$responseBodyConverter$0(nextResponseBodyConverter, (ResponseBody) obj);
                }
            };
        }

        static Object lambda$responseBodyConverter$0(Converter converter, ResponseBody responseBody) throws IOException {
            if (responseBody.contentLength() == 0) {
                return null;
            }
            try {
                return converter.convert(responseBody);
            } catch (Exception e) {
                Timber.e(e, "NullOn Error ", new Object[0]);
                return null;
            }
        }
    }
}