Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import javax.inject.Inject;

import dagger.android.AndroidInjection;
import timber.log.Timber;

/**
Expand All @@ -22,7 +21,7 @@ public class QuickTileService extends TileService {
@Override
public void onCreate() {
super.onCreate();
AndroidInjection.inject(this);
((TutorialApplication) getApplication()).api24OrGreaterServiceInjector().inject(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import android.app.Application;
import android.app.Service;

import com.github.tonytangandroid.daggertutorial.dagger.ApplicationComponent;
import com.github.tonytangandroid.daggertutorial.dagger.DaggerApplicationComponent;
import com.github.tonytangandroid.daggertutorial.dagger.api24.HasApi24OrGreaterServiceInjector;

import javax.inject.Inject;

Expand All @@ -14,18 +16,20 @@
import dagger.android.HasServiceInjector;
import timber.log.Timber;

public class TutorialApplication extends Application implements HasActivityInjector, HasServiceInjector {
public class TutorialApplication extends Application implements HasActivityInjector, HasServiceInjector, HasApi24OrGreaterServiceInjector {

@Inject
DispatchingAndroidInjector<Activity> activityDispatchingAndroidInjector;
@Inject
DispatchingAndroidInjector<Service> serviceDispatchingAndroidInjector;

private ApplicationComponent applicationComponent;

@Override
public void onCreate() {
super.onCreate();
DaggerApplicationComponent.builder().application(this).build().inject(this);
applicationComponent = DaggerApplicationComponent.builder().application(this).build();
applicationComponent.inject(this);
Timber.plant(new Timber.DebugTree());
}

Expand All @@ -38,4 +42,9 @@ public AndroidInjector<Activity> activityInjector() {
public AndroidInjector<Service> serviceInjector() {
return serviceDispatchingAndroidInjector;
}

@Override
public AndroidInjector<Service> api24OrGreaterServiceInjector() {
return applicationComponent.api24OrGreaterServiceComponent().injector();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Application;

import com.github.tonytangandroid.daggertutorial.TutorialApplication;
import com.github.tonytangandroid.daggertutorial.dagger.api24.Api24OrGreaterServiceComponent;
import com.github.tonytangandroid.daggertutorial.dagger.module.ApplicationModule;
import com.github.tonytangandroid.daggertutorial.dagger.module.DataBindModule;
import com.github.tonytangandroid.daggertutorial.dagger.module.DataProviderModule;
Expand All @@ -20,6 +21,8 @@
AndroidInjectionModule.class, ActivityInjector.class, ServiceInjector.class})
public interface ApplicationComponent {

Api24OrGreaterServiceComponent api24OrGreaterServiceComponent();

void inject(TutorialApplication app);

@Component.Builder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.tonytangandroid.daggertutorial.dagger;

import com.github.tonytangandroid.daggertutorial.DemoService;
import com.github.tonytangandroid.daggertutorial.QuickTileService;

import dagger.Module;
import dagger.android.ContributesAndroidInjector;
Expand All @@ -12,7 +11,4 @@ public abstract class ServiceInjector {
@ContributesAndroidInjector()
abstract DemoService bindDemoService();

@ContributesAndroidInjector()
abstract QuickTileService bindQuickTileService();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.github.tonytangandroid.daggertutorial.dagger.api24;

import android.app.Service;

import dagger.Subcomponent;
import dagger.android.DispatchingAndroidInjector;

@Subcomponent(modules = Api24OrGreaterServiceModule.class)
public interface Api24OrGreaterServiceComponent {
DispatchingAndroidInjector<Service> injector();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.tonytangandroid.daggertutorial.dagger.api24;

import com.github.tonytangandroid.daggertutorial.QuickTileService;

import dagger.Module;
import dagger.android.ContributesAndroidInjector;

@Module
public abstract class Api24OrGreaterServiceModule {

@ContributesAndroidInjector()
abstract QuickTileService bindQuickTileService();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.github.tonytangandroid.daggertutorial.dagger.api24;

import android.app.Service;

import dagger.android.AndroidInjector;

public interface HasApi24OrGreaterServiceInjector {

AndroidInjector<Service> api24OrGreaterServiceInjector();
}