Skip to content

Commit

Permalink
add Flow to dagger module
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhuinden committed Jan 18, 2017
1 parent 5069045 commit 7b8f0f2
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
@@ -1,17 +1,24 @@
package com.zhuinden.examplegithubclient.application.injection.config;

import com.zhuinden.examplegithubclient.application.injection.modules.InteractorModule;
import com.zhuinden.examplegithubclient.application.injection.modules.NavigationModule;
import com.zhuinden.examplegithubclient.application.injection.modules.OkHttpModule;
import com.zhuinden.examplegithubclient.application.injection.modules.RetrofitModule;
import com.zhuinden.examplegithubclient.application.injection.modules.ServiceModule;
import com.zhuinden.examplegithubclient.presentation.activity.main.DaggerMainComponent;
import com.zhuinden.examplegithubclient.presentation.activity.main.MainComponent;

import flowless.Flow;

/**
* Created by Zhuinden on 2016.12.21..
*/

public class MainComponentConfig {
public interface Provider<T> {
T get();
}

private MainComponentConfig() {
}

Expand All @@ -20,12 +27,17 @@ private MainComponentConfig() {
static InteractorModule interactorModule = new InteractorModule();
static ServiceModule serviceModule = new ServiceModule();

public static MainComponent create() {
static Provider<NavigationModule> navigationModule(Flow flow) {
return () -> new NavigationModule(flow);
}

public static MainComponent create(Flow flow) {
return DaggerMainComponent.builder() //
.navigationModule(navigationModule(flow).get()) //
.okHttpModule(okHttpModule) //
.retrofitModule(retrofitModule) //
.interactorModule(interactorModule) //
.serviceModule(serviceModule) //
.build(); //
}
}
}
@@ -0,0 +1,35 @@
package com.zhuinden.examplegithubclient.application.injection.modules;

import dagger.Module;
import dagger.Provides;
import flowless.Flow;
import flowless.KeyManager;
import flowless.ServiceProvider;

/**
* Created by Owner on 2017. 01. 18..
*/

@Module
public class NavigationModule {
private Flow flow;

public NavigationModule(Flow flow) {
this.flow = flow;
}

@Provides
Flow flow() {
return flow;
}

@Provides
ServiceProvider serviceProvider() {
return flow.getServices();
}

@Provides
KeyManager keyManager() {
return flow.getStates();
}
}
Expand Up @@ -46,11 +46,12 @@ private void injectServices() {
return;
}
didInject = true;
Flow flow = Flow.get(getBaseContext());
ServiceProvider serviceProvider = ServiceProvider.get(getBaseContext());
MainKey mainKey = Flow.getKey(getBaseContext());
MainComponent mainComponent;
if(!serviceProvider.hasService(mainKey, DaggerService.TAG)) {
mainComponent = MainComponentConfig.create();
mainComponent = MainComponentConfig.create(flow);
serviceProvider.bindService(mainKey, DaggerService.TAG, mainComponent);
} else {
mainComponent = DaggerService.getGlobalComponent(getBaseContext());
Expand Down
Expand Up @@ -2,6 +2,7 @@

import com.zhuinden.examplegithubclient.application.injection.ActivityScope;
import com.zhuinden.examplegithubclient.application.injection.modules.InteractorModule;
import com.zhuinden.examplegithubclient.application.injection.modules.NavigationModule;
import com.zhuinden.examplegithubclient.application.injection.modules.OkHttpModule;
import com.zhuinden.examplegithubclient.application.injection.modules.RepositoryModule;
import com.zhuinden.examplegithubclient.application.injection.modules.RetrofitModule;
Expand All @@ -16,15 +17,24 @@
import com.zhuinden.examplegithubclient.util.AnnotationCache;

import dagger.Component;
import flowless.Flow;
import flowless.KeyManager;
import flowless.ServiceProvider;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;

/**
* Created by Owner on 2016.12.10.
*/
@ActivityScope
@Component(modules = {OkHttpModule.class, RetrofitModule.class, InteractorModule.class, RepositoryModule.class, ServiceModule.class})
@Component(modules = {OkHttpModule.class, RetrofitModule.class, InteractorModule.class, NavigationModule.class, RepositoryModule.class, ServiceModule.class})
public interface MainComponent {
Flow flow();

ServiceProvider serviceProvider();

KeyManager keyManager();

HeaderInterceptor headerInterceptor();

AnnotationCache annotationCache();
Expand Down
Expand Up @@ -35,6 +35,8 @@ public class MainPresenter
@Inject
AnnotationCache annotationCache;

@Inject
Flow flow;

@Inject
public MainPresenter() {
Expand Down Expand Up @@ -100,7 +102,7 @@ public void setTitle(int title) {
}
}

public void goToKey(Flow flow, Object newKey) {
public void goToKey(Object newKey) {
closeDrawer();
if(newKey instanceof LoginKey) {
flow.setHistory(History.single(newKey), Direction.FORWARD);
Expand Down
Expand Up @@ -57,7 +57,7 @@ public void onClickDrawerItem(View view) {
Object newKey = leftDrawerItem.getKeyCreator().createKey();
MainComponent component = DaggerService.getGlobalComponent(context);
MainPresenter mainPresenter = component.mainPresenter();
mainPresenter.goToKey(Flow.get(view), newKey);
mainPresenter.goToKey(newKey);
}

public LeftDrawerViewHolder(View itemView) {
Expand Down

0 comments on commit 7b8f0f2

Please sign in to comment.