From f9246a0674a78f8a4c2e639b935a01372224595b Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Thu, 7 May 2020 17:17:54 -0500 Subject: [PATCH] Convert injection package to Kotlin --- .../activities/BaseListSettingsActivity.java | 1 - .../tasks/activities/PlaceSettingsActivity.kt | 2 +- .../org/tasks/billing/PurchaseActivity.kt | 2 +- .../tasks/injection/ActivityComponent.java | 129 ---------------- .../org/tasks/injection/ActivityComponent.kt | 78 ++++++++++ .../org/tasks/injection/ActivityModule.java | 52 ------- .../org/tasks/injection/ActivityModule.kt | 37 +++++ .../org/tasks/injection/ActivityScope.java | 9 -- .../java/org/tasks/injection/ActivityScope.kt | 7 + .../tasks/injection/ApplicationComponent.java | 28 ---- .../tasks/injection/ApplicationComponent.kt | 20 +++ .../tasks/injection/ApplicationModule.java | 145 ------------------ .../org/tasks/injection/ApplicationModule.kt | 93 +++++++++++ .../org/tasks/injection/ApplicationScope.java | 9 -- .../org/tasks/injection/ApplicationScope.kt | 7 + .../tasks/injection/BroadcastComponent.java | 25 --- .../org/tasks/injection/BroadcastComponent.kt | 19 +++ .../org/tasks/injection/BroadcastModule.java | 6 - .../org/tasks/injection/BroadcastModule.kt | 6 + .../injection/ContentProviderComponent.java | 11 -- .../injection/ContentProviderComponent.kt | 10 ++ .../injection/ContentProviderModule.java | 6 - .../tasks/injection/ContentProviderModule.kt | 6 + .../main/java/org/tasks/injection/Dagger.java | 43 ------ .../main/java/org/tasks/injection/Dagger.kt | 37 +++++ .../injection/DialogFragmentComponent.java | 67 -------- .../injection/DialogFragmentComponent.kt | 35 +++++ .../tasks/injection/DialogFragmentModule.java | 21 --- .../tasks/injection/DialogFragmentModule.kt | 8 + .../java/org/tasks/injection/ForActivity.java | 17 -- .../java/org/tasks/injection/ForActivity.kt | 9 ++ .../org/tasks/injection/ForApplication.java | 17 -- .../org/tasks/injection/ForApplication.kt | 9 ++ .../tasks/injection/FragmentComponent.java | 109 ------------- .../org/tasks/injection/FragmentComponent.kt | 52 +++++++ .../org/tasks/injection/FragmentModule.java | 20 --- .../org/tasks/injection/FragmentModule.kt | 8 + .../tasks/injection/InjectingActivity.java | 8 - .../org/tasks/injection/InjectingActivity.kt | 7 + .../injection/InjectingAppCompatActivity.java | 29 ---- .../injection/InjectingAppCompatActivity.kt | 20 +++ .../injection/InjectingAppWidgetProvider.java | 20 --- .../injection/InjectingAppWidgetProvider.kt | 17 ++ .../tasks/injection/InjectingApplication.java | 27 ---- .../tasks/injection/InjectingApplication.kt | 17 ++ .../InjectingBottomSheetDialogFragment.java | 21 --- .../InjectingBottomSheetDialogFragment.kt | 17 ++ .../injection/InjectingBroadcastReceiver.java | 18 --- .../injection/InjectingBroadcastReceiver.kt | 16 ++ .../injection/InjectingContentProvider.java | 22 --- .../injection/InjectingContentProvider.kt | 17 ++ .../injection/InjectingDialogFragment.java | 21 --- .../injection/InjectingDialogFragment.kt | 18 +++ .../tasks/injection/InjectingFragment.java | 21 --- .../org/tasks/injection/InjectingFragment.kt | 17 ++ .../injection/InjectingJobIntentService.java | 31 ---- .../injection/InjectingJobIntentService.kt | 28 ++++ .../org/tasks/injection/InjectingService.java | 90 ----------- .../org/tasks/injection/InjectingService.kt | 73 +++++++++ .../org/tasks/injection/InjectingWorker.java | 37 ----- .../org/tasks/injection/InjectingWorker.kt | 28 ++++ .../org/tasks/injection/JobComponent.java | 34 ---- .../java/org/tasks/injection/JobComponent.kt | 17 ++ .../org/tasks/injection/ProductionModule.java | 26 ---- .../org/tasks/injection/ProductionModule.kt | 26 ++++ .../org/tasks/injection/ServiceComponent.java | 25 --- .../org/tasks/injection/ServiceComponent.kt | 19 +++ .../org/tasks/injection/ServiceModule.java | 6 - .../java/org/tasks/injection/ServiceModule.kt | 6 + .../ThemedInjectingAppCompatActivity.java | 36 ----- .../ThemedInjectingAppCompatActivity.kt | 27 ++++ .../java/org/tasks/injection/WorkModule.java | 6 - .../java/org/tasks/injection/WorkModule.kt | 6 + 73 files changed, 819 insertions(+), 1195 deletions(-) delete mode 100644 app/src/main/java/org/tasks/injection/ActivityComponent.java create mode 100644 app/src/main/java/org/tasks/injection/ActivityComponent.kt delete mode 100644 app/src/main/java/org/tasks/injection/ActivityModule.java create mode 100644 app/src/main/java/org/tasks/injection/ActivityModule.kt delete mode 100644 app/src/main/java/org/tasks/injection/ActivityScope.java create mode 100644 app/src/main/java/org/tasks/injection/ActivityScope.kt delete mode 100644 app/src/main/java/org/tasks/injection/ApplicationComponent.java create mode 100644 app/src/main/java/org/tasks/injection/ApplicationComponent.kt delete mode 100644 app/src/main/java/org/tasks/injection/ApplicationModule.java create mode 100644 app/src/main/java/org/tasks/injection/ApplicationModule.kt delete mode 100644 app/src/main/java/org/tasks/injection/ApplicationScope.java create mode 100644 app/src/main/java/org/tasks/injection/ApplicationScope.kt delete mode 100644 app/src/main/java/org/tasks/injection/BroadcastComponent.java create mode 100644 app/src/main/java/org/tasks/injection/BroadcastComponent.kt delete mode 100644 app/src/main/java/org/tasks/injection/BroadcastModule.java create mode 100644 app/src/main/java/org/tasks/injection/BroadcastModule.kt delete mode 100644 app/src/main/java/org/tasks/injection/ContentProviderComponent.java create mode 100644 app/src/main/java/org/tasks/injection/ContentProviderComponent.kt delete mode 100644 app/src/main/java/org/tasks/injection/ContentProviderModule.java create mode 100644 app/src/main/java/org/tasks/injection/ContentProviderModule.kt delete mode 100644 app/src/main/java/org/tasks/injection/Dagger.java create mode 100644 app/src/main/java/org/tasks/injection/Dagger.kt delete mode 100644 app/src/main/java/org/tasks/injection/DialogFragmentComponent.java create mode 100644 app/src/main/java/org/tasks/injection/DialogFragmentComponent.kt delete mode 100644 app/src/main/java/org/tasks/injection/DialogFragmentModule.java create mode 100644 app/src/main/java/org/tasks/injection/DialogFragmentModule.kt delete mode 100644 app/src/main/java/org/tasks/injection/ForActivity.java create mode 100644 app/src/main/java/org/tasks/injection/ForActivity.kt delete mode 100644 app/src/main/java/org/tasks/injection/ForApplication.java create mode 100644 app/src/main/java/org/tasks/injection/ForApplication.kt delete mode 100644 app/src/main/java/org/tasks/injection/FragmentComponent.java create mode 100644 app/src/main/java/org/tasks/injection/FragmentComponent.kt delete mode 100644 app/src/main/java/org/tasks/injection/FragmentModule.java create mode 100644 app/src/main/java/org/tasks/injection/FragmentModule.kt delete mode 100644 app/src/main/java/org/tasks/injection/InjectingActivity.java create mode 100644 app/src/main/java/org/tasks/injection/InjectingActivity.kt delete mode 100644 app/src/main/java/org/tasks/injection/InjectingAppCompatActivity.java create mode 100644 app/src/main/java/org/tasks/injection/InjectingAppCompatActivity.kt delete mode 100644 app/src/main/java/org/tasks/injection/InjectingAppWidgetProvider.java create mode 100644 app/src/main/java/org/tasks/injection/InjectingAppWidgetProvider.kt delete mode 100644 app/src/main/java/org/tasks/injection/InjectingApplication.java create mode 100644 app/src/main/java/org/tasks/injection/InjectingApplication.kt delete mode 100644 app/src/main/java/org/tasks/injection/InjectingBottomSheetDialogFragment.java create mode 100644 app/src/main/java/org/tasks/injection/InjectingBottomSheetDialogFragment.kt delete mode 100644 app/src/main/java/org/tasks/injection/InjectingBroadcastReceiver.java create mode 100644 app/src/main/java/org/tasks/injection/InjectingBroadcastReceiver.kt delete mode 100644 app/src/main/java/org/tasks/injection/InjectingContentProvider.java create mode 100644 app/src/main/java/org/tasks/injection/InjectingContentProvider.kt delete mode 100644 app/src/main/java/org/tasks/injection/InjectingDialogFragment.java create mode 100644 app/src/main/java/org/tasks/injection/InjectingDialogFragment.kt delete mode 100644 app/src/main/java/org/tasks/injection/InjectingFragment.java create mode 100644 app/src/main/java/org/tasks/injection/InjectingFragment.kt delete mode 100644 app/src/main/java/org/tasks/injection/InjectingJobIntentService.java create mode 100644 app/src/main/java/org/tasks/injection/InjectingJobIntentService.kt delete mode 100644 app/src/main/java/org/tasks/injection/InjectingService.java create mode 100644 app/src/main/java/org/tasks/injection/InjectingService.kt delete mode 100644 app/src/main/java/org/tasks/injection/InjectingWorker.java create mode 100644 app/src/main/java/org/tasks/injection/InjectingWorker.kt delete mode 100644 app/src/main/java/org/tasks/injection/JobComponent.java create mode 100644 app/src/main/java/org/tasks/injection/JobComponent.kt delete mode 100644 app/src/main/java/org/tasks/injection/ProductionModule.java create mode 100644 app/src/main/java/org/tasks/injection/ProductionModule.kt delete mode 100644 app/src/main/java/org/tasks/injection/ServiceComponent.java create mode 100644 app/src/main/java/org/tasks/injection/ServiceComponent.kt delete mode 100644 app/src/main/java/org/tasks/injection/ServiceModule.java create mode 100644 app/src/main/java/org/tasks/injection/ServiceModule.kt delete mode 100644 app/src/main/java/org/tasks/injection/ThemedInjectingAppCompatActivity.java create mode 100644 app/src/main/java/org/tasks/injection/ThemedInjectingAppCompatActivity.kt delete mode 100644 app/src/main/java/org/tasks/injection/WorkModule.java create mode 100644 app/src/main/java/org/tasks/injection/WorkModule.kt diff --git a/app/src/main/java/org/tasks/activities/BaseListSettingsActivity.java b/app/src/main/java/org/tasks/activities/BaseListSettingsActivity.java index 8f32806ac..3d3719c94 100644 --- a/app/src/main/java/org/tasks/activities/BaseListSettingsActivity.java +++ b/app/src/main/java/org/tasks/activities/BaseListSettingsActivity.java @@ -53,7 +53,6 @@ public abstract class BaseListSettingsActivity extends ThemedInjectingAppCompatA @BindView(R.id.toolbar) Toolbar toolbar; - @Inject ThemeColor themeColor; @Inject DialogBuilder dialogBuilder; @Inject ColorProvider colorProvider; diff --git a/app/src/main/java/org/tasks/activities/PlaceSettingsActivity.kt b/app/src/main/java/org/tasks/activities/PlaceSettingsActivity.kt index aa75de2c9..a5e356156 100644 --- a/app/src/main/java/org/tasks/activities/PlaceSettingsActivity.kt +++ b/app/src/main/java/org/tasks/activities/PlaceSettingsActivity.kt @@ -53,7 +53,7 @@ class PlaceSettingsActivity : BaseListSettingsActivity(), MapFragment.MapFragmen selectedIcon = place.getIcon()!! } - map.init(supportFragmentManager, this, theme.themeBase.isDarkTheme(this)) + map.init(supportFragmentManager, this, tasksTheme.themeBase.isDarkTheme(this)) updateTheme() } diff --git a/app/src/main/java/org/tasks/billing/PurchaseActivity.kt b/app/src/main/java/org/tasks/billing/PurchaseActivity.kt index b5b492f91..34f629491 100644 --- a/app/src/main/java/org/tasks/billing/PurchaseActivity.kt +++ b/app/src/main/java/org/tasks/billing/PurchaseActivity.kt @@ -51,7 +51,7 @@ class PurchaseActivity : ThemedInjectingAppCompatActivity(), OnPurchasesUpdated, setContentView(binding.root) ButterKnife.bind(this) - adapter = PurchaseAdapter(this, theme, locale, ::onPriceChanged) + adapter = PurchaseAdapter(this, tasksTheme, locale, ::onPriceChanged) if (savedInstanceState != null) { binding.buttons.check( diff --git a/app/src/main/java/org/tasks/injection/ActivityComponent.java b/app/src/main/java/org/tasks/injection/ActivityComponent.java deleted file mode 100644 index c847dfa06..000000000 --- a/app/src/main/java/org/tasks/injection/ActivityComponent.java +++ /dev/null @@ -1,129 +0,0 @@ -package org.tasks.injection; - -import com.todoroo.astrid.activity.BeastModePreferences; -import com.todoroo.astrid.activity.MainActivity; -import com.todoroo.astrid.activity.ShareLinkActivity; -import com.todoroo.astrid.activity.TaskEditActivity; -import com.todoroo.astrid.gcal.CalendarReminderActivity; -import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity; -import dagger.Subcomponent; -import org.tasks.activities.CameraActivity; -import org.tasks.activities.DateAndTimePickerActivity; -import org.tasks.activities.FilterSelectionActivity; -import org.tasks.activities.FilterSettingsActivity; -import org.tasks.activities.GoogleTaskListSettingsActivity; -import org.tasks.activities.PlaceSettingsActivity; -import org.tasks.activities.TagSettingsActivity; -import org.tasks.billing.PurchaseActivity; -import org.tasks.caldav.CaldavAccountSettingsActivity; -import org.tasks.caldav.CaldavCalendarSettingsActivity; -import org.tasks.dashclock.DashClockSettings; -import org.tasks.drive.DriveLoginActivity; -import org.tasks.etesync.EncryptionSettingsActivity; -import org.tasks.etesync.EteSyncAccountSettingsActivity; -import org.tasks.etesync.EteSyncCalendarSettingsActivity; -import org.tasks.locale.ui.activity.TaskerCreateTaskActivity; -import org.tasks.locale.ui.activity.TaskerSettingsActivity; -import org.tasks.location.LocationPickerActivity; -import org.tasks.activities.attribution.AttributionActivity; -import org.tasks.preferences.HelpAndFeedback; -import org.tasks.preferences.MainPreferences; -import org.tasks.preferences.ManageSpaceActivity; -import org.tasks.preferences.NotificationPreferences; -import org.tasks.preferences.SyncPreferences; -import org.tasks.reminders.NotificationActivity; -import org.tasks.reminders.SnoozeActivity; -import org.tasks.tags.TagPickerActivity; -import org.tasks.tags.TagPickerViewModel; -import org.tasks.ui.TaskListViewModel; -import org.tasks.voice.VoiceCommandActivity; -import org.tasks.widget.ShortcutConfigActivity; -import org.tasks.widget.WidgetClickActivity; -import org.tasks.widget.WidgetConfigActivity; - -@ActivityScope -@Subcomponent(modules = {ActivityModule.class, LocationModule.class}) -public interface ActivityComponent { - - void inject(GtasksLoginActivity gtasksLoginActivity); - - FragmentComponent plus(FragmentModule module); - - DialogFragmentComponent plus(DialogFragmentModule dialogFragmentModule); - - void inject(TaskerSettingsActivity taskerSettingsActivity); - - void inject(DashClockSettings dashClockSettings); - - void inject(CalendarReminderActivity calendarReminderActivity); - - void inject(FilterSettingsActivity filterSettingsActivity); - - void inject(TagSettingsActivity tagSettingsActivity); - - void inject(ShareLinkActivity shareLinkActivity); - - void inject(MainActivity mainActivity); - - void inject(BeastModePreferences beastModePreferences); - - void inject(NotificationActivity notificationActivity); - - void inject(SnoozeActivity snoozeActivity); - - void inject(FilterSelectionActivity filterSelectionActivity); - - void inject(DateAndTimePickerActivity dateAndTimePickerActivity); - - void inject(CameraActivity cameraActivity); - - void inject(VoiceCommandActivity voiceCommandActivity); - - void inject(WidgetConfigActivity widgetConfigActivity); - - void inject(ShortcutConfigActivity shortcutConfigActivity); - - void inject(GoogleTaskListSettingsActivity googleTaskListSettingsActivity); - - void inject(CaldavCalendarSettingsActivity caldavCalendarSettingsActivity); - - void inject(TaskerCreateTaskActivity taskerCreateTaskActivity); - - void inject(TaskListViewModel taskListViewModel); - - void inject(PurchaseActivity purchaseActivity); - - void inject(CaldavAccountSettingsActivity caldavAccountSettingsActivity); - - void inject(EteSyncAccountSettingsActivity eteSyncAccountSettingsActivity); - - void inject(DriveLoginActivity driveLoginActivity); - - void inject(TaskEditActivity taskEditActivity); - - void inject(WidgetClickActivity widgetActivity); - - void inject(LocationPickerActivity locationPickerActivity); - - void inject(AttributionActivity attributionActivity); - - void inject(TagPickerActivity tagPickerActivity); - - void inject(TagPickerViewModel viewModel); - - void inject(EteSyncCalendarSettingsActivity eteSyncCalendarSettingsActivity); - - void inject(EncryptionSettingsActivity encryptionSettingsActivity); - - void inject(MainPreferences mainPreferences); - - void inject(HelpAndFeedback helpAndFeedback); - - void inject(NotificationPreferences notificationPreferences); - - void inject(ManageSpaceActivity manageSpaceActivity); - - void inject(SyncPreferences syncPreferences); - - void inject(PlaceSettingsActivity placeSettingsActivity); -} diff --git a/app/src/main/java/org/tasks/injection/ActivityComponent.kt b/app/src/main/java/org/tasks/injection/ActivityComponent.kt new file mode 100644 index 000000000..b59e294bb --- /dev/null +++ b/app/src/main/java/org/tasks/injection/ActivityComponent.kt @@ -0,0 +1,78 @@ +package org.tasks.injection + +import com.todoroo.astrid.activity.BeastModePreferences +import com.todoroo.astrid.activity.MainActivity +import com.todoroo.astrid.activity.ShareLinkActivity +import com.todoroo.astrid.activity.TaskEditActivity +import com.todoroo.astrid.gcal.CalendarReminderActivity +import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity +import dagger.Subcomponent +import org.tasks.activities.* +import org.tasks.activities.attribution.AttributionActivity +import org.tasks.billing.PurchaseActivity +import org.tasks.caldav.CaldavAccountSettingsActivity +import org.tasks.caldav.CaldavCalendarSettingsActivity +import org.tasks.dashclock.DashClockSettings +import org.tasks.drive.DriveLoginActivity +import org.tasks.etesync.EncryptionSettingsActivity +import org.tasks.etesync.EteSyncAccountSettingsActivity +import org.tasks.etesync.EteSyncCalendarSettingsActivity +import org.tasks.locale.ui.activity.TaskerCreateTaskActivity +import org.tasks.locale.ui.activity.TaskerSettingsActivity +import org.tasks.location.LocationPickerActivity +import org.tasks.preferences.* +import org.tasks.reminders.NotificationActivity +import org.tasks.reminders.SnoozeActivity +import org.tasks.tags.TagPickerActivity +import org.tasks.tags.TagPickerViewModel +import org.tasks.ui.TaskListViewModel +import org.tasks.voice.VoiceCommandActivity +import org.tasks.widget.ShortcutConfigActivity +import org.tasks.widget.WidgetClickActivity +import org.tasks.widget.WidgetConfigActivity + +@ActivityScope +@Subcomponent(modules = [ActivityModule::class, LocationModule::class]) +interface ActivityComponent { + operator fun plus(module: FragmentModule): FragmentComponent + operator fun plus(dialogFragmentModule: DialogFragmentModule): DialogFragmentComponent + fun inject(activity: GtasksLoginActivity) + fun inject(activity: TaskerSettingsActivity) + fun inject(activity: DashClockSettings) + fun inject(activity: CalendarReminderActivity) + fun inject(activity: FilterSettingsActivity) + fun inject(activity: TagSettingsActivity) + fun inject(activity: ShareLinkActivity) + fun inject(activity: MainActivity) + fun inject(activity: BeastModePreferences) + fun inject(activity: NotificationActivity) + fun inject(activity: SnoozeActivity) + fun inject(activity: FilterSelectionActivity) + fun inject(activity: DateAndTimePickerActivity) + fun inject(activity: CameraActivity) + fun inject(activity: VoiceCommandActivity) + fun inject(activity: WidgetConfigActivity) + fun inject(activity: ShortcutConfigActivity) + fun inject(activity: GoogleTaskListSettingsActivity) + fun inject(activity: CaldavCalendarSettingsActivity) + fun inject(activity: TaskerCreateTaskActivity) + fun inject(activity: TaskListViewModel) + fun inject(activity: PurchaseActivity) + fun inject(activity: CaldavAccountSettingsActivity) + fun inject(activity: EteSyncAccountSettingsActivity) + fun inject(activity: DriveLoginActivity) + fun inject(activity: TaskEditActivity) + fun inject(activity: WidgetClickActivity) + fun inject(activity: LocationPickerActivity) + fun inject(activity: AttributionActivity) + fun inject(activity: TagPickerActivity) + fun inject(activity: TagPickerViewModel) + fun inject(activity: EteSyncCalendarSettingsActivity) + fun inject(activity: EncryptionSettingsActivity) + fun inject(activity: MainPreferences) + fun inject(activity: HelpAndFeedback) + fun inject(activity: NotificationPreferences) + fun inject(activity: ManageSpaceActivity) + fun inject(activity: SyncPreferences) + fun inject(activity: PlaceSettingsActivity) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/ActivityModule.java b/app/src/main/java/org/tasks/injection/ActivityModule.java deleted file mode 100644 index b2318c0b4..000000000 --- a/app/src/main/java/org/tasks/injection/ActivityModule.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.tasks.injection; - -import android.app.Activity; -import android.content.Context; -import dagger.Module; -import dagger.Provides; -import org.tasks.R; -import org.tasks.billing.Inventory; -import org.tasks.preferences.Preferences; -import org.tasks.themes.ColorProvider; -import org.tasks.themes.ThemeAccent; -import org.tasks.themes.ThemeBase; -import org.tasks.themes.ThemeColor; - -@Module -class ActivityModule { - - private final Activity activity; - - public ActivityModule(Activity activity) { - this.activity = activity; - } - - @Provides - public Activity getActivity() { - return activity; - } - - @Provides - @ForActivity - Context getActivityContext() { - return activity; - } - - @Provides - @ActivityScope - ThemeBase getThemeBase(Preferences preferences, Inventory inventory) { - return ThemeBase.getThemeBase(preferences, inventory, activity.getIntent()); - } - - @Provides - @ActivityScope - public ThemeColor getThemeColor(ColorProvider colorProvider, Preferences preferences) { - return colorProvider.getThemeColor(preferences.getDefaultThemeColor(), true); - } - - @Provides - @ActivityScope - ThemeAccent getThemeAccent(ColorProvider colorProvider, Preferences preferences) { - return colorProvider.getThemeAccent(preferences.getInt(R.string.p_theme_accent, 1)); - } -} diff --git a/app/src/main/java/org/tasks/injection/ActivityModule.kt b/app/src/main/java/org/tasks/injection/ActivityModule.kt new file mode 100644 index 000000000..926b3f247 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/ActivityModule.kt @@ -0,0 +1,37 @@ +package org.tasks.injection + +import android.app.Activity +import android.content.Context +import dagger.Module +import dagger.Provides +import org.tasks.R +import org.tasks.billing.Inventory +import org.tasks.preferences.Preferences +import org.tasks.themes.ColorProvider +import org.tasks.themes.ThemeAccent +import org.tasks.themes.ThemeBase +import org.tasks.themes.ThemeColor + +@Module +class ActivityModule(@get:Provides val activity: Activity) { + + @get:ForActivity + @get:Provides + val activityContext: Context + get() = activity + + @Provides + @ActivityScope + fun getThemeBase(preferences: Preferences, inventory: Inventory): ThemeBase + = ThemeBase.getThemeBase(preferences, inventory, activity.intent) + + @Provides + @ActivityScope + fun getThemeColor(colorProvider: ColorProvider, preferences: Preferences): ThemeColor + = colorProvider.getThemeColor(preferences.defaultThemeColor, true) + + @Provides + @ActivityScope + fun getThemeAccent(colorProvider: ColorProvider, preferences: Preferences): ThemeAccent + = colorProvider.getThemeAccent(preferences.getInt(R.string.p_theme_accent, 1)) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/ActivityScope.java b/app/src/main/java/org/tasks/injection/ActivityScope.java deleted file mode 100644 index 8669c6e93..000000000 --- a/app/src/main/java/org/tasks/injection/ActivityScope.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.tasks.injection; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import javax.inject.Scope; - -@Scope -@Retention(RetentionPolicy.RUNTIME) -@interface ActivityScope {} diff --git a/app/src/main/java/org/tasks/injection/ActivityScope.kt b/app/src/main/java/org/tasks/injection/ActivityScope.kt new file mode 100644 index 000000000..b2062240d --- /dev/null +++ b/app/src/main/java/org/tasks/injection/ActivityScope.kt @@ -0,0 +1,7 @@ +package org.tasks.injection + +import javax.inject.Scope + +@Scope +@Retention(AnnotationRetention.RUNTIME) +internal annotation class ActivityScope \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/ApplicationComponent.java b/app/src/main/java/org/tasks/injection/ApplicationComponent.java deleted file mode 100644 index 5cf0c895f..000000000 --- a/app/src/main/java/org/tasks/injection/ApplicationComponent.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.tasks.injection; - -import dagger.Component; -import org.tasks.Tasks; -import org.tasks.backup.TasksBackupAgent; -import org.tasks.dashclock.DashClockExtension; -import org.tasks.widget.ScrollableWidgetUpdateService; - -@ApplicationScope -@Component(modules = {ApplicationModule.class, ProductionModule.class}) -public interface ApplicationComponent { - - void inject(DashClockExtension dashClockExtension); - - void inject(Tasks tasks); - - void inject(ScrollableWidgetUpdateService scrollableWidgetUpdateService); - - ActivityComponent plus(ActivityModule module); - - BroadcastComponent plus(BroadcastModule module); - - ServiceComponent plus(ServiceModule module); - - JobComponent plus(WorkModule module); - - void inject(TasksBackupAgent tasksBackupAgent); -} diff --git a/app/src/main/java/org/tasks/injection/ApplicationComponent.kt b/app/src/main/java/org/tasks/injection/ApplicationComponent.kt new file mode 100644 index 000000000..1e3240f5c --- /dev/null +++ b/app/src/main/java/org/tasks/injection/ApplicationComponent.kt @@ -0,0 +1,20 @@ +package org.tasks.injection + +import dagger.Component +import org.tasks.Tasks +import org.tasks.backup.TasksBackupAgent +import org.tasks.dashclock.DashClockExtension +import org.tasks.widget.ScrollableWidgetUpdateService + +@ApplicationScope +@Component(modules = [ApplicationModule::class, ProductionModule::class]) +interface ApplicationComponent { + operator fun plus(module: ActivityModule): ActivityComponent + operator fun plus(module: BroadcastModule): BroadcastComponent + operator fun plus(module: ServiceModule): ServiceComponent + operator fun plus(module: WorkModule): JobComponent + fun inject(dashClockExtension: DashClockExtension) + fun inject(tasks: Tasks) + fun inject(scrollableWidgetUpdateService: ScrollableWidgetUpdateService) + fun inject(tasksBackupAgent: TasksBackupAgent) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/ApplicationModule.java b/app/src/main/java/org/tasks/injection/ApplicationModule.java deleted file mode 100644 index b08099488..000000000 --- a/app/src/main/java/org/tasks/injection/ApplicationModule.java +++ /dev/null @@ -1,145 +0,0 @@ -package org.tasks.injection; - -import android.content.Context; -import com.todoroo.astrid.dao.Database; -import com.todoroo.astrid.dao.TaskDao; -import dagger.Module; -import dagger.Provides; -import org.tasks.analytics.Firebase; -import org.tasks.billing.BillingClient; -import org.tasks.billing.BillingClientImpl; -import org.tasks.billing.Inventory; -import org.tasks.data.AlarmDao; -import org.tasks.data.CaldavDao; -import org.tasks.data.DeletionDao; -import org.tasks.data.FilterDao; -import org.tasks.data.GoogleTaskDao; -import org.tasks.data.GoogleTaskListDao; -import org.tasks.data.LocationDao; -import org.tasks.data.TagDao; -import org.tasks.data.TagDataDao; -import org.tasks.data.TaskAttachmentDao; -import org.tasks.data.TaskListMetadataDao; -import org.tasks.data.UserActivityDao; -import org.tasks.jobs.WorkManager; -import org.tasks.locale.Locale; -import org.tasks.location.Geocoder; -import org.tasks.location.MapboxGeocoder; -import org.tasks.notifications.NotificationDao; - -@Module -public class ApplicationModule { - - private final Context context; - - public ApplicationModule(Context context) { - this.context = context; - } - - @Provides - public Locale getLocale() { - return Locale.getInstance(context); - } - - @Provides - @ForApplication - public Context getApplicationContext() { - return context; - } - - @Provides - @ApplicationScope - NotificationDao getNotificationDao(Database database) { - return database.notificationDao(); - } - - @Provides - @ApplicationScope - TagDataDao getTagDataDao(Database database) { - return database.getTagDataDao(); - } - - @Provides - @ApplicationScope - UserActivityDao getUserActivityDao(Database database) { - return database.getUserActivityDao(); - } - - @Provides - @ApplicationScope - TaskAttachmentDao getTaskAttachmentDao(Database database) { - return database.getTaskAttachmentDao(); - } - - @Provides - @ApplicationScope - TaskListMetadataDao getTaskListMetadataDao(Database database) { - return database.getTaskListMetadataDao(); - } - - @Provides - @ApplicationScope - GoogleTaskDao getGoogleTaskDao(Database database) { - return database.getGoogleTaskDao(); - } - - @Provides - @ApplicationScope - AlarmDao getAlarmDao(Database database) { - return database.getAlarmDao(); - } - - @Provides - @ApplicationScope - LocationDao getGeofenceDao(Database database) { - return database.getLocationDao(); - } - - @Provides - @ApplicationScope - TagDao getTagDao(Database database) { - return database.getTagDao(); - } - - @Provides - @ApplicationScope - FilterDao getFilterDao(Database database) { - return database.getFilterDao(); - } - - @Provides - @ApplicationScope - GoogleTaskListDao getGoogleTaskListDao(Database database) { - return database.getGoogleTaskListDao(); - } - - @Provides - @ApplicationScope - CaldavDao getCaldavDao(Database database) { - return database.getCaldavDao(); - } - - @Provides - @ApplicationScope - TaskDao getTaskDao(Database database, WorkManager workManager) { - TaskDao taskDao = database.getTaskDao(); - taskDao.initialize(workManager); - return taskDao; - } - - @Provides - @ApplicationScope - DeletionDao getDeletionDao(Database database) { - return database.getDeletionDao(); - } - - @Provides - BillingClient getBillingClient(Inventory inventory, Firebase firebase) { - return new BillingClientImpl(context, inventory, firebase); - } - - @Provides - Geocoder getGeocoder(@ForApplication Context context) { - return new MapboxGeocoder(context); - } -} diff --git a/app/src/main/java/org/tasks/injection/ApplicationModule.kt b/app/src/main/java/org/tasks/injection/ApplicationModule.kt new file mode 100644 index 000000000..36b7db123 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/ApplicationModule.kt @@ -0,0 +1,93 @@ +package org.tasks.injection + +import android.content.Context +import com.todoroo.astrid.dao.Database +import com.todoroo.astrid.dao.TaskDao +import dagger.Module +import dagger.Provides +import org.tasks.analytics.Firebase +import org.tasks.billing.BillingClient +import org.tasks.billing.BillingClientImpl +import org.tasks.billing.Inventory +import org.tasks.data.* +import org.tasks.jobs.WorkManager +import org.tasks.locale.Locale +import org.tasks.location.Geocoder +import org.tasks.location.MapboxGeocoder +import org.tasks.notifications.NotificationDao + +@Module +class ApplicationModule(@get:Provides @get:ForApplication val context: Context) { + + @get:Provides + val locale: Locale + get() = Locale.getInstance(context) + + @Provides + @ApplicationScope + fun getNotificationDao(db: Database): NotificationDao = db.notificationDao() + + @Provides + @ApplicationScope + fun getTagDataDao(db: Database): TagDataDao = db.tagDataDao + + @Provides + @ApplicationScope + fun getUserActivityDao(db: Database): UserActivityDao = db.userActivityDao + + @Provides + @ApplicationScope + fun getTaskAttachmentDao(db: Database): TaskAttachmentDao = db.taskAttachmentDao + + @Provides + @ApplicationScope + fun getTaskListMetadataDao(db: Database): TaskListMetadataDao = db.taskListMetadataDao + + @Provides + @ApplicationScope + fun getGoogleTaskDao(db: Database): GoogleTaskDao = db.googleTaskDao + + @Provides + @ApplicationScope + fun getAlarmDao(db: Database): AlarmDao = db.alarmDao + + @Provides + @ApplicationScope + fun getGeofenceDao(db: Database): LocationDao = db.locationDao + + @Provides + @ApplicationScope + fun getTagDao(db: Database): TagDao = db.tagDao + + @Provides + @ApplicationScope + fun getFilterDao(db: Database): FilterDao = db.filterDao + + @Provides + @ApplicationScope + fun getGoogleTaskListDao(db: Database): GoogleTaskListDao = db.googleTaskListDao + + @Provides + @ApplicationScope + fun getCaldavDao(db: Database): CaldavDao = db.caldavDao + + @Provides + @ApplicationScope + fun getTaskDao(db: Database, workManager: WorkManager): TaskDao { + val taskDao = db.taskDao + taskDao.initialize(workManager) + return taskDao + } + + @Provides + @ApplicationScope + fun getDeletionDao(db: Database): DeletionDao = db.deletionDao + + @Provides + fun getBillingClient(inventory: Inventory, firebase: Firebase): BillingClient + = BillingClientImpl(context, inventory, firebase) + + @get:Provides + val geocoder: Geocoder + get() = MapboxGeocoder(context) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/ApplicationScope.java b/app/src/main/java/org/tasks/injection/ApplicationScope.java deleted file mode 100644 index 6953e6890..000000000 --- a/app/src/main/java/org/tasks/injection/ApplicationScope.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.tasks.injection; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import javax.inject.Scope; - -@Scope -@Retention(RetentionPolicy.RUNTIME) -public @interface ApplicationScope {} diff --git a/app/src/main/java/org/tasks/injection/ApplicationScope.kt b/app/src/main/java/org/tasks/injection/ApplicationScope.kt new file mode 100644 index 000000000..a1e1fece5 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/ApplicationScope.kt @@ -0,0 +1,7 @@ +package org.tasks.injection + +import javax.inject.Scope + +@Scope +@Retention(AnnotationRetention.RUNTIME) +annotation class ApplicationScope \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/BroadcastComponent.java b/app/src/main/java/org/tasks/injection/BroadcastComponent.java deleted file mode 100644 index 36fd97e18..000000000 --- a/app/src/main/java/org/tasks/injection/BroadcastComponent.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.tasks.injection; - -import com.todoroo.astrid.gcal.CalendarAlarmReceiver; -import dagger.Subcomponent; -import org.tasks.notifications.NotificationClearedReceiver; -import org.tasks.receivers.BootCompletedReceiver; -import org.tasks.receivers.CompleteTaskReceiver; -import org.tasks.receivers.MyPackageReplacedReceiver; -import org.tasks.widget.TasksWidget; - -@Subcomponent(modules = BroadcastModule.class) -public interface BroadcastComponent { - - void inject(CalendarAlarmReceiver calendarAlarmReceiver); - - void inject(MyPackageReplacedReceiver myPackageReplacedReceiver); - - void inject(CompleteTaskReceiver completeTaskReceiver); - - void inject(BootCompletedReceiver bootCompletedReceiver); - - void inject(TasksWidget tasksWidget); - - void inject(NotificationClearedReceiver notificationClearedReceiver); -} diff --git a/app/src/main/java/org/tasks/injection/BroadcastComponent.kt b/app/src/main/java/org/tasks/injection/BroadcastComponent.kt new file mode 100644 index 000000000..05abc7cb3 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/BroadcastComponent.kt @@ -0,0 +1,19 @@ +package org.tasks.injection + +import com.todoroo.astrid.gcal.CalendarAlarmReceiver +import dagger.Subcomponent +import org.tasks.notifications.NotificationClearedReceiver +import org.tasks.receivers.BootCompletedReceiver +import org.tasks.receivers.CompleteTaskReceiver +import org.tasks.receivers.MyPackageReplacedReceiver +import org.tasks.widget.TasksWidget + +@Subcomponent(modules = [BroadcastModule::class]) +interface BroadcastComponent { + fun inject(broadcastReceiver: CalendarAlarmReceiver) + fun inject(broadcastReceiver: MyPackageReplacedReceiver) + fun inject(broadcastReceiver: CompleteTaskReceiver) + fun inject(broadcastReceiver: BootCompletedReceiver) + fun inject(broadcastReceiver: TasksWidget) + fun inject(broadcastReceiver: NotificationClearedReceiver) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/BroadcastModule.java b/app/src/main/java/org/tasks/injection/BroadcastModule.java deleted file mode 100644 index 88dad017a..000000000 --- a/app/src/main/java/org/tasks/injection/BroadcastModule.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.tasks.injection; - -import dagger.Module; - -@Module -class BroadcastModule {} diff --git a/app/src/main/java/org/tasks/injection/BroadcastModule.kt b/app/src/main/java/org/tasks/injection/BroadcastModule.kt new file mode 100644 index 000000000..b95cd069d --- /dev/null +++ b/app/src/main/java/org/tasks/injection/BroadcastModule.kt @@ -0,0 +1,6 @@ +package org.tasks.injection + +import dagger.Module + +@Module +class BroadcastModule \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/ContentProviderComponent.java b/app/src/main/java/org/tasks/injection/ContentProviderComponent.java deleted file mode 100644 index d71bf7e92..000000000 --- a/app/src/main/java/org/tasks/injection/ContentProviderComponent.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.tasks.injection; - -import com.todoroo.astrid.provider.Astrid2TaskProvider; -import dagger.Component; - -@ApplicationScope -@Component(modules = ContentProviderModule.class) -public interface ContentProviderComponent { - - void inject(Astrid2TaskProvider astrid2TaskProvider); -} diff --git a/app/src/main/java/org/tasks/injection/ContentProviderComponent.kt b/app/src/main/java/org/tasks/injection/ContentProviderComponent.kt new file mode 100644 index 000000000..6a8d3eaab --- /dev/null +++ b/app/src/main/java/org/tasks/injection/ContentProviderComponent.kt @@ -0,0 +1,10 @@ +package org.tasks.injection + +import com.todoroo.astrid.provider.Astrid2TaskProvider +import dagger.Component + +@ApplicationScope +@Component(modules = [ContentProviderModule::class]) +interface ContentProviderComponent { + fun inject(contentProvider: Astrid2TaskProvider) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/ContentProviderModule.java b/app/src/main/java/org/tasks/injection/ContentProviderModule.java deleted file mode 100644 index 1c30b9e42..000000000 --- a/app/src/main/java/org/tasks/injection/ContentProviderModule.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.tasks.injection; - -import dagger.Module; - -@Module(includes = ProductionModule.class) -class ContentProviderModule {} diff --git a/app/src/main/java/org/tasks/injection/ContentProviderModule.kt b/app/src/main/java/org/tasks/injection/ContentProviderModule.kt new file mode 100644 index 000000000..be12dfb10 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/ContentProviderModule.kt @@ -0,0 +1,6 @@ +package org.tasks.injection + +import dagger.Module + +@Module(includes = [ProductionModule::class]) +internal class ContentProviderModule \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/Dagger.java b/app/src/main/java/org/tasks/injection/Dagger.java deleted file mode 100644 index 53390e6f9..000000000 --- a/app/src/main/java/org/tasks/injection/Dagger.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.tasks.injection; - -import android.content.Context; -import org.tasks.locale.Locale; -import timber.log.Timber; - -class Dagger { - - private static final Object lock = new Object(); - - private static Dagger instance; - private final ApplicationComponent applicationComponent; - - private Dagger(Context context) { - Context localeContext = context.getApplicationContext(); - try { - localeContext = Locale.getInstance(localeContext).createConfigurationContext(localeContext); - } catch (Exception e) { - Timber.e(e); - } - - applicationComponent = - DaggerApplicationComponent.builder() - .applicationModule(new ApplicationModule(localeContext)) - .productionModule(new ProductionModule()) - .build(); - } - - public static Dagger get(Context context) { - if (instance == null) { - synchronized (lock) { - if (instance == null) { - instance = new Dagger(context); - } - } - } - return instance; - } - - ApplicationComponent getApplicationComponent() { - return applicationComponent; - } -} diff --git a/app/src/main/java/org/tasks/injection/Dagger.kt b/app/src/main/java/org/tasks/injection/Dagger.kt new file mode 100644 index 000000000..5a794afd1 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/Dagger.kt @@ -0,0 +1,37 @@ +package org.tasks.injection + +import android.content.Context +import org.tasks.locale.Locale +import timber.log.Timber + +internal class Dagger private constructor(context: Context) { + val applicationComponent: ApplicationComponent + + companion object { + private val lock = Any() + private var instance: Dagger? = null + operator fun get(context: Context): Dagger { + if (instance == null) { + synchronized(lock) { + if (instance == null) { + instance = Dagger(context) + } + } + } + return instance!! + } + } + + init { + var localeContext = context.applicationContext + try { + localeContext = Locale.getInstance(localeContext).createConfigurationContext(localeContext) + } catch (e: Exception) { + Timber.e(e) + } + applicationComponent = DaggerApplicationComponent.builder() + .applicationModule(ApplicationModule(localeContext)) + .productionModule(ProductionModule()) + .build() + } +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/DialogFragmentComponent.java b/app/src/main/java/org/tasks/injection/DialogFragmentComponent.java deleted file mode 100644 index d336fa6af..000000000 --- a/app/src/main/java/org/tasks/injection/DialogFragmentComponent.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.tasks.injection; - -import dagger.Subcomponent; -import org.tasks.activities.RemoteListPicker; -import org.tasks.calendars.CalendarPicker; -import org.tasks.dialogs.AddAttachmentDialog; -import org.tasks.dialogs.ColorPalettePicker; -import org.tasks.dialogs.ColorWheelPicker; -import org.tasks.dialogs.DateTimePicker; -import org.tasks.dialogs.ExportTasksDialog; -import org.tasks.dialogs.GeofenceDialog; -import org.tasks.dialogs.IconPickerDialog; -import org.tasks.dialogs.ImportTasksDialog; -import org.tasks.dialogs.NewFilterDialog; -import org.tasks.dialogs.RecordAudioDialog; -import org.tasks.dialogs.SortDialog; -import org.tasks.dialogs.ThemePickerDialog; -import org.tasks.dialogs.WhatsNewDialog; -import org.tasks.locale.LocalePickerDialog; -import org.tasks.reminders.NotificationDialog; -import org.tasks.reminders.SnoozeDialog; -import org.tasks.repeats.BasicRecurrenceDialog; -import org.tasks.repeats.CustomRecurrenceDialog; - -@Subcomponent(modules = DialogFragmentModule.class) -public interface DialogFragmentComponent { - - void inject(RemoteListPicker remoteListPicker); - - void inject(NotificationDialog notificationDialog); - - void inject(CalendarPicker calendarPicker); - - void inject(AddAttachmentDialog addAttachmentDialog); - - void inject(SnoozeDialog snoozeDialog); - - void inject(SortDialog sortDialog); - - void inject(RecordAudioDialog recordAudioDialog); - - void inject(CustomRecurrenceDialog customRecurrenceDialog); - - void inject(BasicRecurrenceDialog basicRecurrenceDialog); - - void inject(GeofenceDialog geofenceDialog); - - void inject(IconPickerDialog iconPickerDialog); - - void inject(ExportTasksDialog exportTasksDialog); - - void inject(ImportTasksDialog importTasksDialog); - - void inject(LocalePickerDialog localePickerDialog); - - void inject(ThemePickerDialog themePickerDialog); - - void inject(ColorWheelPicker colorWheelPicker); - - void inject(ColorPalettePicker colorPalettePicker); - - void inject(DateTimePicker dateTimePicker); - - void inject(NewFilterDialog newFilterDialog); - - void inject(WhatsNewDialog whatsNewDialog); -} diff --git a/app/src/main/java/org/tasks/injection/DialogFragmentComponent.kt b/app/src/main/java/org/tasks/injection/DialogFragmentComponent.kt new file mode 100644 index 000000000..6ee6edba9 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/DialogFragmentComponent.kt @@ -0,0 +1,35 @@ +package org.tasks.injection + +import dagger.Subcomponent +import org.tasks.activities.RemoteListPicker +import org.tasks.calendars.CalendarPicker +import org.tasks.dialogs.* +import org.tasks.locale.LocalePickerDialog +import org.tasks.reminders.NotificationDialog +import org.tasks.reminders.SnoozeDialog +import org.tasks.repeats.BasicRecurrenceDialog +import org.tasks.repeats.CustomRecurrenceDialog + +@Subcomponent(modules = [DialogFragmentModule::class]) +interface DialogFragmentComponent { + fun inject(dialogFragment: RemoteListPicker) + fun inject(dialogFragment: NotificationDialog) + fun inject(dialogFragment: CalendarPicker) + fun inject(dialogFragment: AddAttachmentDialog) + fun inject(dialogFragment: SnoozeDialog) + fun inject(dialogFragment: SortDialog) + fun inject(dialogFragment: RecordAudioDialog) + fun inject(dialogFragment: CustomRecurrenceDialog) + fun inject(dialogFragment: BasicRecurrenceDialog) + fun inject(dialogFragment: GeofenceDialog) + fun inject(dialogFragment: IconPickerDialog) + fun inject(dialogFragment: ExportTasksDialog) + fun inject(dialogFragment: ImportTasksDialog) + fun inject(dialogFragment: LocalePickerDialog) + fun inject(dialogFragment: ThemePickerDialog) + fun inject(dialogFragment: ColorWheelPicker) + fun inject(dialogFragment: ColorPalettePicker) + fun inject(dialogFragment: DateTimePicker) + fun inject(dialogFragment: NewFilterDialog) + fun inject(dialogFragment: WhatsNewDialog) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/DialogFragmentModule.java b/app/src/main/java/org/tasks/injection/DialogFragmentModule.java deleted file mode 100644 index 32765b946..000000000 --- a/app/src/main/java/org/tasks/injection/DialogFragmentModule.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.tasks.injection; - -import androidx.fragment.app.DialogFragment; -import androidx.fragment.app.Fragment; -import dagger.Module; -import dagger.Provides; - -@Module -class DialogFragmentModule { - - private final DialogFragment dialogFragment; - - DialogFragmentModule(DialogFragment dialogFragment) { - this.dialogFragment = dialogFragment; - } - - @Provides - public Fragment getFragment() { - return dialogFragment; - } -} diff --git a/app/src/main/java/org/tasks/injection/DialogFragmentModule.kt b/app/src/main/java/org/tasks/injection/DialogFragmentModule.kt new file mode 100644 index 000000000..27a8816c5 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/DialogFragmentModule.kt @@ -0,0 +1,8 @@ +package org.tasks.injection + +import androidx.fragment.app.Fragment +import dagger.Module +import dagger.Provides + +@Module +class DialogFragmentModule internal constructor(@get:Provides val fragment: Fragment) \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/ForActivity.java b/app/src/main/java/org/tasks/injection/ForActivity.java deleted file mode 100644 index d2a7764a1..000000000 --- a/app/src/main/java/org/tasks/injection/ForActivity.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.tasks.injection; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.PARAMETER; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; -import javax.inject.Qualifier; - -@Qualifier -@Target({FIELD, PARAMETER, METHOD}) -@Documented -@Retention(RUNTIME) -public @interface ForActivity {} diff --git a/app/src/main/java/org/tasks/injection/ForActivity.kt b/app/src/main/java/org/tasks/injection/ForActivity.kt new file mode 100644 index 000000000..6ce9b3f32 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/ForActivity.kt @@ -0,0 +1,9 @@ +package org.tasks.injection + +import javax.inject.Qualifier + +@Qualifier +@Target(AnnotationTarget.FIELD, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +@MustBeDocumented +@Retention(AnnotationRetention.RUNTIME) +annotation class ForActivity \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/ForApplication.java b/app/src/main/java/org/tasks/injection/ForApplication.java deleted file mode 100644 index 819ac8701..000000000 --- a/app/src/main/java/org/tasks/injection/ForApplication.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.tasks.injection; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.PARAMETER; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; -import javax.inject.Qualifier; - -@Qualifier -@Target({FIELD, PARAMETER, METHOD}) -@Documented -@Retention(RUNTIME) -public @interface ForApplication {} diff --git a/app/src/main/java/org/tasks/injection/ForApplication.kt b/app/src/main/java/org/tasks/injection/ForApplication.kt new file mode 100644 index 000000000..6b18ba870 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/ForApplication.kt @@ -0,0 +1,9 @@ +package org.tasks.injection + +import javax.inject.Qualifier + +@Qualifier +@Target(AnnotationTarget.FIELD, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +@MustBeDocumented +@Retention(AnnotationRetention.RUNTIME) +annotation class ForApplication \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/FragmentComponent.java b/app/src/main/java/org/tasks/injection/FragmentComponent.java deleted file mode 100644 index 964fac55e..000000000 --- a/app/src/main/java/org/tasks/injection/FragmentComponent.java +++ /dev/null @@ -1,109 +0,0 @@ -package org.tasks.injection; - -import com.todoroo.astrid.activity.TaskEditFragment; -import com.todoroo.astrid.activity.TaskListFragment; -import com.todoroo.astrid.files.FilesControlSet; -import com.todoroo.astrid.repeats.RepeatControlSet; -import com.todoroo.astrid.tags.TagsControlSet; -import com.todoroo.astrid.timers.TimerControlSet; -import com.todoroo.astrid.ui.HideUntilControlSet; -import com.todoroo.astrid.ui.ReminderControlSet; -import dagger.Subcomponent; -import org.tasks.fragments.CommentBarFragment; -import org.tasks.preferences.fragments.Advanced; -import org.tasks.preferences.fragments.Backups; -import org.tasks.preferences.fragments.DashClock; -import org.tasks.preferences.fragments.DateAndTime; -import org.tasks.preferences.fragments.Debug; -import org.tasks.preferences.fragments.HelpAndFeedback; -import org.tasks.preferences.fragments.LookAndFeel; -import org.tasks.preferences.fragments.MainSettingsFragment; -import org.tasks.preferences.fragments.NavigationDrawer; -import org.tasks.preferences.fragments.Notifications; -import org.tasks.preferences.fragments.ScrollableWidget; -import org.tasks.preferences.fragments.Synchronization; -import org.tasks.preferences.fragments.TaskDefaults; -import org.tasks.preferences.fragments.TaskerListNotification; -import org.tasks.preferences.fragments.Widgets; -import org.tasks.ui.CalendarControlSet; -import org.tasks.ui.DeadlineControlSet; -import org.tasks.ui.DescriptionControlSet; -import org.tasks.ui.EmptyTaskEditFragment; -import org.tasks.ui.LocationControlSet; -import org.tasks.ui.NavigationDrawerFragment; -import org.tasks.ui.PriorityControlSet; -import org.tasks.ui.RemoteListFragment; -import org.tasks.ui.SubtaskControlSet; -import org.tasks.ui.TaskListViewModel; - -@Subcomponent(modules = FragmentModule.class) -public interface FragmentComponent { - - void inject(TimerControlSet timerControlSet); - - void inject(TaskEditFragment taskEditFragment); - - void inject(NavigationDrawerFragment navigationDrawerFragment); - - void inject(PriorityControlSet priorityControlSet); - - void inject(RepeatControlSet repeatControlSet); - - void inject(CommentBarFragment commentBarFragment); - - void inject(FilesControlSet filesControlSet); - - void inject(TagsControlSet tagsControlSet); - - void inject(HideUntilControlSet hideUntilControlSet); - - void inject(ReminderControlSet reminderControlSet); - - void inject(DeadlineControlSet deadlineControlSet); - - void inject(DescriptionControlSet descriptionControlSet); - - void inject(CalendarControlSet calendarControlSet); - - void inject(TaskListFragment taskListFragment); - - void inject(RemoteListFragment remoteListFragment); - - void inject(LocationControlSet locationControlSet); - - void inject(SubtaskControlSet subtaskControlSet); - - void inject(TaskListViewModel taskListViewModel); - - void inject(HelpAndFeedback helpAndFeedback); - - void inject(LookAndFeel lookAndFeel); - - void inject(Synchronization synchronization); - - void inject(Debug debug); - - void inject(MainSettingsFragment mainSettingsFragment); - - void inject(Backups backups); - - void inject(Advanced advanced); - - void inject(Notifications notifications); - - void inject(TaskDefaults taskDefaults); - - void inject(ScrollableWidget scrollableWidget); - - void inject(DashClock dashClock); - - void inject(TaskerListNotification taskerListNotification); - - void inject(EmptyTaskEditFragment emptyTaskEditFragment); - - void inject(NavigationDrawer navigationDrawer); - - void inject(Widgets widgets); - - void inject(DateAndTime dateAndTime); -} diff --git a/app/src/main/java/org/tasks/injection/FragmentComponent.kt b/app/src/main/java/org/tasks/injection/FragmentComponent.kt new file mode 100644 index 000000000..35e59f68a --- /dev/null +++ b/app/src/main/java/org/tasks/injection/FragmentComponent.kt @@ -0,0 +1,52 @@ +package org.tasks.injection + +import com.todoroo.astrid.activity.TaskEditFragment +import com.todoroo.astrid.activity.TaskListFragment +import com.todoroo.astrid.files.FilesControlSet +import com.todoroo.astrid.repeats.RepeatControlSet +import com.todoroo.astrid.tags.TagsControlSet +import com.todoroo.astrid.timers.TimerControlSet +import com.todoroo.astrid.ui.HideUntilControlSet +import com.todoroo.astrid.ui.ReminderControlSet +import dagger.Subcomponent +import org.tasks.fragments.CommentBarFragment +import org.tasks.preferences.fragments.* +import org.tasks.ui.* + +@Subcomponent(modules = [FragmentModule::class]) +interface FragmentComponent { + fun inject(fragment: TimerControlSet) + fun inject(fragment: TaskEditFragment) + fun inject(fragment: NavigationDrawerFragment) + fun inject(fragment: PriorityControlSet) + fun inject(fragment: RepeatControlSet) + fun inject(fragment: CommentBarFragment) + fun inject(fragment: FilesControlSet) + fun inject(fragment: TagsControlSet) + fun inject(fragment: HideUntilControlSet) + fun inject(fragment: ReminderControlSet) + fun inject(fragment: DeadlineControlSet) + fun inject(fragment: DescriptionControlSet) + fun inject(fragment: CalendarControlSet) + fun inject(fragment: TaskListFragment) + fun inject(fragment: RemoteListFragment) + fun inject(fragment: LocationControlSet) + fun inject(fragment: SubtaskControlSet) + fun inject(fragment: TaskListViewModel) + fun inject(fragment: HelpAndFeedback) + fun inject(fragment: LookAndFeel) + fun inject(fragment: Synchronization) + fun inject(fragment: Debug) + fun inject(fragment: MainSettingsFragment) + fun inject(fragment: Backups) + fun inject(fragment: Advanced) + fun inject(fragment: Notifications) + fun inject(fragment: TaskDefaults) + fun inject(fragment: ScrollableWidget) + fun inject(fragment: DashClock) + fun inject(fragment: TaskerListNotification) + fun inject(fragment: EmptyTaskEditFragment) + fun inject(fragment: NavigationDrawer) + fun inject(fragment: Widgets) + fun inject(fragment: DateAndTime) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/FragmentModule.java b/app/src/main/java/org/tasks/injection/FragmentModule.java deleted file mode 100644 index 09f2b8140..000000000 --- a/app/src/main/java/org/tasks/injection/FragmentModule.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.tasks.injection; - -import androidx.fragment.app.Fragment; -import dagger.Module; -import dagger.Provides; - -@Module -public class FragmentModule { - - private final Fragment fragment; - - public FragmentModule(Fragment fragment) { - this.fragment = fragment; - } - - @Provides - public Fragment getFragment() { - return fragment; - } -} diff --git a/app/src/main/java/org/tasks/injection/FragmentModule.kt b/app/src/main/java/org/tasks/injection/FragmentModule.kt new file mode 100644 index 000000000..3158fb857 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/FragmentModule.kt @@ -0,0 +1,8 @@ +package org.tasks.injection + +import androidx.fragment.app.Fragment +import dagger.Module +import dagger.Provides + +@Module +class FragmentModule(@get:Provides val fragment: Fragment) \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/InjectingActivity.java b/app/src/main/java/org/tasks/injection/InjectingActivity.java deleted file mode 100644 index 49e06816a..000000000 --- a/app/src/main/java/org/tasks/injection/InjectingActivity.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.tasks.injection; - -public interface InjectingActivity { - - void inject(ActivityComponent component); - - ActivityComponent getComponent(); -} diff --git a/app/src/main/java/org/tasks/injection/InjectingActivity.kt b/app/src/main/java/org/tasks/injection/InjectingActivity.kt new file mode 100644 index 000000000..a8d537422 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/InjectingActivity.kt @@ -0,0 +1,7 @@ +package org.tasks.injection + +interface InjectingActivity { + fun inject(component: ActivityComponent) + + val component: ActivityComponent +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/InjectingAppCompatActivity.java b/app/src/main/java/org/tasks/injection/InjectingAppCompatActivity.java deleted file mode 100644 index 438fe44ef..000000000 --- a/app/src/main/java/org/tasks/injection/InjectingAppCompatActivity.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.tasks.injection; - -import android.os.Bundle; -import androidx.appcompat.app.AppCompatActivity; -import org.tasks.locale.Locale; - -public abstract class InjectingAppCompatActivity extends AppCompatActivity - implements InjectingActivity { - - private ActivityComponent activityComponent; - - protected InjectingAppCompatActivity() { - Locale.getInstance(this).applyOverrideConfiguration(this); - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - activityComponent = - ((InjectingApplication) getApplication()).getComponent().plus(new ActivityModule(this)); - inject(activityComponent); - setTitle(""); - super.onCreate(savedInstanceState); - } - - @Override - public ActivityComponent getComponent() { - return activityComponent; - } -} diff --git a/app/src/main/java/org/tasks/injection/InjectingAppCompatActivity.kt b/app/src/main/java/org/tasks/injection/InjectingAppCompatActivity.kt new file mode 100644 index 000000000..d24944e56 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/InjectingAppCompatActivity.kt @@ -0,0 +1,20 @@ +package org.tasks.injection + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import org.tasks.locale.Locale + +abstract class InjectingAppCompatActivity protected constructor() : AppCompatActivity(), InjectingActivity { + override lateinit var component: ActivityComponent + + override fun onCreate(savedInstanceState: Bundle?) { + component = (application as InjectingApplication).component.plus(ActivityModule(this)) + inject(component) + title = "" + super.onCreate(savedInstanceState) + } + + init { + Locale.getInstance(this).applyOverrideConfiguration(this) + } +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/InjectingAppWidgetProvider.java b/app/src/main/java/org/tasks/injection/InjectingAppWidgetProvider.java deleted file mode 100644 index 3e51d8177..000000000 --- a/app/src/main/java/org/tasks/injection/InjectingAppWidgetProvider.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.tasks.injection; - -import android.appwidget.AppWidgetProvider; -import android.content.Context; -import android.content.Intent; - -public abstract class InjectingAppWidgetProvider extends AppWidgetProvider { - - @Override - public void onReceive(Context context, Intent intent) { - inject( - ((InjectingApplication) context.getApplicationContext()) - .getComponent() - .plus(new BroadcastModule())); - - super.onReceive(context, intent); - } - - protected abstract void inject(BroadcastComponent component); -} diff --git a/app/src/main/java/org/tasks/injection/InjectingAppWidgetProvider.kt b/app/src/main/java/org/tasks/injection/InjectingAppWidgetProvider.kt new file mode 100644 index 000000000..c0edc59b2 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/InjectingAppWidgetProvider.kt @@ -0,0 +1,17 @@ +package org.tasks.injection + +import android.appwidget.AppWidgetProvider +import android.content.Context +import android.content.Intent + +abstract class InjectingAppWidgetProvider : AppWidgetProvider() { + override fun onReceive(context: Context, intent: Intent) { + inject( + (context.applicationContext as InjectingApplication) + .component + .plus(BroadcastModule())) + super.onReceive(context, intent) + } + + protected abstract fun inject(component: BroadcastComponent) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/InjectingApplication.java b/app/src/main/java/org/tasks/injection/InjectingApplication.java deleted file mode 100644 index cd48c9157..000000000 --- a/app/src/main/java/org/tasks/injection/InjectingApplication.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.tasks.injection; - -import android.app.Application; -import android.content.Context; -import org.tasks.locale.Locale; - -public abstract class InjectingApplication extends Application { - - private ApplicationComponent applicationComponent; - - @Override - public void onCreate() { - super.onCreate(); - - Context context = Locale.getInstance(this).createConfigurationContext(getApplicationContext()); - - applicationComponent = Dagger.get(context).getApplicationComponent(); - - inject(applicationComponent); - } - - protected abstract void inject(ApplicationComponent component); - - public ApplicationComponent getComponent() { - return applicationComponent; - } -} diff --git a/app/src/main/java/org/tasks/injection/InjectingApplication.kt b/app/src/main/java/org/tasks/injection/InjectingApplication.kt new file mode 100644 index 000000000..a9f088a88 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/InjectingApplication.kt @@ -0,0 +1,17 @@ +package org.tasks.injection + +import android.app.Application +import org.tasks.locale.Locale + +abstract class InjectingApplication : Application() { + lateinit var component: ApplicationComponent + + override fun onCreate() { + super.onCreate() + val context = Locale.getInstance(this).createConfigurationContext(applicationContext) + component = Dagger.Companion[context].applicationComponent + inject(component) + } + + protected abstract fun inject(component: ApplicationComponent?) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/InjectingBottomSheetDialogFragment.java b/app/src/main/java/org/tasks/injection/InjectingBottomSheetDialogFragment.java deleted file mode 100644 index 5de0777f0..000000000 --- a/app/src/main/java/org/tasks/injection/InjectingBottomSheetDialogFragment.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.tasks.injection; - -import android.app.Activity; -import com.google.android.material.bottomsheet.BottomSheetDialogFragment; - -public abstract class InjectingBottomSheetDialogFragment extends BottomSheetDialogFragment { - - private boolean injected; - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - - if (!injected) { - inject(((InjectingActivity) activity).getComponent().plus(new DialogFragmentModule(this))); - injected = true; - } - } - - protected abstract void inject(DialogFragmentComponent component); -} diff --git a/app/src/main/java/org/tasks/injection/InjectingBottomSheetDialogFragment.kt b/app/src/main/java/org/tasks/injection/InjectingBottomSheetDialogFragment.kt new file mode 100644 index 000000000..1fa678190 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/InjectingBottomSheetDialogFragment.kt @@ -0,0 +1,17 @@ +package org.tasks.injection + +import android.app.Activity +import com.google.android.material.bottomsheet.BottomSheetDialogFragment + +abstract class InjectingBottomSheetDialogFragment : BottomSheetDialogFragment() { + private var injected = false + override fun onAttach(activity: Activity) { + super.onAttach(activity) + if (!injected) { + inject((activity as InjectingActivity).component.plus(DialogFragmentModule(this))) + injected = true + } + } + + protected abstract fun inject(component: DialogFragmentComponent) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/InjectingBroadcastReceiver.java b/app/src/main/java/org/tasks/injection/InjectingBroadcastReceiver.java deleted file mode 100644 index 9f13fbe60..000000000 --- a/app/src/main/java/org/tasks/injection/InjectingBroadcastReceiver.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.tasks.injection; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; - -public abstract class InjectingBroadcastReceiver extends BroadcastReceiver { - - @Override - public void onReceive(Context context, Intent intent) { - inject( - ((InjectingApplication) context.getApplicationContext()) - .getComponent() - .plus(new BroadcastModule())); - } - - protected abstract void inject(BroadcastComponent component); -} diff --git a/app/src/main/java/org/tasks/injection/InjectingBroadcastReceiver.kt b/app/src/main/java/org/tasks/injection/InjectingBroadcastReceiver.kt new file mode 100644 index 000000000..8ec62e24d --- /dev/null +++ b/app/src/main/java/org/tasks/injection/InjectingBroadcastReceiver.kt @@ -0,0 +1,16 @@ +package org.tasks.injection + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent + +abstract class InjectingBroadcastReceiver : BroadcastReceiver() { + override fun onReceive(context: Context, intent: Intent) { + inject( + (context.applicationContext as InjectingApplication) + .component + .plus(BroadcastModule())) + } + + protected abstract fun inject(component: BroadcastComponent) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/InjectingContentProvider.java b/app/src/main/java/org/tasks/injection/InjectingContentProvider.java deleted file mode 100644 index 1987829cf..000000000 --- a/app/src/main/java/org/tasks/injection/InjectingContentProvider.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.tasks.injection; - -import android.content.ContentProvider; -import android.content.Context; - -public abstract class InjectingContentProvider extends ContentProvider { - - @Override - public boolean onCreate() { - Context context = getContext(); - inject( - DaggerContentProviderComponent.builder() - .applicationModule(new ApplicationModule(context.getApplicationContext())) - .productionModule(new ProductionModule()) - .contentProviderModule(new ContentProviderModule()) - .build()); - - return true; - } - - protected abstract void inject(ContentProviderComponent component); -} diff --git a/app/src/main/java/org/tasks/injection/InjectingContentProvider.kt b/app/src/main/java/org/tasks/injection/InjectingContentProvider.kt new file mode 100644 index 000000000..1ca22189e --- /dev/null +++ b/app/src/main/java/org/tasks/injection/InjectingContentProvider.kt @@ -0,0 +1,17 @@ +package org.tasks.injection + +import android.content.ContentProvider + +abstract class InjectingContentProvider : ContentProvider() { + override fun onCreate(): Boolean { + inject( + DaggerContentProviderComponent.builder() + .applicationModule(ApplicationModule(context!!.applicationContext)) + .productionModule(ProductionModule()) + .contentProviderModule(ContentProviderModule()) + .build()) + return true + } + + protected abstract fun inject(component: ContentProviderComponent) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/InjectingDialogFragment.java b/app/src/main/java/org/tasks/injection/InjectingDialogFragment.java deleted file mode 100644 index a96598a87..000000000 --- a/app/src/main/java/org/tasks/injection/InjectingDialogFragment.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.tasks.injection; - -import android.app.Activity; -import androidx.fragment.app.DialogFragment; - -public abstract class InjectingDialogFragment extends DialogFragment { - - private boolean injected; - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - - if (!injected) { - inject(((InjectingActivity) activity).getComponent().plus(new DialogFragmentModule(this))); - injected = true; - } - } - - protected abstract void inject(DialogFragmentComponent component); -} diff --git a/app/src/main/java/org/tasks/injection/InjectingDialogFragment.kt b/app/src/main/java/org/tasks/injection/InjectingDialogFragment.kt new file mode 100644 index 000000000..c51e1508f --- /dev/null +++ b/app/src/main/java/org/tasks/injection/InjectingDialogFragment.kt @@ -0,0 +1,18 @@ +package org.tasks.injection + +import android.app.Activity +import androidx.fragment.app.DialogFragment + +abstract class InjectingDialogFragment : DialogFragment() { + private var injected = false + + override fun onAttach(activity: Activity) { + super.onAttach(activity) + if (!injected) { + inject((activity as InjectingActivity).component.plus(DialogFragmentModule(this))) + injected = true + } + } + + protected abstract fun inject(component: DialogFragmentComponent) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/InjectingFragment.java b/app/src/main/java/org/tasks/injection/InjectingFragment.java deleted file mode 100644 index 9a1e0b41c..000000000 --- a/app/src/main/java/org/tasks/injection/InjectingFragment.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.tasks.injection; - -import android.app.Activity; -import androidx.fragment.app.Fragment; - -public abstract class InjectingFragment extends Fragment { - - private boolean injected; - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - - if (!injected) { - inject(((InjectingActivity) activity).getComponent().plus(new FragmentModule(this))); - injected = true; - } - } - - protected abstract void inject(FragmentComponent component); -} diff --git a/app/src/main/java/org/tasks/injection/InjectingFragment.kt b/app/src/main/java/org/tasks/injection/InjectingFragment.kt new file mode 100644 index 000000000..a0580a7a8 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/InjectingFragment.kt @@ -0,0 +1,17 @@ +package org.tasks.injection + +import android.app.Activity +import androidx.fragment.app.Fragment + +abstract class InjectingFragment : Fragment() { + private var injected = false + override fun onAttach(activity: Activity) { + super.onAttach(activity) + if (!injected) { + inject((activity as InjectingActivity).component.plus(FragmentModule(this))) + injected = true + } + } + + protected abstract fun inject(component: FragmentComponent) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/InjectingJobIntentService.java b/app/src/main/java/org/tasks/injection/InjectingJobIntentService.java deleted file mode 100644 index adfc8bfed..000000000 --- a/app/src/main/java/org/tasks/injection/InjectingJobIntentService.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.tasks.injection; - -import android.content.Intent; -import androidx.annotation.NonNull; -import androidx.core.app.JobIntentService; -import timber.log.Timber; - -public abstract class InjectingJobIntentService extends JobIntentService { - - public static final int JOB_ID_GEOFENCE_TRANSITION = 1081; - public static final int JOB_ID_REFRESH_RECEIVER = 1082; - public static final int JOB_ID_NOTIFICATION_SCHEDULER = 1084; - public static final int JOB_ID_CALENDAR_NOTIFICATION = 1085; - public static final int JOB_ID_TASKER = 1086; - - @Override - protected final void onHandleWork(@NonNull Intent intent) { - inject( - ((InjectingApplication) getApplication()).getComponent().plus(new ServiceModule())); - - try { - doWork(intent); - } catch (Exception e) { - Timber.e(e); - } - } - - protected abstract void doWork(@NonNull Intent intent); - - protected abstract void inject(ServiceComponent component); -} diff --git a/app/src/main/java/org/tasks/injection/InjectingJobIntentService.kt b/app/src/main/java/org/tasks/injection/InjectingJobIntentService.kt new file mode 100644 index 000000000..0b96449e0 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/InjectingJobIntentService.kt @@ -0,0 +1,28 @@ +package org.tasks.injection + +import android.content.Intent +import androidx.core.app.JobIntentService +import timber.log.Timber + +abstract class InjectingJobIntentService : JobIntentService() { + override fun onHandleWork(intent: Intent) { + inject( + (application as InjectingApplication).component.plus(ServiceModule())) + try { + doWork(intent) + } catch (e: Exception) { + Timber.e(e) + } + } + + protected abstract fun doWork(intent: Intent) + protected abstract fun inject(component: ServiceComponent) + + companion object { + const val JOB_ID_GEOFENCE_TRANSITION = 1081 + const val JOB_ID_REFRESH_RECEIVER = 1082 + const val JOB_ID_NOTIFICATION_SCHEDULER = 1084 + const val JOB_ID_CALENDAR_NOTIFICATION = 1085 + const val JOB_ID_TASKER = 1086 + } +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/InjectingService.java b/app/src/main/java/org/tasks/injection/InjectingService.java deleted file mode 100644 index 7c3c65769..000000000 --- a/app/src/main/java/org/tasks/injection/InjectingService.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.tasks.injection; - -import android.app.Notification; -import android.app.Service; -import android.content.Intent; -import androidx.core.app.NotificationCompat; -import io.reactivex.Completable; -import io.reactivex.android.schedulers.AndroidSchedulers; -import io.reactivex.disposables.CompositeDisposable; -import io.reactivex.schedulers.Schedulers; -import javax.inject.Inject; -import org.tasks.R; -import org.tasks.analytics.Firebase; -import org.tasks.notifications.NotificationManager; - -public abstract class InjectingService extends Service { - - @Inject Firebase firebase; - - private CompositeDisposable disposables; - - @Override - public void onCreate() { - super.onCreate(); - - startForeground(); - - disposables = new CompositeDisposable(); - - inject(((InjectingApplication) getApplication()).getComponent().plus(new ServiceModule())); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - startForeground(); - - disposables.add( - Completable.fromAction(this::doWork) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe( - () -> done(startId), - t -> { - firebase.reportException(t); - done(startId); - })); - - return Service.START_NOT_STICKY; - } - - private void done(int startId) { - scheduleNext(); - stopSelf(startId); - } - - @Override - public void onDestroy() { - super.onDestroy(); - - stopForeground(true); - - disposables.dispose(); - } - - private void startForeground() { - startForeground(getNotificationId(), buildNotification()); - } - - protected abstract int getNotificationId(); - - protected abstract int getNotificationBody(); - - private Notification buildNotification() { - return new NotificationCompat.Builder( - this, NotificationManager.NOTIFICATION_CHANNEL_MISCELLANEOUS) - .setSound(null) - .setSmallIcon(R.drawable.ic_check_white_24dp) - .setContentTitle(getString(R.string.app_name)) - .setContentText(getString(getNotificationBody())) - .build(); - } - - protected void scheduleNext() { - - } - - protected abstract void doWork(); - - protected abstract void inject(ServiceComponent component); -} diff --git a/app/src/main/java/org/tasks/injection/InjectingService.kt b/app/src/main/java/org/tasks/injection/InjectingService.kt new file mode 100644 index 000000000..3fe11fc85 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/InjectingService.kt @@ -0,0 +1,73 @@ +package org.tasks.injection + +import android.app.Notification +import android.app.Service +import android.content.Intent +import androidx.core.app.NotificationCompat +import io.reactivex.Completable +import io.reactivex.android.schedulers.AndroidSchedulers +import io.reactivex.disposables.CompositeDisposable +import io.reactivex.schedulers.Schedulers +import org.tasks.R +import org.tasks.analytics.Firebase +import org.tasks.notifications.NotificationManager +import javax.inject.Inject + +abstract class InjectingService : Service() { + @Inject lateinit var firebase: Firebase + private var disposables: CompositeDisposable? = null + + override fun onCreate() { + super.onCreate() + startForeground() + disposables = CompositeDisposable() + inject((application as InjectingApplication).component.plus(ServiceModule())) + } + + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + startForeground() + disposables!!.add( + Completable.fromAction { doWork() } + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe( + { done(startId) } + ) { t: Throwable? -> + firebase!!.reportException(t) + done(startId) + }) + return START_NOT_STICKY + } + + private fun done(startId: Int) { + scheduleNext() + stopSelf(startId) + } + + override fun onDestroy() { + super.onDestroy() + stopForeground(true) + disposables!!.dispose() + } + + private fun startForeground() { + startForeground(notificationId, buildNotification()) + } + + protected abstract val notificationId: Int + protected abstract val notificationBody: Int + + private fun buildNotification(): Notification { + return NotificationCompat.Builder( + this, NotificationManager.NOTIFICATION_CHANNEL_MISCELLANEOUS) + .setSound(null) + .setSmallIcon(R.drawable.ic_check_white_24dp) + .setContentTitle(getString(R.string.app_name)) + .setContentText(getString(notificationBody)) + .build() + } + + protected open fun scheduleNext() {} + protected abstract fun doWork() + protected abstract fun inject(component: ServiceComponent) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/InjectingWorker.java b/app/src/main/java/org/tasks/injection/InjectingWorker.java deleted file mode 100644 index 42e05255a..000000000 --- a/app/src/main/java/org/tasks/injection/InjectingWorker.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.tasks.injection; - -import android.content.Context; -import androidx.annotation.NonNull; -import androidx.work.Worker; -import androidx.work.WorkerParameters; -import javax.inject.Inject; -import org.tasks.analytics.Firebase; -import timber.log.Timber; - -public abstract class InjectingWorker extends Worker { - - @Inject protected Firebase firebase; - - public InjectingWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { - super(context, workerParams); - } - - @NonNull - @Override - public Result doWork() { - Timber.d("%s.doWork()", getClass().getSimpleName()); - JobComponent component = - ((InjectingApplication) getApplicationContext()).getComponent().plus(new WorkModule()); - inject(component); - try { - return run(); - } catch (Exception e) { - firebase.reportException(e); - return Result.failure(); - } - } - - protected abstract Result run(); - - protected abstract void inject(JobComponent component); -} diff --git a/app/src/main/java/org/tasks/injection/InjectingWorker.kt b/app/src/main/java/org/tasks/injection/InjectingWorker.kt new file mode 100644 index 000000000..b22de7a41 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/InjectingWorker.kt @@ -0,0 +1,28 @@ +package org.tasks.injection + +import android.content.Context +import androidx.work.Worker +import androidx.work.WorkerParameters +import org.tasks.analytics.Firebase +import timber.log.Timber +import javax.inject.Inject + +abstract class InjectingWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) { + @Inject lateinit var firebase: Firebase + + override fun doWork(): Result { + Timber.d("%s.doWork()", javaClass.simpleName) + val component = (applicationContext as InjectingApplication).component.plus(WorkModule()) + inject(component) + return try { + run() + } catch (e: Exception) { + firebase.reportException(e) + Result.failure() + } + } + + protected abstract fun run(): Result + + protected abstract fun inject(component: JobComponent) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/JobComponent.java b/app/src/main/java/org/tasks/injection/JobComponent.java deleted file mode 100644 index 1e8264e2a..000000000 --- a/app/src/main/java/org/tasks/injection/JobComponent.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.tasks.injection; - -import dagger.Subcomponent; -import org.tasks.jobs.AfterSaveWork; -import org.tasks.jobs.BackupWork; -import org.tasks.jobs.CleanupWork; -import org.tasks.jobs.DriveUploader; -import org.tasks.jobs.MidnightRefreshWork; -import org.tasks.jobs.RefreshWork; -import org.tasks.jobs.RemoteConfigWork; -import org.tasks.jobs.ReverseGeocodeWork; -import org.tasks.jobs.SyncWork; - -@Subcomponent(modules = WorkModule.class) -public interface JobComponent { - - void inject(SyncWork syncWork); - - void inject(BackupWork backupWork); - - void inject(RefreshWork refreshWork); - - void inject(CleanupWork cleanupWork); - - void inject(MidnightRefreshWork midnightRefreshWork); - - void inject(AfterSaveWork afterSaveWork); - - void inject(DriveUploader driveUploader); - - void inject(ReverseGeocodeWork reverseGeocodeWork); - - void inject(RemoteConfigWork remoteConfigWork); -} diff --git a/app/src/main/java/org/tasks/injection/JobComponent.kt b/app/src/main/java/org/tasks/injection/JobComponent.kt new file mode 100644 index 000000000..533217fc6 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/JobComponent.kt @@ -0,0 +1,17 @@ +package org.tasks.injection + +import dagger.Subcomponent +import org.tasks.jobs.* + +@Subcomponent(modules = [WorkModule::class]) +interface JobComponent { + fun inject(work: SyncWork) + fun inject(work: BackupWork) + fun inject(work: RefreshWork) + fun inject(work: CleanupWork) + fun inject(work: MidnightRefreshWork) + fun inject(work: AfterSaveWork) + fun inject(work: DriveUploader) + fun inject(work: ReverseGeocodeWork) + fun inject(work: RemoteConfigWork) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/ProductionModule.java b/app/src/main/java/org/tasks/injection/ProductionModule.java deleted file mode 100644 index bccaa58d6..000000000 --- a/app/src/main/java/org/tasks/injection/ProductionModule.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.tasks.injection; - -import android.content.Context; -import androidx.room.Room; -import com.todoroo.astrid.dao.Database; -import dagger.Module; -import dagger.Provides; -import org.tasks.db.Migrations; -import org.tasks.preferences.Preferences; - -@Module(includes = ApplicationModule.class) -class ProductionModule { - @Provides - @ApplicationScope - Database getAppDatabase(@ForApplication Context context) { - return Room.databaseBuilder(context, Database.class, Database.NAME) - .allowMainThreadQueries() // TODO: remove me - .addMigrations(Migrations.MIGRATIONS) - .build(); - } - - @Provides - Preferences getPreferences(@ForApplication Context context) { - return new Preferences(context); - } -} diff --git a/app/src/main/java/org/tasks/injection/ProductionModule.kt b/app/src/main/java/org/tasks/injection/ProductionModule.kt new file mode 100644 index 000000000..c695d74aa --- /dev/null +++ b/app/src/main/java/org/tasks/injection/ProductionModule.kt @@ -0,0 +1,26 @@ +package org.tasks.injection + +import android.content.Context +import androidx.room.Room +import com.todoroo.astrid.dao.Database +import dagger.Module +import dagger.Provides +import org.tasks.db.Migrations +import org.tasks.preferences.Preferences + +@Module(includes = [ApplicationModule::class]) +internal class ProductionModule { + @Provides + @ApplicationScope + fun getAppDatabase(@ForApplication context: Context): Database { + return Room.databaseBuilder(context, Database::class.java, Database.NAME) + .allowMainThreadQueries() // TODO: remove me + .addMigrations(*Migrations.MIGRATIONS) + .build() + } + + @Provides + fun getPreferences(@ForApplication context: Context): Preferences { + return Preferences(context) + } +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/ServiceComponent.java b/app/src/main/java/org/tasks/injection/ServiceComponent.java deleted file mode 100644 index 44923106f..000000000 --- a/app/src/main/java/org/tasks/injection/ServiceComponent.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.tasks.injection; - -import dagger.Subcomponent; -import org.tasks.jobs.NotificationService; -import org.tasks.locale.receiver.TaskerIntentService; -import org.tasks.location.GeofenceTransitionsIntentService; -import org.tasks.receivers.RefreshReceiver; -import org.tasks.scheduling.CalendarNotificationIntentService; -import org.tasks.scheduling.NotificationSchedulerIntentService; - -@Subcomponent(modules = ServiceModule.class) -public interface ServiceComponent { - - void inject(CalendarNotificationIntentService calendarNotificationIntentService); - - void inject(GeofenceTransitionsIntentService geofenceTransitionsIntentService); - - void inject(NotificationSchedulerIntentService notificationSchedulerIntentService); - - void inject(TaskerIntentService taskerIntentService); - - void inject(NotificationService notificationService); - - void inject(RefreshReceiver refreshReceiver); -} diff --git a/app/src/main/java/org/tasks/injection/ServiceComponent.kt b/app/src/main/java/org/tasks/injection/ServiceComponent.kt new file mode 100644 index 000000000..ed60b842e --- /dev/null +++ b/app/src/main/java/org/tasks/injection/ServiceComponent.kt @@ -0,0 +1,19 @@ +package org.tasks.injection + +import dagger.Subcomponent +import org.tasks.jobs.NotificationService +import org.tasks.locale.receiver.TaskerIntentService +import org.tasks.location.GeofenceTransitionsIntentService +import org.tasks.receivers.RefreshReceiver +import org.tasks.scheduling.CalendarNotificationIntentService +import org.tasks.scheduling.NotificationSchedulerIntentService + +@Subcomponent(modules = [ServiceModule::class]) +interface ServiceComponent { + fun inject(service: CalendarNotificationIntentService) + fun inject(service: GeofenceTransitionsIntentService) + fun inject(service: NotificationSchedulerIntentService) + fun inject(service: TaskerIntentService) + fun inject(service: NotificationService) + fun inject(service: RefreshReceiver) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/ServiceModule.java b/app/src/main/java/org/tasks/injection/ServiceModule.java deleted file mode 100644 index 220c3e185..000000000 --- a/app/src/main/java/org/tasks/injection/ServiceModule.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.tasks.injection; - -import dagger.Module; - -@Module -class ServiceModule {} diff --git a/app/src/main/java/org/tasks/injection/ServiceModule.kt b/app/src/main/java/org/tasks/injection/ServiceModule.kt new file mode 100644 index 000000000..2c3572575 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/ServiceModule.kt @@ -0,0 +1,6 @@ +package org.tasks.injection + +import dagger.Module + +@Module +class ServiceModule \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/ThemedInjectingAppCompatActivity.java b/app/src/main/java/org/tasks/injection/ThemedInjectingAppCompatActivity.java deleted file mode 100644 index 33570b0d5..000000000 --- a/app/src/main/java/org/tasks/injection/ThemedInjectingAppCompatActivity.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.tasks.injection; - -import android.os.Bundle; -import androidx.appcompat.app.AppCompatActivity; -import javax.inject.Inject; -import org.tasks.locale.Locale; -import org.tasks.themes.Theme; -import org.tasks.themes.ThemeColor; - -public abstract class ThemedInjectingAppCompatActivity extends AppCompatActivity - implements InjectingActivity { - - @Inject protected Theme theme; - @Inject protected ThemeColor themeColor; - - private ActivityComponent activityComponent; - - protected ThemedInjectingAppCompatActivity() { - Locale.getInstance(this).applyOverrideConfiguration(this); - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - activityComponent = - ((InjectingApplication) getApplication()).getComponent().plus(new ActivityModule(this)); - inject(activityComponent); - setTitle(null); - theme.applyThemeAndStatusBarColor(this); - super.onCreate(savedInstanceState); - } - - @Override - public ActivityComponent getComponent() { - return activityComponent; - } -} diff --git a/app/src/main/java/org/tasks/injection/ThemedInjectingAppCompatActivity.kt b/app/src/main/java/org/tasks/injection/ThemedInjectingAppCompatActivity.kt new file mode 100644 index 000000000..a78da51f2 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/ThemedInjectingAppCompatActivity.kt @@ -0,0 +1,27 @@ +package org.tasks.injection + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import org.tasks.locale.Locale +import org.tasks.themes.Theme +import org.tasks.themes.ThemeColor +import javax.inject.Inject + +abstract class ThemedInjectingAppCompatActivity protected constructor() : AppCompatActivity(), InjectingActivity { + @Inject lateinit var tasksTheme: Theme + @Inject protected lateinit var themeColor: ThemeColor + + override lateinit var component: ActivityComponent + + override fun onCreate(savedInstanceState: Bundle?) { + component = (application as InjectingApplication).component.plus(ActivityModule(this)) + inject(component) + title = null + tasksTheme.applyThemeAndStatusBarColor(this) + super.onCreate(savedInstanceState) + } + + init { + Locale.getInstance(this).applyOverrideConfiguration(this) + } +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/WorkModule.java b/app/src/main/java/org/tasks/injection/WorkModule.java deleted file mode 100644 index 3c69da02b..000000000 --- a/app/src/main/java/org/tasks/injection/WorkModule.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.tasks.injection; - -import dagger.Module; - -@Module -class WorkModule {} diff --git a/app/src/main/java/org/tasks/injection/WorkModule.kt b/app/src/main/java/org/tasks/injection/WorkModule.kt new file mode 100644 index 000000000..a1369b98b --- /dev/null +++ b/app/src/main/java/org/tasks/injection/WorkModule.kt @@ -0,0 +1,6 @@ +package org.tasks.injection + +import dagger.Module + +@Module +class WorkModule \ No newline at end of file