Last active
October 12, 2017 19:42
-
-
Save alouanemed/68e1e1aa27fe8749bb51efbbfa004d7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module public abstract class ActivityBindingModule { | |
@ActivityScoped @ContributesAndroidInjector(modules = MainModule.class) | |
abstract MainActivity mainActivity(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton @Component(modules = { | |
AppModule.class, ActivityBindingModule.class, AndroidSupportInjectionModule.class, | |
ArticlesAppModule.class, NetworkModule.class, DataModule.class | |
}) public interface AppComponent extends AndroidInjector<ArticlesApp> { | |
Realm realm(); | |
User currentUser(); | |
@Component.Builder abstract class Builder extends AndroidInjector.Builder<ArticlesApp> { | |
@BindsInstance public abstract Builder application(Application application); | |
public abstract Builder appModule(ArticlesAppModule appm); | |
public abstract Builder networkModule(NetworkModule networkModule); | |
public abstract AppComponent build(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ArticlesApp extends DaggerApplication { | |
public static ArticlesApp getApp(Context context) { | |
return (ArticlesApp) context.getApplicationContext(); | |
} | |
@Override public void onCreate() { | |
super.onCreate(); | |
initDependencies(); | |
} | |
private void initDependencies() { | |
..... | |
} | |
@Override protected AndroidInjector<? extends DaggerApplication> applicationInjector() { | |
return DaggerArticlesComponent.builder() | |
.application(this) | |
.ArticlesAppModule(new ArticlesAppModule(this)) | |
.networkModule(new NetworkModule()) | |
.create(this); | |
} | |
@Override protected void attachBaseContext(Context base) { | |
super.attachBaseContext(base); | |
MultiDex.install(this); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module public class ArticlesAppModule { | |
private ArticlesApp app; | |
@Inject public ArticlesAppModule(ArticlesApp app) { | |
this.app = app; | |
} | |
@Provides @Singleton static RealmConfiguration provideRealmConfiguration() { | |
RealmConfiguration.Builder builder = new RealmConfiguration.Builder(); | |
if (BuildConfig.DEBUG) { | |
builder = builder.deleteRealmIfMigrationNeeded(); | |
} | |
return builder.build(); | |
} | |
/*... Other dependencies....*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ArticlesFragment | |
extends BaseFragment<ArticlesContract.Presenter, ArticlesContract.View> | |
implements ArticlesContract.View, SwipeRefreshLayout.OnRefreshListener { | |
@Inject PresenterFactory<ArticlesContract.Presenter> mPresenterFactory; | |
/* ... Init views handle fragment intercation..no dagger stuff here.. */ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module public abstract class ArticlesModule { | |
@FragmentScoped @Provides public PresenterFactory<ArticlesContract.Presenter> providePresenterFactory( | |
DataManager data) { | |
return () -> new ArticlesPresenter(data); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class BaseActivity<P extends BasePresenter<V>, V> extends DaggerAppCompatActivity | |
implements LoaderManager.LoaderCallbacks<P> { | |
/*... init layout, toolbar and android stuff, no dagger stuff related ....*/ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends BaseActivity<MainContract.Presenter, MainContract.View> | |
implements MainContract.View, OnTabSelectListener { | |
public static final int REQUEST_CONNECT = 199; | |
@Inject PresenterFactory<MainContract.Presenter> mPresenterFactory; | |
/*... Views....*/ | |
/*... Handle Bottom view tabs on click ....*/ | |
... | |
case R.id.tab_articles: | |
fragmentClass = ArticlesFragment.class; | |
break; | |
try { | |
if (fragmentClass != null) selectedFragment = (Fragment) fragmentClass.newInstance(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
if (fragmentClass != null) { | |
fragmentManager.beginTransaction() | |
.replace(R.id.frame_layout, selectedFragment) | |
.commitAllowingStateLoss(); | |
setTitle(mTabTitle); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module public abstract class MainModule { | |
@FragmentScoped | |
@ContributesAndroidInjector(modules = ArticlesModule.class) abstract ArticlesFragment articlesFragment(); | |
@Provides @ActivityScoped static String provideTaskId(MainActivity activity) { | |
return activity.getIntent().getStringExtra(""); | |
} | |
//have any idea on how to improve this ??? | |
@ActivityScoped @Provides | |
public PresenterFactory<MainContract.Presenter> providePresenterFactory() { | |
return MainPresenter::new; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment