private Retrofit retrofit;
private static final class RetrofitManangerHolder {
private static final RetrofitMananger RETROFIT_MANANGER = new RetrofitMananger ( ) ;
}
public static RetrofitMananger getInstance ( ) {
return RetrofitManangerHolder. RETROFIT_MANANGER;
}
private static OkHttpClient okHttpClient ( ) {
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor ( ) ;
httpLoggingInterceptor. setLevel ( HttpLoggingInterceptor. Level. BODY) ;
OkHttpClient build = new OkHttpClient. Builder ( )
. writeTimeout ( 10 , TimeUnit. SECONDS)
. readTimeout ( 10 , TimeUnit. SECONDS)
. connectTimeout ( 10 , TimeUnit. SECONDS)
. addInterceptor ( httpLoggingInterceptor)
. addInterceptor ( new headerInterceptro ( ) )
. build ( ) ;
return build;
}
private RetrofitMananger ( ) {
retrofit = new Retrofit. Builder ( )
. baseUrl ( MyUrl. Base_Url)
. client ( okHttpClient ( ) )
. addCallAdapterFactory ( RxJava2CallAdapterFactory. create ( ) )
. addConverterFactory ( GsonConverterFactory. create ( ) )
. build ( ) ;
}
private static final class headerInterceptro implements Interceptor {
@RequiresApi ( api = Build. VERSION_CODES. JELLY_BEAN_MR1)
@Override
public Response intercept ( Chain chain) throws IOException {
Request request = chain. request ( ) ;
Request build = request. newBuilder ( )
. addHeader ( "sessionId" , "16067915695491719" )
. addHeader ( "userId" , "1719" )
. addHeader ( "ak" , "0110010010000" )
. build ( ) ;
return chain. proceed ( build) ;
}
}
public IApi create ( ) {
return retrofit. create ( IApi. class ) ;
}
public static boolean isNext ( Context context) {
ConnectivityManager systemService
= ( ConnectivityManager) context. getSystemService ( Context. CONNECTIVITY_SERVICE) ;
NetworkInfo activeNetworkInfo = systemService. getActiveNetworkInfo ( ) ;
if ( activeNetworkInfo!= null && activeNetworkInfo. isConnected ( ) ) {
return true ;
}
return false ;
}