opt
This commit is contained in:
@@ -6,7 +6,7 @@ import androidx.collection.ArrayMap;
|
||||
import java.util.Map;
|
||||
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
|
||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
public final class RetrofitFactory {
|
||||
@@ -21,7 +21,7 @@ public final class RetrofitFactory {
|
||||
target = new Retrofit.Builder().
|
||||
client(OkHttpFactory.getInstance()).
|
||||
baseUrl(baseUrl).
|
||||
addCallAdapterFactory(RxJavaCallAdapterFactory.create()).
|
||||
addCallAdapterFactory( RxJava2CallAdapterFactory.create()).
|
||||
addConverterFactory(GsonConverterFactory.create()).
|
||||
build();
|
||||
sRpcServiceMap.put(baseUrl,target);
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
package com.mogo.utils.network;
|
||||
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
|
||||
|
||||
import com.mogo.utils.network.ui.ProgressDialog;
|
||||
import com.mogo.utils.network.utils.Util;
|
||||
|
||||
import rx.Subscriber;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Extension of {@link Subscriber}. For better extension and customization, client can extend this
|
||||
* class to override the default behaviours such as loading appearance on each lifecycle method
|
||||
* of network callback.<p/>
|
||||
*/
|
||||
|
||||
public abstract class SubscriberEx< T > extends Subscriber< T > {
|
||||
protected final RequestOptions mRequestOptions;
|
||||
private ProgressDialog mProgressDialog;
|
||||
|
||||
public SubscriberEx( RequestOptions requestOptions ) {
|
||||
if ( requestOptions == null ) {
|
||||
throw new IllegalArgumentException( "RequestOptions cannot be null" );
|
||||
}
|
||||
this.mRequestOptions = requestOptions;
|
||||
if ( mRequestOptions.isLoading() ) {
|
||||
this.mProgressDialog = new ProgressDialog();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method must be called if you want to use the default loading dialog in case of override.
|
||||
* Otherwise you can ignore it.
|
||||
*/
|
||||
@Override
|
||||
@CallSuper
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if ( !Util.checkAlive( mRequestOptions.getCaller() ) ) {
|
||||
unsubscribe();
|
||||
return;
|
||||
}
|
||||
if ( mRequestOptions.isLoading() && mProgressDialog != null ) {
|
||||
mProgressDialog.showLoadingDialog( mRequestOptions.getContext(), mRequestOptions.getLoadingMessage(), mRequestOptions.isCancelable(), mRequestOptions.isCancelableOnTouchOutside() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method must be called if you want to use the default loading dialog in case of override.
|
||||
* Otherwise you can ignore it.
|
||||
*/
|
||||
private void onFinish() {
|
||||
if ( mRequestOptions.isLoading() && mProgressDialog != null ) {
|
||||
mProgressDialog.removeLoadingDialog();
|
||||
mProgressDialog = null;
|
||||
}
|
||||
if ( !Util.checkAlive( mRequestOptions.getCaller() ) ) {
|
||||
unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method must be called if you want to use the default loading dialog in case of override.
|
||||
* Otherwise you can ignore it.
|
||||
*/
|
||||
@Override
|
||||
@CallSuper
|
||||
public void onCompleted() {
|
||||
onFinish();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method must be called if you want to use the default loading dialog in case of override.
|
||||
* Otherwise you can ignore it.
|
||||
*/
|
||||
@Override
|
||||
@CallSuper
|
||||
public void onError( Throwable e ) {
|
||||
onFinish();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method must be override if you care about the result of request.
|
||||
*
|
||||
* @param o The result of network request
|
||||
*/
|
||||
@Override
|
||||
@CallSuper
|
||||
public void onNext( T o ) {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user