Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dagger support lib #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/build
/captures
.externalNativeBuild
/.idea
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 27
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "iammert.com.dagger_android_injection"
minSdkVersion 15
targetSdkVersion 25
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -24,12 +24,12 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:appcompat-v7:27.0.2'
testCompile 'junit:junit:4.12'
compile 'com.android.support.constraint:constraint-layout:1.0.2'

compile 'com.google.dagger:dagger:2.11'
annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.11'
compile 'com.google.dagger:dagger-android-support:2.11'
compile 'com.google.dagger:dagger:2.13'
annotationProcessor 'com.google.dagger:dagger-compiler:2.13'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.13'
compile 'com.google.dagger:dagger-android-support:2.13'
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,18 @@
package iammert.com.dagger_android_injection;

import android.app.Activity;
import android.app.Application;

import javax.inject.Inject;

import dagger.android.DispatchingAndroidInjector;
import dagger.android.HasActivityInjector;
import dagger.android.AndroidInjector;
import dagger.android.DaggerApplication;
import iammert.com.dagger_android_injection.di.DaggerAppComponent;


/**
* Created by mertsimsek on 25/05/2017.
*/

public class AndroidSampleApp extends Application implements HasActivityInjector {

@Inject
DispatchingAndroidInjector<Activity> activityDispatchingAndroidInjector;

@Override
public void onCreate() {
super.onCreate();
DaggerAppComponent
.builder()
.application(this)
.build()
.inject(this);

}
public class AndroidSampleApp extends DaggerApplication {

@Override
public DispatchingAndroidInjector<Activity> activityInjector() {
return activityDispatchingAndroidInjector;
protected AndroidInjector<? extends AndroidSampleApp> applicationInjector() {
return DaggerAppComponent.builder().create(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
package iammert.com.dagger_android_injection.di;

import android.app.Application;

import dagger.BindsInstance;
import dagger.Component;
import dagger.android.AndroidInjectionModule;
import dagger.android.AndroidInjector;
import dagger.android.support.AndroidSupportInjectionModule;
import iammert.com.dagger_android_injection.AndroidSampleApp;

/**
* Created by mertsimsek on 25/05/2017.
*/
@Component(modules = {
AndroidInjectionModule.class,
AndroidSupportInjectionModule.class,
AppModule.class,
ActivityBuilder.class})
public interface AppComponent {

public interface AppComponent extends AndroidInjector<AndroidSampleApp> {
@Component.Builder
interface Builder {
@BindsInstance Builder application(Application application);
AppComponent build();
abstract class Builder extends AndroidInjector.Builder<AndroidSampleApp> {
}

void inject(AndroidSampleApp app);
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
package iammert.com.dagger_android_injection.ui.detail;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import javax.inject.Inject;

import dagger.android.AndroidInjection;
import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
import dagger.android.support.HasSupportFragmentInjector;
import dagger.android.support.DaggerAppCompatActivity;
import iammert.com.dagger_android_injection.R;
import iammert.com.dagger_android_injection.ui.detail.fragment.DetailFragment;

/**
* Created by mertsimsek on 25/05/2017.
*/

public class DetailActivity extends AppCompatActivity implements HasSupportFragmentInjector, DetailView {

@Inject
DispatchingAndroidInjector<Fragment> fragmentDispatchingAndroidInjector;
public class DetailActivity extends DaggerAppCompatActivity implements DetailView {

@Inject
DetailPresenter detailPresenter;

@Override
protected void onCreate(Bundle savedInstanceState) {
AndroidInjection.inject(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
detailPresenter.loadDetail();
Expand All @@ -45,9 +35,4 @@ protected void onCreate(Bundle savedInstanceState) {
public void onDetailLoaded() {
Log.v("TEST", "Detail is loaded");
}

@Override
public AndroidInjector<Fragment> supportFragmentInjector() {
return fragmentDispatchingAndroidInjector;
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package iammert.com.dagger_android_injection.ui.detail.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import javax.inject.Inject;

import dagger.android.support.AndroidSupportInjection;
import dagger.android.support.DaggerFragment;


/**
* Created by mertsimsek on 02/06/2017.
*/

public class DetailFragment extends Fragment implements DetailFragmentView {
public class DetailFragment extends DaggerFragment implements DetailFragmentView {

@Inject
DetailFragmentPresenter detailFragmentPresenter;
Expand All @@ -29,18 +24,6 @@ public static DetailFragment newInstance() {
return fragment;
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return super.onCreateView(inflater, container, savedInstanceState);
}

@Override
public void onAttach(Context context) {
AndroidSupportInjection.inject(this);
super.onAttach(context);
}

@Override
public void onDetailFragmentLoaded() {
Log.v("TEST", "OnDetailFragmentLoaded.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package iammert.com.dagger_android_injection.ui.detail.fragment;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package iammert.com.dagger_android_injection.ui.main;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import javax.inject.Inject;

import dagger.android.AndroidInjection;
import dagger.android.support.DaggerAppCompatActivity;
import iammert.com.dagger_android_injection.R;
import iammert.com.dagger_android_injection.ui.detail.DetailActivity;

public class MainActivity extends AppCompatActivity implements MainView{
public class MainActivity extends DaggerAppCompatActivity implements MainView{

@Inject
MainPresenter mainPresenter;

@Override
protected void onCreate(Bundle savedInstanceState) {
AndroidInjection.inject(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mainPresenter.loadMain();
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha4'
classpath 'com.android.tools.build:gradle:3.0.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Jun 28 17:54:12 EEST 2017
#Fri Dec 15 10:16:23 EET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-rc-1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip