提交 b42b1978 编写于 作者: J jessyan

Improve AppComponent

上级 599a50ec
......@@ -29,8 +29,6 @@ import com.jess.arms.base.App;
import com.jess.arms.base.BaseApplication;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.di.component.DaggerAppComponent;
import com.jess.arms.di.module.AppModule;
import com.jess.arms.di.module.ClientModule;
import com.jess.arms.di.module.GlobalConfigModule;
import com.jess.arms.integration.ActivityLifecycle;
import com.jess.arms.integration.ConfigModule;
......@@ -100,8 +98,7 @@ public class AppDelegate implements App, AppLifecycles {
this.mApplication = application;
mAppComponent = DaggerAppComponent
.builder()
.appModule(new AppModule(mApplication))//提供application
.clientModule(new ClientModule())//用于提供okhttp和retrofit的单例
.application(mApplication)//提供application
.globalConfigModule(getGlobalConfigModule(mApplication, mModules))//全局配置
.build();
mAppComponent.inject(this);
......
......@@ -33,6 +33,7 @@ import java.io.File;
import javax.inject.Singleton;
import dagger.BindsInstance;
import dagger.Component;
import me.jessyan.rxerrorhandler.core.RxErrorHandler;
import okhttp3.OkHttpClient;
......@@ -80,4 +81,12 @@ public interface AppComponent {
Cache.Factory cacheFactory();
void inject(AppDelegate delegate);
@Component.Builder
interface Builder {
@BindsInstance
Builder application(Application application);
Builder globalConfigModule(GlobalConfigModule globalConfigModule);
AppComponent build();
}
}
......@@ -47,17 +47,6 @@ import dagger.Provides;
*/
@Module
public class AppModule {
private Application mApplication;
public AppModule(Application application) {
this.mApplication = application;
}
@Singleton
@Provides
public Application provideApplication() {
return mApplication;
}
@Singleton
@Provides
......
......@@ -32,6 +32,7 @@ import com.jess.arms.integration.cache.Cache;
import com.jess.arms.integration.cache.CacheType;
import com.jess.arms.integration.cache.LruCache;
import com.jess.arms.utils.DataHelper;
import com.jess.arms.utils.Preconditions;
import java.io.File;
import java.util.ArrayList;
......@@ -251,10 +252,7 @@ public class GlobalConfigModule {
}
public Builder baseurl(BaseUrl baseUrl) {
if (baseUrl == null) {
throw new NullPointerException("BaseUrl can not be null");
}
this.baseUrl = baseUrl;
this.baseUrl = Preconditions.checkNotNull(baseUrl, BaseUrl.class.getCanonicalName() + "can not be null.");
return this;
}
......@@ -308,16 +306,12 @@ public class GlobalConfigModule {
}
public Builder printHttpLogLevel(RequestInterceptor.Level printHttpLogLevel) {//是否让框架打印 Http 的请求和响应信息
if (printHttpLogLevel == null)
throw new NullPointerException("printHttpLogLevel == null. Use RequestInterceptor.Level.NONE instead.");
this.printHttpLogLevel = printHttpLogLevel;
this.printHttpLogLevel = Preconditions.checkNotNull(printHttpLogLevel, "The printHttpLogLevel can not be null, use RequestInterceptor.Level.NONE instead.");
return this;
}
public Builder formatPrinter(FormatPrinter formatPrinter){
if (formatPrinter == null)
throw new NullPointerException("FormatPrinter can not be null");
this.formatPrinter = formatPrinter;
this.formatPrinter = Preconditions.checkNotNull(formatPrinter, FormatPrinter.class.getCanonicalName() + "can not be null.");
return this;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册