Permalink
Browse files

Scoped Dependencies

  • Loading branch information...
CROSP committed Oct 29, 2018
1 parent eb721b9 commit c27d59e7a57c003a5d4460eaa70a9f123c030622
Showing with 1,362 additions and 206 deletions.
  1. BIN .gradle/4.6/fileContent/fileContent.lock
  2. BIN .gradle/4.6/fileHashes/fileHashes.bin
  3. BIN .gradle/4.6/fileHashes/fileHashes.lock
  4. BIN .gradle/4.6/javaCompile/classAnalysis.bin
  5. BIN .gradle/4.6/javaCompile/javaCompile.lock
  6. BIN .gradle/4.6/javaCompile/taskHistory.bin
  7. BIN .gradle/4.6/taskHistory/taskHistory.bin
  8. BIN .gradle/4.6/taskHistory/taskHistory.lock
  9. BIN .gradle/buildOutputCleanup/buildOutputCleanup.lock
  10. +6 −0 .idea/vcs.xml
  11. +744 −145 .idea/workspace.xml
  12. +9 −10 app/src/main/java/net/crosp/android/dagger2scopeinternals/base/ui/activity/BaseActivity.java
  13. +28 −0 ...rc/main/java/net/crosp/android/dagger2scopeinternals/di/component/activity/ActivityComponent.java
  14. +74 −0 ...ain/java/net/crosp/android/dagger2scopeinternals/di/component/activity/module/ActivityModule.java
  15. +4 −6 ...n/java/net/crosp/android/dagger2scopeinternals/di/component/application/ApplicationComponent.java
  16. +13 −0 ...ava/net/crosp/android/dagger2scopeinternals/module/main/di/components/MainFirstViewComponent.java
  17. +18 −0 ...n/java/net/crosp/android/dagger2scopeinternals/module/main/di/components/MainScreenComponent.java
  18. +13 −0 ...va/net/crosp/android/dagger2scopeinternals/module/main/di/components/MainSecondViewComponent.java
  19. +24 −0 .../java/net/crosp/android/dagger2scopeinternals/module/main/di/modules/MainFirstFragmentModule.java
  20. +23 −0 ...rc/main/java/net/crosp/android/dagger2scopeinternals/module/main/di/modules/MainScreenModule.java
  21. +24 −0 ...java/net/crosp/android/dagger2scopeinternals/module/main/di/modules/MainSecondFragmentModule.java
  22. +25 −5 app/src/main/java/net/crosp/android/dagger2scopeinternals/module/main/ui/MainActivity.java
  23. +6 −10 app/src/main/java/net/crosp/android/dagger2scopeinternals/module/main/ui/MainFirstFragment.java
  24. +72 −0 app/src/main/java/net/crosp/android/dagger2scopeinternals/module/main/ui/MainSecondFragment.java
  25. +13 −0 ...osp/android/dagger2scopeinternals/module/secondary/di/components/SecondaryFirstViewComponent.java
  26. +18 −0 .../crosp/android/dagger2scopeinternals/module/secondary/di/components/SecondaryScreenComponent.java
  27. +13 −0 ...sp/android/dagger2scopeinternals/module/secondary/di/components/SecondarySecondViewComponent.java
  28. +24 −0 ...crosp/android/dagger2scopeinternals/module/secondary/di/modules/SecondaryFirstFragmentModule.java
  29. +23 −0 ...va/net/crosp/android/dagger2scopeinternals/module/secondary/di/modules/SecondaryScreenModule.java
  30. +24 −0 ...rosp/android/dagger2scopeinternals/module/secondary/di/modules/SecondarySecondFragmentModule.java
  31. +33 −4 app/src/main/java/net/crosp/android/dagger2scopeinternals/module/secondary/ui/SecondaryActivity.java
  32. +16 −12 .../dagger2scopeinternals/module/secondary/ui/{MainFirstFragment.java → SecondaryFirstFragment.java}
  33. +60 −0 ...ain/java/net/crosp/android/dagger2scopeinternals/module/secondary/ui/SecondarySecondFragment.java
  34. +1 −8 app/src/main/res/layout/fragment_main_first.xml
  35. +24 −6 app/src/main/res/layout/fragment_main_second.xml
  36. +27 −0 app/src/main/res/layout/fragment_secondary_second.xml
  37. +3 −0 app/src/main/res/values/strings.xml
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -11,11 +11,15 @@
import android.view.ViewGroup;
import net.crosp.android.dagger2scopeinternals.base.ui.contract.ActivityController;
import net.crosp.android.dagger2scopeinternals.di.NamedConstants;
import net.crosp.android.dagger2scopeinternals.di.component.activity.ActivityComponent;
import net.crosp.android.dagger2scopeinternals.di.component.activity.module.ActivityModule;
import net.crosp.android.dagger2scopeinternals.di.component.application.ApplicationComponent;
import net.crosp.android.dagger2scopeinternals.di.contract.ProvidesComponent;
import net.crosp.android.dagger2scopeinternals.module.shareddependencies.contract.CarDataRepositoryContract;
import javax.inject.Inject;
import javax.inject.Named;
/**
* Created by Alexander Molochko on 12/12/2016.
@@ -29,17 +33,12 @@
// Views
protected ViewGroup mContentContainer;
// Variables
// @Inject
@Inject
protected LayoutInflater mLayoutInflater;
/* @Inject
@Named(NamedConstants.Fragment.SUPPORT_FRAGMENT_MANAGER)*/
@Inject
@Named(NamedConstants.Fragment.SUPPORT_FRAGMENT_MANAGER)
protected FragmentManager mFragmentManager;
protected ApplicationComponent mAppComponent;
// Dagger dependency graph
/*
protected ActivityComponent mActivityComponent;
*/
//================================================================================
// Lifecycle callbacks
@@ -62,8 +61,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
}
private void initDependencyComponents() {
mAppComponent = ((ProvidesComponent<ApplicationComponent>) getApplication()).getComponent();
mAppComponent.inject(this);
ApplicationComponent appComponent = ((ProvidesComponent<ApplicationComponent>) getApplication()).getComponent();
mActivityComponent = appComponent.plusActivityComponent(new ActivityModule(this));
}
/* @Override
@@ -0,0 +1,28 @@
package net.crosp.android.dagger2scopeinternals.di.component.activity;
import net.crosp.android.dagger2scopeinternals.base.ui.activity.BaseActivity;
import net.crosp.android.dagger2scopeinternals.di.component.activity.module.ActivityModule;
import net.crosp.android.dagger2scopeinternals.di.scope.PerActivity;
import net.crosp.android.dagger2scopeinternals.module.main.di.components.MainScreenComponent;
import net.crosp.android.dagger2scopeinternals.module.secondary.di.components.SecondaryScreenComponent;
import dagger.Subcomponent;
/**
* Created by Alexander Molochko on 1/22/17.
* Project HeartHealthMonitor
* Copyright (C) 2017 CROSP Solutions
*/
@PerActivity
@Subcomponent(modules = {ActivityModule.class})
public interface ActivityComponent {
public void inject(BaseActivity baseActivity);
// Subcomponents
MainScreenComponent plusMainScreenComponent();
SecondaryScreenComponent plusSecondaryScreenComponent();
}
@@ -0,0 +1,74 @@
package net.crosp.android.dagger2scopeinternals.di.component.activity.module;
import android.app.Activity;
import android.content.Context;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import net.crosp.android.dagger2scopeinternals.di.NamedConstants;
import net.crosp.android.dagger2scopeinternals.di.scope.PerActivity;
import javax.inject.Named;
import dagger.Module;
import dagger.Provides;
/**
* Created by Alexander Molochko on 1/22/17.
* Project HeartHealthMonitor
* Copyright (C) 2017 CROSP Solutions
*/
@Module
@PerActivity
public class ActivityModule {
private final AppCompatActivity mActivity;
public static final String CONTEXT_ACTIVITY = "context.activity";
public ActivityModule(AppCompatActivity activity) {
this.mActivity = activity;
}
@Provides
@PerActivity
@Named(CONTEXT_ACTIVITY)
Context provideActivityContext() {
return this.mActivity;
}
/**
* Provide the activity to dependents in the graph.
*/
@Provides
@PerActivity
Activity provideActivity() {
return this.mActivity;
}
/**
* Provide the layout inflater to dependents in the graph.
*/
@Provides
@PerActivity
LayoutInflater provideLayoutInflater() {
return LayoutInflater.from(mActivity);
}
/**
* Provide the layout inflater to dependents in the graph.
*/
@Provides
@Named(NamedConstants.Fragment.SUPPORT_FRAGMENT_MANAGER)
@PerActivity
FragmentManager provideSupportFragmentManager() {
return mActivity.getSupportFragmentManager();
}
@Provides
@Named(NamedConstants.Fragment.DEFAULT_FRAGMENT_MANAGER)
@PerActivity
android.app.FragmentManager provideFragmentManager() {
return mActivity.getFragmentManager();
}
}
@@ -1,10 +1,10 @@
package net.crosp.android.dagger2scopeinternals.di.component.application;
import net.crosp.android.dagger2scopeinternals.base.ui.activity.BaseActivity;
import net.crosp.android.dagger2scopeinternals.di.component.Dagger2ScopeInternalsApplication;
import net.crosp.android.dagger2scopeinternals.di.component.activity.ActivityComponent;
import net.crosp.android.dagger2scopeinternals.di.component.activity.module.ActivityModule;
import net.crosp.android.dagger2scopeinternals.di.component.application.module.ApplicationUnscopedModule;
import net.crosp.android.dagger2scopeinternals.di.scope.PerApplication;
import net.crosp.android.dagger2scopeinternals.module.main.ui.MainActivity;
import dagger.Component;
@@ -21,9 +21,7 @@
// Injection methods
void inject(Dagger2ScopeInternalsApplication mainApplication);
void inject(MainActivity mainActivity);
void inject(BaseActivity baseActivity);
// Subcomponents
ActivityComponent plusActivityComponent(ActivityModule activityModule);
}
@@ -0,0 +1,13 @@
package net.crosp.android.dagger2scopeinternals.module.main.di.components;
import net.crosp.android.dagger2scopeinternals.di.scope.PerFragment;
import net.crosp.android.dagger2scopeinternals.module.main.di.modules.MainFirstFragmentModule;
import net.crosp.android.dagger2scopeinternals.module.main.ui.MainFirstFragment;
import dagger.Subcomponent;
@PerFragment
@Subcomponent(modules = {MainFirstFragmentModule.class})
public interface MainFirstViewComponent {
void inject(MainFirstFragment fragment);
}
@@ -0,0 +1,18 @@
package net.crosp.android.dagger2scopeinternals.module.main.di.components;
import net.crosp.android.dagger2scopeinternals.di.scope.PerScreen;
import net.crosp.android.dagger2scopeinternals.module.main.di.modules.MainScreenModule;
import net.crosp.android.dagger2scopeinternals.module.main.ui.MainActivity;
import dagger.Subcomponent;
@PerScreen
@Subcomponent(modules = {MainScreenModule.class})
public interface MainScreenComponent {
void inject(MainActivity activity);
MainFirstViewComponent plusMainFirstViewComponent();
MainSecondViewComponent plusMainSecondViewComponent();
}
@@ -0,0 +1,13 @@
package net.crosp.android.dagger2scopeinternals.module.main.di.components;
import net.crosp.android.dagger2scopeinternals.di.scope.PerFragment;
import net.crosp.android.dagger2scopeinternals.module.main.di.modules.MainSecondFragmentModule;
import net.crosp.android.dagger2scopeinternals.module.main.ui.MainSecondFragment;
import dagger.Subcomponent;
@PerFragment
@Subcomponent(modules = {MainSecondFragmentModule.class})
public interface MainSecondViewComponent {
void inject(MainSecondFragment fragment);
}
@@ -0,0 +1,24 @@
package net.crosp.android.dagger2scopeinternals.module.main.di.modules;
import android.app.Activity;
import net.crosp.android.dagger2scopeinternals.di.scope.PerFragment;
import net.crosp.android.dagger2scopeinternals.module.main.ui.MainActivity;
import net.crosp.android.dagger2scopeinternals.module.main.ui.MainFirstFragment;
import dagger.Module;
import dagger.Provides;
/**
* Created by Alexander Molochko on 10/27/18.
* Project Dagger2ScopeInternals
* Copyright (C) 2018 CROSP Solutions
*/
@Module
public class MainFirstFragmentModule {
@Provides
@PerFragment
public MainFirstFragment.SecondFragmentRouter provideSecondFragmentRouter(Activity containerActivity) {
return (MainActivity) containerActivity;
}
}
@@ -0,0 +1,23 @@
package net.crosp.android.dagger2scopeinternals.module.main.di.modules;
import android.app.Activity;
import net.crosp.android.dagger2scopeinternals.di.scope.PerScreen;
import net.crosp.android.dagger2scopeinternals.module.main.ui.MainActivity;
import dagger.Module;
import dagger.Provides;
/**
* Created by Alexander Molochko on 10/27/18.
* Project Dagger2ScopeInternals
* Copyright (C) 2018 CROSP Solutions
*/
@Module
public class MainScreenModule {
@Provides
@PerScreen
public MainActivity provideScreenActivity(Activity containerActivity) {
return (MainActivity) containerActivity;
}
}
@@ -0,0 +1,24 @@
package net.crosp.android.dagger2scopeinternals.module.main.di.modules;
import android.app.Activity;
import net.crosp.android.dagger2scopeinternals.di.scope.PerFragment;
import net.crosp.android.dagger2scopeinternals.module.main.ui.MainActivity;
import net.crosp.android.dagger2scopeinternals.module.main.ui.MainSecondFragment;
import dagger.Module;
import dagger.Provides;
/**
* Created by Alexander Molochko on 10/27/18.
* Project Dagger2ScopeInternals
* Copyright (C) 2018 CROSP Solutions
*/
@Module
public class MainSecondFragmentModule {
@Provides
@PerFragment
public MainSecondFragment.FirstFragmentRouter provideFirstFragmentRouter(Activity containerActivity) {
return (MainActivity) containerActivity;
}
}
@@ -6,14 +6,17 @@
import net.crosp.android.dagger2scopeinternals.R;
import net.crosp.android.dagger2scopeinternals.base.ui.activity.BaseSingleFragmentActivity;
import net.crosp.android.dagger2scopeinternals.di.contract.ProvidesComponent;
import net.crosp.android.dagger2scopeinternals.module.main.di.components.MainScreenComponent;
import net.crosp.android.dagger2scopeinternals.module.secondary.ui.SecondaryActivity;
import net.crosp.android.dagger2scopeinternals.module.shareddependencies.contract.CarDataRepositoryContract;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
public class MainActivity extends BaseSingleFragmentActivity implements MainFirstFragment.SecondFragmentRouter {
public class MainActivity extends BaseSingleFragmentActivity implements ProvidesComponent<MainScreenComponent>, MainFirstFragment.SecondFragmentRouter, MainSecondFragment.FirstFragmentRouter {
@Inject
CarDataRepositoryContract mCarRepoOther;
// Views
@@ -22,6 +25,7 @@
// UI Variables
ActionBar mActionBar;
MainScreenComponent mMainScreenComponent;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -34,9 +38,8 @@ protected void onCreate(Bundle savedInstanceState) {
}
private void injectDependencies() {
mAppComponent.inject(this);
System.out.println(mCarRepoOther);
mAppComponent.inject(this);
mMainScreenComponent = mActivityComponent.plusMainScreenComponent();
mMainScreenComponent.inject(this);
}
private void initUI() {
@@ -51,6 +54,11 @@ protected void initToolbar() {
setSupportActionBar(mMainToolbar);
mActionBar = getSupportActionBar();
}
@Override
public MainScreenComponent getComponent() {
return mMainScreenComponent;
}
// Layout configuration
@Override
@@ -75,7 +83,19 @@ public int getContentContainerId() {
// Routing
@Override
public void onSwitchToSecondFragmentRequested() {
public void onSwitchToSecondFragment() {
replaceFragment(MainSecondFragment.class, false);
}
@Override
public void onSwitchBackToFirstFragment() {
replaceFragment(MainFirstFragment.class, false);
}
@Override
public void switchToSecondaryActivity() {
startNewActivity(SecondaryActivity.class);
}
}
Oops, something went wrong.

0 comments on commit c27d59e

Please sign in to comment.