Alibaba fit tool Class Analysis in mobile development
Replace MySerVice with your own interface
Package com. example. a05_weekexamdemo.util;
Import okhttp3.OkHttpClient;
Import into fit2.20.fit;
Import Export fit2.adapter. rxjava. RxJavaCallAdapterFactory;
Import into fit2.converter. gson. GsonConverterFactory;
/**
* Created by yujie on April /12/30.
*/
Public class extends fithelper {
Public static OkHttpClient okHttpClient;
Public static MySerVice mySerVice;
Static {
GetOkHttpClient ();
}
Public static OkHttpClient getOkHttpClient (){
If (okHttpClient = null ){
Synchronized (OkHttpClient. class ){
If (okHttpClient = null ){
OkHttpClient = new OkHttpClient ();
}
}
}
Return okHttpClient;
}
Public static MySerVice getMySerVice (String url ){
If (mySerVice = null ){
Synchronized (MySerVice. class ){
If (mySerVice = null ){
MySerVice = createMyService (MySerVice. class, url );
}
}
}
Return mySerVice;
}
Private static T createMyService (Class tClass, String url ){
T t = new fit. Builder ()
. BaseUrl (url)
. AddConverterFactory (GsonConverterFactory. create ())
. AddCallAdapterFactory (RxJavaCallAdapterFactory. create ())
. Build ()
. Create (tClass );
Return t;
}
}