Skip to content

Commit

Permalink
开发retrofit对象,可用于自定义创建请求
Browse files Browse the repository at this point in the history
  • Loading branch information
VeiZhang committed Jul 17, 2018
1 parent 5fabb94 commit 855f40b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions retrofit/src/main/java/com/excellence/retrofit/RetrofitClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class RetrofitClient
public static final String TAG = RetrofitClient.class.getSimpleName();

private static RetrofitClient mInstance = null;
private Retrofit mRetrofit = null;
private RetrofitHttpService mService = null;
/**
* 全局请求头
Expand All @@ -82,6 +83,7 @@ public static RetrofitClient getInstance()

private RetrofitClient(Builder builder)
{
mRetrofit = builder.mRetrofit;
mService = builder.mService;
mHeaders = builder.mHeaders;
mParams = builder.mParams;
Expand All @@ -97,6 +99,11 @@ public void execute(@NonNull Runnable command)
};
}

public Retrofit getRetrofit()
{
return mRetrofit;
}

protected RetrofitHttpService getService()
{
return mService;
Expand Down Expand Up @@ -235,6 +242,7 @@ public static class Builder
private Context mContext = null;
private Retrofit.Builder mRetrofitBuilder = null;
private OkHttpClient.Builder mHttpClientBuilder = null;
private Retrofit mRetrofit = null;
private RetrofitHttpService mService = null;
private boolean cacheEnable = false;
private Cache mCache = null;
Expand Down Expand Up @@ -623,8 +631,8 @@ public void build()
mRetrofitBuilder.addCallAdapterFactory(RxJavaCallAdapterFactory.create());
}

Retrofit retrofit = mRetrofitBuilder.build();
mService = retrofit.create(RetrofitHttpService.class);
mRetrofit = mRetrofitBuilder.build();
mService = mRetrofit.create(RetrofitHttpService.class);
mInstance = new RetrofitClient(this);
}
}
Expand Down

0 comments on commit 855f40b

Please sign in to comment.