Skip to content
This repository was archived by the owner on Sep 10, 2020. It is now read-only.
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
@@ -0,0 +1,11 @@
package com.jakewharton.telecine;

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,9 @@
package com.jakewharton.telecine;

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

@Module
public abstract class Api24OrGreaterServiceModule {
@ContributesAndroidInjector() abstract TelecineTileService bindTelecineTileService();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,32 @@
import android.app.Activity;
import android.app.Application;
import android.app.Service;

import com.bugsnag.android.BeforeNotify;
import com.bugsnag.android.Bugsnag;
import com.bugsnag.android.Error;

import javax.inject.Inject;

import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
import dagger.android.HasActivityInjector;
import dagger.android.HasServiceInjector;
import javax.inject.Inject;
import timber.log.Timber;

public final class TelecineApplication extends Application
implements HasActivityInjector, HasServiceInjector {
@Inject DispatchingAndroidInjector<Activity> dispatchingActivityInjector;
@Inject DispatchingAndroidInjector<Service> dispatchingServiceInjector;
private TelecineComponent telecineComponent;

public TelecineComponent telecineComponent() {
return telecineComponent;
}

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

if (BuildConfig.DEBUG) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.jakewharton.telecine;

import android.app.Application;

import javax.inject.Singleton;

import dagger.BindsInstance;
import dagger.Component;
import dagger.android.AndroidInjectionModule;
import javax.inject.Singleton;

@Singleton @Component(modules = { AndroidInjectionModule.class, TelecineModule.class })
interface TelecineComponent {
void inject(TelecineApplication app);

Api24OrGreaterServiceComponent api24OrGreaterServiceComponent();

@Component.Builder interface Builder {
@BindsInstance Builder application(Application application);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import android.app.Application;
import android.content.ContentResolver;
import android.content.SharedPreferences;

import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;

import java.util.Map;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import dagger.android.ContributesAndroidInjector;
import java.util.Map;
import javax.inject.Singleton;
import timber.log.Timber;

import static android.content.Context.MODE_PRIVATE;
Expand Down Expand Up @@ -109,5 +113,4 @@ static Integer provideVideoSizePercentage(@VideoSizePercentage IntPreference pre

@ContributesAndroidInjector abstract TelecineService contributeTelecineService();

@ContributesAndroidInjector abstract TelecineTileService contributeTelecineTileService();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import android.annotation.TargetApi;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;

import com.google.android.gms.analytics.HitBuilders;
import dagger.android.AndroidInjection;

import javax.inject.Inject;

import timber.log.Timber;

import static android.os.Build.VERSION_CODES.N;
Expand All @@ -15,7 +17,7 @@ public final class TelecineTileService extends TileService {
@Inject Analytics analytics;

@Override public void onCreate() {
AndroidInjection.inject(this);
((TelecineApplication) getApplication()).telecineComponent().api24OrGreaterServiceComponent().injector().inject(this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is unfortunate. mind if i try something to see if we can avoid the Service knowing about its injector?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opened #172 to keep the usefulness of the Android injection pieces.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. I got you the point. And your solution is much cleaner. I have also changed the implementation in my own project. Thank you for the help.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for looking into it! This was a fun problem.

super.onCreate();
}

Expand Down