aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/com/android/tv/MainActivity.java14
-rw-r--r--src/com/android/tv/TvSingletons.java4
-rw-r--r--src/com/android/tv/app/LiveTvApplication.java5
-rw-r--r--src/com/android/tv/app/LiveTvApplicationComponent.java24
-rw-r--r--src/com/android/tv/app/LiveTvModule.java23
-rw-r--r--src/com/android/tv/modules/TvApplicationModule.java24
-rw-r--r--src/com/android/tv/modules/TvSingletonsModule.java25
7 files changed, 115 insertions, 4 deletions
diff --git a/src/com/android/tv/MainActivity.java b/src/com/android/tv/MainActivity.java
index f2d6989b..a6c5868a 100644
--- a/src/com/android/tv/MainActivity.java
+++ b/src/com/android/tv/MainActivity.java
@@ -149,6 +149,8 @@ import com.android.tv.util.account.AccountHelper;
import com.android.tv.util.images.ImageCache;
import com.google.common.base.Optional;
+import dagger.android.AndroidInjection;
+import dagger.android.ContributesAndroidInjector;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayDeque;
@@ -159,6 +161,7 @@ import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
+import javax.inject.Inject;
import javax.inject.Provider;
/** The main activity for the Live TV app. */
@@ -259,7 +262,7 @@ public class MainActivity extends Activity
private final MySingletonsImpl mMySingletons = new MySingletonsImpl();
private AccessibilityManager mAccessibilityManager;
- private ChannelDataManager mChannelDataManager;
+ @Inject ChannelDataManager mChannelDataManager;
private ProgramDataManager mProgramDataManager;
private TvInputManagerHelper mTvInputManagerHelper;
private ChannelTuner mChannelTuner;
@@ -465,6 +468,7 @@ public class MainActivity extends Activity
@Override
protected void onCreate(Bundle savedInstanceState) {
+ AndroidInjection.inject(this);
mAccessibilityManager =
(AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE);
TvSingletons tvSingletons = TvSingletons.getSingletons(this);
@@ -490,7 +494,6 @@ public class MainActivity extends Activity
mSetupUtils = tvSingletons.getSetupUtils();
TvSingletons tvApplication = (TvSingletons) getApplication();
- mChannelDataManager = tvApplication.getChannelDataManager();
// In API 23, TvContract.isChannelUriForPassthroughInput is hidden.
boolean isPassthroughInput =
TvContract.isChannelUriForPassthroughInput(getIntent().getData());
@@ -2966,4 +2969,11 @@ public class MainActivity extends Activity
return TvSingletons.getSingletons(getApplicationContext()).getDvrManager();
}
}
+
+ /** Exports {@link MainActivity} for Dagger codegen to create the appropriate injector. */
+ @dagger.Module
+ public abstract static class Module {
+ @ContributesAndroidInjector
+ abstract MainActivity contributesMainActivityActivityInjector();
+ }
}
diff --git a/src/com/android/tv/TvSingletons.java b/src/com/android/tv/TvSingletons.java
index 89e45a81..70213d41 100644
--- a/src/com/android/tv/TvSingletons.java
+++ b/src/com/android/tv/TvSingletons.java
@@ -47,8 +47,7 @@ public interface TvSingletons extends BaseSingletons, HasBuiltInTunerManager {
/**
* Returns the @{@link TvSingletons} using the application context.
*
- * @deprecated use {@link com.android.tv.common.singletons.HasSingletons#get(Class, Context)}
- * instead
+ * @deprecated use injection instead.
*/
@Deprecated
static TvSingletons getSingletons(Context context) {
@@ -59,6 +58,7 @@ public interface TvSingletons extends BaseSingletons, HasBuiltInTunerManager {
void handleInputCountChanged();
+ @Deprecated
ChannelDataManager getChannelDataManager();
/**
diff --git a/src/com/android/tv/app/LiveTvApplication.java b/src/com/android/tv/app/LiveTvApplication.java
index 18db5da9..7ccbebdc 100644
--- a/src/com/android/tv/app/LiveTvApplication.java
+++ b/src/com/android/tv/app/LiveTvApplication.java
@@ -33,6 +33,7 @@ import com.android.tv.common.singletons.HasSingletons;
import com.android.tv.common.util.CommonUtils;
import com.android.tv.data.epg.EpgReader;
import com.android.tv.data.epg.StubEpgReader;
+import com.android.tv.modules.TvSingletonsModule;
import com.android.tv.perf.PerformanceMonitor;
import com.android.tv.perf.PerformanceMonitorManagerFactory;
import com.android.tv.tuner.setup.LiveTvTunerSetupActivity;
@@ -72,6 +73,10 @@ public class LiveTvApplication extends TvApplication implements HasSingletons<Tv
@Override
public void onCreate() {
super.onCreate();
+ DaggerLiveTvApplicationComponent.builder()
+ .tvSingletonsModule(new TvSingletonsModule(this))
+ .build()
+ .inject(this);
PERFORMANCE_MONITOR_MANAGER.getStartupMeasure().onAppCreate(this);
}
diff --git a/src/com/android/tv/app/LiveTvApplicationComponent.java b/src/com/android/tv/app/LiveTvApplicationComponent.java
new file mode 100644
index 00000000..65b32166
--- /dev/null
+++ b/src/com/android/tv/app/LiveTvApplicationComponent.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.tv.app;
+
+import dagger.Component;
+import dagger.android.AndroidInjectionModule;
+import dagger.android.AndroidInjector;
+
+/** Dagger component for {@link LiveTvApplication}. */
+@Component(modules = {AndroidInjectionModule.class, LiveTvModule.class})
+public interface LiveTvApplicationComponent extends AndroidInjector<LiveTvApplication> {}
diff --git a/src/com/android/tv/app/LiveTvModule.java b/src/com/android/tv/app/LiveTvModule.java
new file mode 100644
index 00000000..168680cd
--- /dev/null
+++ b/src/com/android/tv/app/LiveTvModule.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.tv.app;
+
+import com.android.tv.modules.TvApplicationModule;
+import dagger.Module;
+
+/** Dagger module for {@link LiveTvApplication}. */
+@Module(includes = {TvApplicationModule.class})
+class LiveTvModule {}
diff --git a/src/com/android/tv/modules/TvApplicationModule.java b/src/com/android/tv/modules/TvApplicationModule.java
new file mode 100644
index 00000000..d2831937
--- /dev/null
+++ b/src/com/android/tv/modules/TvApplicationModule.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.tv.modules;
+
+import com.android.tv.MainActivity;
+import com.android.tv.TvApplication;
+import dagger.Module;
+
+/** Dagger module for {@link TvApplication}. */
+@Module(includes = {TvSingletonsModule.class, MainActivity.Module.class})
+public class TvApplicationModule {}
diff --git a/src/com/android/tv/modules/TvSingletonsModule.java b/src/com/android/tv/modules/TvSingletonsModule.java
new file mode 100644
index 00000000..378d64ef
--- /dev/null
+++ b/src/com/android/tv/modules/TvSingletonsModule.java
@@ -0,0 +1,25 @@
+package com.android.tv.modules;
+
+import com.android.tv.TvSingletons;
+import com.android.tv.data.ChannelDataManager;
+import dagger.Module;
+import dagger.Provides;
+
+/**
+ * Provides bindings for items provided by {@link TvSingletons}.
+ *
+ * <p>Use this module to inject items directly instead of using {@code TvSingletons}.
+ */
+@Module
+public class TvSingletonsModule {
+ private final TvSingletons mTvSingletons;
+
+ public TvSingletonsModule(TvSingletons mTvSingletons) {
+ this.mTvSingletons = mTvSingletons;
+ }
+
+ @Provides
+ ChannelDataManager providesChannelDataManager() {
+ return mTvSingletons.getChannelDataManager();
+ }
+}