RetrofitManager的封裝

package com.example.videodemo;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;


public class RetrofitManager {
    private String baseUrl;
    private Retrofit retrofit;
    OkHttpClient client;
    private  static RetrofitManager retrofitManager;
    private RetrofitManager(){}
    private RetrofitManager(String baseUrl, OkHttpClient client) {
        this.baseUrl = baseUrl;
        this.client = client;
        initRetrofit();
    }

    public static synchronized RetrofitManager getinstantce(String baseUrl, OkHttpClient client){
        retrofitManager=new RetrofitManager(baseUrl,client);
        return retrofitManager;
    }

    public void initRetrofit(){
        retrofit=new Retrofit.Builder()
                .baseUrl(baseUrl)
                .client(client)
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    public <T> T setcreate(Class<T> regsServer){
        return retrofit.create(regsServer);
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章