diff --git a/app/src/androidTest/java/org/tasks/injection/TestModule.kt b/app/src/androidTest/java/org/tasks/injection/TestModule.kt index 6c6a61953..5ac0c8430 100644 --- a/app/src/androidTest/java/org/tasks/injection/TestModule.kt +++ b/app/src/androidTest/java/org/tasks/injection/TestModule.kt @@ -14,19 +14,19 @@ import org.tasks.preferences.Preferences class TestModule { @Provides @ApplicationScope - fun getDatabase(context: Application): Database { + fun getDatabase(@ApplicationContext context: Context): Database { return Room.inMemoryDatabaseBuilder(context, Database::class.java) .fallbackToDestructiveMigration() .build() } @Provides - fun getPermissionChecker(context: Application): PermissionChecker { + fun getPermissionChecker(@ApplicationContext context: Context): PermissionChecker { return PermissivePermissionChecker(context) } @Provides - fun getPreferences(context: Application): Preferences { + fun getPreferences(@ApplicationContext context: Context): Preferences { return TestUtilities.newPreferences(context) } } \ No newline at end of file diff --git a/app/src/androidTest/java/org/tasks/preferences/PermissivePermissionChecker.kt b/app/src/androidTest/java/org/tasks/preferences/PermissivePermissionChecker.kt index cbae9e9ac..1172ed037 100644 --- a/app/src/androidTest/java/org/tasks/preferences/PermissivePermissionChecker.kt +++ b/app/src/androidTest/java/org/tasks/preferences/PermissivePermissionChecker.kt @@ -1,8 +1,9 @@ package org.tasks.preferences import android.content.Context +import org.tasks.injection.ApplicationContext -class PermissivePermissionChecker(context: Application) : PermissionChecker(context) { +class PermissivePermissionChecker(@ApplicationContext context: Context) : PermissionChecker(context) { override fun canAccessCalendars() = true override fun canAccessAccounts() = true diff --git a/app/src/debug/java/org/tasks/BuildSetup.kt b/app/src/debug/java/org/tasks/BuildSetup.kt index d1e240120..c836cd6aa 100644 --- a/app/src/debug/java/org/tasks/BuildSetup.kt +++ b/app/src/debug/java/org/tasks/BuildSetup.kt @@ -1,6 +1,5 @@ package org.tasks -import android.app.Application import android.content.Context import android.os.StrictMode import android.os.StrictMode.VmPolicy @@ -13,12 +12,13 @@ import com.facebook.flipper.plugins.network.NetworkFlipperPlugin import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin import com.facebook.soloader.SoLoader import leakcanary.AppWatcher +import org.tasks.injection.ApplicationContext import org.tasks.preferences.Preferences import timber.log.Timber import timber.log.Timber.DebugTree import javax.inject.Inject -class BuildSetup @Inject constructor(private val context: Application, private val preferences: Preferences) { +class BuildSetup @Inject constructor(@param:ApplicationContext private val context: Context, private val preferences: Preferences) { fun setup() { Timber.plant(DebugTree()) SoLoader.init(context, false) diff --git a/app/src/debug/java/org/tasks/DebugNetworkInterceptor.kt b/app/src/debug/java/org/tasks/DebugNetworkInterceptor.kt index 11efb12b9..5333b1056 100644 --- a/app/src/debug/java/org/tasks/DebugNetworkInterceptor.kt +++ b/app/src/debug/java/org/tasks/DebugNetworkInterceptor.kt @@ -1,6 +1,5 @@ package org.tasks -import android.app.Application import android.content.Context import com.facebook.flipper.android.AndroidFlipperClient import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor @@ -8,10 +7,11 @@ import com.facebook.flipper.plugins.network.NetworkFlipperPlugin import com.google.api.client.http.HttpRequest import com.google.api.client.http.HttpResponse import okhttp3.OkHttpClient +import org.tasks.injection.ApplicationContext import java.io.IOException import javax.inject.Inject -class DebugNetworkInterceptor @Inject constructor(private val context: Application) { +class DebugNetworkInterceptor @Inject constructor(@param:ApplicationContext private val context: Context) { fun add(builder: OkHttpClient.Builder) { builder.addNetworkInterceptor(FlipperOkhttpInterceptor(getNetworkPlugin(context))) } diff --git a/app/src/generic/java/org/tasks/injection/LocationModule.kt b/app/src/generic/java/org/tasks/injection/LocationModule.kt index 6642fdddf..591a74cf1 100644 --- a/app/src/generic/java/org/tasks/injection/LocationModule.kt +++ b/app/src/generic/java/org/tasks/injection/LocationModule.kt @@ -1,6 +1,6 @@ package org.tasks.injection -import android.app.Application +import android.content.Context import dagger.Module import dagger.Provides import org.tasks.location.MapFragment @@ -12,13 +12,13 @@ import org.tasks.location.PlaceSearchProvider class LocationModule { @Provides @ActivityScope - fun getPlaceSearchProvider(context: Application): PlaceSearchProvider { + fun getPlaceSearchProvider(@ForApplication context: Context): PlaceSearchProvider { return MapboxSearchProvider(context) } @Provides @ActivityScope - fun getMapFragment(context: Application): MapFragment { + fun getMapFragment(@ForApplication context: Context): MapFragment { return MapboxMapFragment(context) } } \ No newline at end of file diff --git a/app/src/googleplay/java/org/tasks/analytics/Firebase.kt b/app/src/googleplay/java/org/tasks/analytics/Firebase.kt index b58c34767..77c2c125b 100644 --- a/app/src/googleplay/java/org/tasks/analytics/Firebase.kt +++ b/app/src/googleplay/java/org/tasks/analytics/Firebase.kt @@ -1,6 +1,5 @@ package org.tasks.analytics -import android.app.Application import android.content.Context import android.os.Bundle import androidx.annotation.StringRes @@ -13,6 +12,7 @@ import io.fabric.sdk.android.Fabric import org.tasks.R import org.tasks.billing.BillingClientImpl import org.tasks.injection.ApplicationScope +import org.tasks.injection.ApplicationContext import org.tasks.jobs.WorkManager import org.tasks.preferences.Preferences import timber.log.Timber @@ -20,7 +20,7 @@ import java.util.concurrent.TimeUnit import javax.inject.Inject @ApplicationScope -class Firebase @Inject constructor(val context: Application, preferences: Preferences) { +class Firebase @Inject constructor(@param:ApplicationContext val context: Context, preferences: Preferences) { private var enabled: Boolean = preferences.isTrackingEnabled private var analytics: FirebaseAnalytics? = null diff --git a/app/src/googleplay/java/org/tasks/billing/BillingClientImpl.java b/app/src/googleplay/java/org/tasks/billing/BillingClientImpl.java index 4398e0965..0c3666c2c 100644 --- a/app/src/googleplay/java/org/tasks/billing/BillingClientImpl.java +++ b/app/src/googleplay/java/org/tasks/billing/BillingClientImpl.java @@ -4,7 +4,7 @@ import static com.google.common.collect.Lists.newArrayList; import static com.todoroo.andlib.utility.AndroidUtilities.assertMainThread; import android.app.Activity; -import android.app.Application; +import android.content.Context; import androidx.annotation.Nullable; import com.android.billingclient.api.BillingClient.BillingResponse; import com.android.billingclient.api.BillingClient.FeatureType; @@ -22,6 +22,7 @@ import io.reactivex.schedulers.Schedulers; import java.util.List; import org.tasks.BuildConfig; import org.tasks.analytics.Firebase; +import org.tasks.injection.ApplicationContext; import timber.log.Timber; @SuppressWarnings("all") @@ -35,7 +36,7 @@ public class BillingClientImpl implements BillingClient, PurchasesUpdatedListene private boolean connected; private OnPurchasesUpdated onPurchasesUpdated; - public BillingClientImpl(Application context, Inventory inventory, Firebase firebase) { + public BillingClientImpl(@ApplicationContext Context context, Inventory inventory, Firebase firebase) { this.inventory = inventory; this.firebase = firebase; billingClient = diff --git a/app/src/googleplay/java/org/tasks/billing/SignatureVerifier.kt b/app/src/googleplay/java/org/tasks/billing/SignatureVerifier.kt index 47eb5fba7..38ba55f7f 100644 --- a/app/src/googleplay/java/org/tasks/billing/SignatureVerifier.kt +++ b/app/src/googleplay/java/org/tasks/billing/SignatureVerifier.kt @@ -1,13 +1,13 @@ package org.tasks.billing -import android.app.Application import android.content.Context import org.tasks.R +import org.tasks.injection.ApplicationContext import timber.log.Timber import java.io.IOException import javax.inject.Inject -internal class SignatureVerifier @Inject constructor(context: Application) { +internal class SignatureVerifier @Inject constructor(@ApplicationContext context: Context) { private val billingKey: String = context.getString(R.string.gp_key) fun verifySignature(purchase: Purchase): Boolean { diff --git a/app/src/googleplay/java/org/tasks/gtasks/PlayServices.kt b/app/src/googleplay/java/org/tasks/gtasks/PlayServices.kt index 0bc82d6a1..5cb385c0b 100644 --- a/app/src/googleplay/java/org/tasks/gtasks/PlayServices.kt +++ b/app/src/googleplay/java/org/tasks/gtasks/PlayServices.kt @@ -1,7 +1,6 @@ package org.tasks.gtasks import android.app.Activity -import android.app.Application import android.content.Context import android.widget.Toast import com.google.android.gms.common.ConnectionResult @@ -14,12 +13,13 @@ import io.reactivex.schedulers.Schedulers import org.tasks.R import org.tasks.data.GoogleTaskListDao import org.tasks.data.LocationDao +import org.tasks.injection.ApplicationContext import org.tasks.preferences.Preferences import timber.log.Timber import javax.inject.Inject class PlayServices @Inject constructor( - private val context: Application, + @param:ApplicationContext private val context: Context, private val preferences: Preferences, private val googleTaskListDao: GoogleTaskListDao, private val locationDao: LocationDao) { diff --git a/app/src/googleplay/java/org/tasks/injection/LocationModule.kt b/app/src/googleplay/java/org/tasks/injection/LocationModule.kt index 68247a454..1b178077c 100644 --- a/app/src/googleplay/java/org/tasks/injection/LocationModule.kt +++ b/app/src/googleplay/java/org/tasks/injection/LocationModule.kt @@ -1,6 +1,6 @@ package org.tasks.injection -import android.app.Application +import android.content.Context import dagger.Module import dagger.Provides import org.tasks.billing.Inventory @@ -13,7 +13,7 @@ internal class LocationModule { @Provides @ActivityScope fun getPlaceSearchProvider( - context: Application, + @ApplicationContext context: Context, preferences: Preferences, playServices: PlayServices, inventory: Inventory): PlaceSearchProvider { @@ -28,7 +28,7 @@ internal class LocationModule { @Provides @ActivityScope - fun getMapFragment(context: Application, preferences: Preferences): MapFragment { + fun getMapFragment(@ApplicationContext context: Context, preferences: Preferences): MapFragment { return if (preferences.useGoogleMaps()) { GoogleMapFragment(context) } else { diff --git a/app/src/googleplay/java/org/tasks/location/GeofenceApi.kt b/app/src/googleplay/java/org/tasks/location/GeofenceApi.kt index 109ddfef0..9638a7b97 100644 --- a/app/src/googleplay/java/org/tasks/location/GeofenceApi.kt +++ b/app/src/googleplay/java/org/tasks/location/GeofenceApi.kt @@ -1,7 +1,6 @@ package org.tasks.location import android.annotation.SuppressLint -import android.app.Application import android.app.PendingIntent import android.content.Context import android.content.Intent @@ -11,12 +10,13 @@ import com.google.android.gms.location.LocationServices import org.tasks.data.LocationDao import org.tasks.data.MergedGeofence import org.tasks.data.Place +import org.tasks.injection.ApplicationContext import org.tasks.preferences.PermissionChecker import timber.log.Timber import javax.inject.Inject class GeofenceApi @Inject constructor( - private val context: Application, + @param:ApplicationContext private val context: Context, private val permissionChecker: PermissionChecker, private val locationDao: LocationDao) { diff --git a/app/src/main/java/com/todoroo/astrid/activity/ShareLinkActivity.java b/app/src/main/java/com/todoroo/astrid/activity/ShareLinkActivity.java index 468af8ad4..a8e800ef1 100644 --- a/app/src/main/java/com/todoroo/astrid/activity/ShareLinkActivity.java +++ b/app/src/main/java/com/todoroo/astrid/activity/ShareLinkActivity.java @@ -8,7 +8,6 @@ import static org.tasks.files.FileHelper.copyToUri; import static org.tasks.files.FileHelper.getFilename; import static org.tasks.intents.TaskIntents.getTaskListIntent; -import android.app.Application; import android.content.Context; import android.content.Intent; import android.net.Uri; @@ -22,6 +21,7 @@ import javax.inject.Inject; import org.tasks.data.TaskAttachment; import org.tasks.files.FileHelper; import org.tasks.injection.ActivityComponent; +import org.tasks.injection.ApplicationContext; import org.tasks.injection.InjectingAppCompatActivity; import org.tasks.preferences.Preferences; import timber.log.Timber; @@ -32,7 +32,7 @@ import timber.log.Timber; */ public final class ShareLinkActivity extends InjectingAppCompatActivity { - @Inject Application context; + @Inject @ApplicationContext Context context; @Inject TaskCreator taskCreator; @Inject Preferences preferences; diff --git a/app/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java b/app/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java index 7777b13cd..aecc6d650 100755 --- a/app/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java +++ b/app/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java @@ -59,6 +59,7 @@ import org.tasks.databinding.FragmentTaskEditBinding; import org.tasks.dialogs.DialogBuilder; import org.tasks.dialogs.Linkify; import org.tasks.fragments.TaskEditControlSetFragmentManager; +import org.tasks.injection.ActivityContext; import org.tasks.injection.FragmentComponent; import org.tasks.injection.InjectingFragment; import org.tasks.notifications.NotificationManager; @@ -80,7 +81,7 @@ public final class TaskEditFragment extends InjectingFragment @Inject TaskDeleter taskDeleter; @Inject NotificationManager notificationManager; @Inject DialogBuilder dialogBuilder; - @Inject Activity context; + @Inject @ActivityContext Context context; @Inject TaskEditControlSetFragmentManager taskEditControlSetFragmentManager; @Inject CommentsController commentsController; @Inject Preferences preferences; diff --git a/app/src/main/java/com/todoroo/astrid/adapter/TaskAdapterProvider.kt b/app/src/main/java/com/todoroo/astrid/adapter/TaskAdapterProvider.kt index 349a3ff2f..ffeee858e 100644 --- a/app/src/main/java/com/todoroo/astrid/adapter/TaskAdapterProvider.kt +++ b/app/src/main/java/com/todoroo/astrid/adapter/TaskAdapterProvider.kt @@ -1,6 +1,5 @@ package com.todoroo.astrid.adapter -import android.app.Application import android.content.Context import com.todoroo.astrid.api.CaldavFilter import com.todoroo.astrid.api.Filter @@ -17,11 +16,12 @@ import org.tasks.data.CaldavDao import org.tasks.data.GoogleTaskDao import org.tasks.data.TaskListMetadata import org.tasks.data.TaskListMetadataDao +import org.tasks.injection.ApplicationContext import org.tasks.preferences.Preferences import javax.inject.Inject class TaskAdapterProvider @Inject constructor( - private val context: Application, + @param:ApplicationContext private val context: Context, private val preferences: Preferences, private val taskListMetadataDao: TaskListMetadataDao, private val taskDao: TaskDao, diff --git a/app/src/main/java/com/todoroo/astrid/core/BuiltInFilterExposer.java b/app/src/main/java/com/todoroo/astrid/core/BuiltInFilterExposer.java index 7bddfc8c4..6c76a20ae 100644 --- a/app/src/main/java/com/todoroo/astrid/core/BuiltInFilterExposer.java +++ b/app/src/main/java/com/todoroo/astrid/core/BuiltInFilterExposer.java @@ -6,7 +6,6 @@ package com.todoroo.astrid.core; -import android.app.Application; import android.content.Context; import android.content.res.Resources; import com.todoroo.andlib.sql.Criterion; @@ -26,6 +25,7 @@ import javax.inject.Inject; import org.tasks.R; import org.tasks.filters.RecentlyModifiedFilter; import org.tasks.filters.SortableFilter; +import org.tasks.injection.ApplicationContext; import org.tasks.preferences.Preferences; import org.tasks.themes.CustomIcons; @@ -42,7 +42,7 @@ public final class BuiltInFilterExposer { @Inject public BuiltInFilterExposer( - Application context, Preferences preferences, TaskDao taskDao) { + @ApplicationContext Context context, Preferences preferences, TaskDao taskDao) { this.context = context; this.preferences = preferences; this.taskDao = taskDao; diff --git a/app/src/main/java/com/todoroo/astrid/files/FilesControlSet.kt b/app/src/main/java/com/todoroo/astrid/files/FilesControlSet.kt index 6d9216dad..0a4c020c6 100644 --- a/app/src/main/java/com/todoroo/astrid/files/FilesControlSet.kt +++ b/app/src/main/java/com/todoroo/astrid/files/FilesControlSet.kt @@ -25,6 +25,7 @@ import org.tasks.data.TaskAttachmentDao import org.tasks.dialogs.AddAttachmentDialog import org.tasks.dialogs.DialogBuilder import org.tasks.files.FileHelper +import org.tasks.injection.ActivityContext import org.tasks.injection.FragmentComponent import org.tasks.preferences.Preferences import org.tasks.ui.TaskEditControlFragment @@ -32,7 +33,7 @@ import java.util.* import javax.inject.Inject class FilesControlSet : TaskEditControlFragment() { - @Inject lateinit var activity: Activity + @Inject @ActivityContext lateinit var activity: Context @Inject lateinit var taskAttachmentDao: TaskAttachmentDao @Inject lateinit var dialogBuilder: DialogBuilder @Inject lateinit var preferences: Preferences diff --git a/app/src/main/java/com/todoroo/astrid/gcal/GCalHelper.java b/app/src/main/java/com/todoroo/astrid/gcal/GCalHelper.java index ea1f48584..2cafb0049 100644 --- a/app/src/main/java/com/todoroo/astrid/gcal/GCalHelper.java +++ b/app/src/main/java/com/todoroo/astrid/gcal/GCalHelper.java @@ -8,9 +8,9 @@ package com.todoroo.astrid.gcal; import static org.tasks.Strings.isNullOrEmpty; -import android.app.Application; import android.content.ContentResolver; import android.content.ContentValues; +import android.content.Context; import android.net.Uri; import android.provider.CalendarContract; import android.text.format.Time; @@ -22,6 +22,7 @@ import javax.inject.Inject; import org.tasks.R; import org.tasks.calendars.AndroidCalendarEvent; import org.tasks.calendars.CalendarEventProvider; +import org.tasks.injection.ApplicationContext; import org.tasks.preferences.PermissionChecker; import org.tasks.preferences.Preferences; import timber.log.Timber; @@ -39,7 +40,7 @@ public class GCalHelper { @Inject public GCalHelper( - Application context, + @ApplicationContext Context context, TaskDao taskDao, Preferences preferences, PermissionChecker permissionChecker, diff --git a/app/src/main/java/com/todoroo/astrid/gtasks/api/GtasksInvoker.java b/app/src/main/java/com/todoroo/astrid/gtasks/api/GtasksInvoker.java index 451b8a118..fa92fee31 100644 --- a/app/src/main/java/com/todoroo/astrid/gtasks/api/GtasksInvoker.java +++ b/app/src/main/java/com/todoroo/astrid/gtasks/api/GtasksInvoker.java @@ -1,6 +1,5 @@ package com.todoroo.astrid.gtasks.api; -import android.app.Application; import android.content.Context; import androidx.annotation.Nullable; import com.google.api.client.http.HttpRequest; @@ -19,6 +18,7 @@ import javax.inject.Inject; import org.tasks.BuildConfig; import org.tasks.DebugNetworkInterceptor; import org.tasks.gtasks.GoogleAccountManager; +import org.tasks.injection.ApplicationContext; import org.tasks.preferences.Preferences; import timber.log.Timber; @@ -40,7 +40,7 @@ public class GtasksInvoker { @Inject public GtasksInvoker( - Application context, + @ApplicationContext Context context, GoogleAccountManager googleAccountManager, Preferences preferences, DebugNetworkInterceptor interceptor) { diff --git a/app/src/main/java/com/todoroo/astrid/repeats/RepeatControlSet.kt b/app/src/main/java/com/todoroo/astrid/repeats/RepeatControlSet.kt index 6ac04f593..e471bc834 100644 --- a/app/src/main/java/com/todoroo/astrid/repeats/RepeatControlSet.kt +++ b/app/src/main/java/com/todoroo/astrid/repeats/RepeatControlSet.kt @@ -5,7 +5,6 @@ */ package com.todoroo.astrid.repeats -import android.app.Activity import android.content.Context import android.os.Bundle import android.view.LayoutInflater @@ -25,6 +24,7 @@ import org.tasks.R import org.tasks.Strings.isNullOrEmpty import org.tasks.analytics.Firebase import org.tasks.dialogs.DialogBuilder +import org.tasks.injection.ActivityContext import org.tasks.injection.FragmentComponent import org.tasks.repeats.BasicRecurrenceDialog import org.tasks.repeats.RepeatRuleToString @@ -45,7 +45,7 @@ import javax.inject.Inject class RepeatControlSet : TaskEditControlFragment() { private val repeatTypes: MutableList = ArrayList() - @Inject lateinit var activity: Activity + @Inject @ActivityContext lateinit var activity: Context @Inject lateinit var dialogBuilder: DialogBuilder @Inject lateinit var theme: Theme @Inject lateinit var firebase: Firebase diff --git a/app/src/main/java/com/todoroo/astrid/service/TaskMover.kt b/app/src/main/java/com/todoroo/astrid/service/TaskMover.kt index 785a8589c..7224e4a47 100644 --- a/app/src/main/java/com/todoroo/astrid/service/TaskMover.kt +++ b/app/src/main/java/com/todoroo/astrid/service/TaskMover.kt @@ -1,6 +1,5 @@ package com.todoroo.astrid.service -import android.app.Application import android.content.Context import com.todoroo.andlib.utility.DateUtilities import com.todoroo.astrid.api.CaldavFilter @@ -12,12 +11,13 @@ import org.tasks.BuildConfig import org.tasks.LocalBroadcastManager import org.tasks.data.* import org.tasks.db.DbUtils.dbchunk +import org.tasks.injection.ApplicationContext import org.tasks.preferences.Preferences import java.util.* import javax.inject.Inject class TaskMover @Inject constructor( - private val context: Application, + @param:ApplicationContext private val context: Context, private val taskDao: TaskDao, private val caldavDao: CaldavDao, private val googleTaskDao: GoogleTaskDao, diff --git a/app/src/main/java/com/todoroo/astrid/service/Upgrader.kt b/app/src/main/java/com/todoroo/astrid/service/Upgrader.kt index a5f568dd1..b911ca92c 100644 --- a/app/src/main/java/com/todoroo/astrid/service/Upgrader.kt +++ b/app/src/main/java/com/todoroo/astrid/service/Upgrader.kt @@ -1,6 +1,5 @@ package com.todoroo.astrid.service -import android.app.Application import android.content.Context import androidx.annotation.ColorRes import com.google.common.collect.ImmutableListMultimap @@ -15,6 +14,7 @@ import org.tasks.caldav.iCalendar.Companion.fromVtodo import org.tasks.caldav.iCalendar.Companion.getParent import org.tasks.caldav.iCalendar.Companion.order import org.tasks.data.* +import org.tasks.injection.ApplicationContext import org.tasks.preferences.DefaultFilterProvider import org.tasks.preferences.Preferences import org.tasks.widget.AppWidgetManager @@ -24,7 +24,7 @@ import java.util.* import javax.inject.Inject class Upgrader @Inject constructor( - private val context: Application, + @param:ApplicationContext private val context: Context, private val preferences: Preferences, private val tagDataDao: TagDataDao, private val tagDao: TagDao, diff --git a/app/src/main/java/com/todoroo/astrid/subtasks/SubtasksHelper.java b/app/src/main/java/com/todoroo/astrid/subtasks/SubtasksHelper.java index 6b20638d2..b4bfa1732 100644 --- a/app/src/main/java/com/todoroo/astrid/subtasks/SubtasksHelper.java +++ b/app/src/main/java/com/todoroo/astrid/subtasks/SubtasksHelper.java @@ -3,7 +3,6 @@ package com.todoroo.astrid.subtasks; import static org.tasks.Strings.isNullOrEmpty; import static org.tasks.db.QueryUtils.showHiddenAndCompleted; -import android.app.Application; import android.content.Context; import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.core.BuiltInFilterExposer; @@ -19,6 +18,7 @@ import org.tasks.data.TagData; import org.tasks.data.TagDataDao; import org.tasks.data.TaskListMetadata; import org.tasks.data.TaskListMetadataDao; +import org.tasks.injection.ApplicationContext; import org.tasks.preferences.Preferences; import timber.log.Timber; @@ -32,7 +32,7 @@ public class SubtasksHelper { @Inject public SubtasksHelper( - Application context, + @ApplicationContext Context context, Preferences preferences, TaskDao taskDao, TagDataDao tagDataDao, diff --git a/app/src/main/java/com/todoroo/astrid/timers/TimerControlSet.kt b/app/src/main/java/com/todoroo/astrid/timers/TimerControlSet.kt index b90abc872..09bd68789 100644 --- a/app/src/main/java/com/todoroo/astrid/timers/TimerControlSet.kt +++ b/app/src/main/java/com/todoroo/astrid/timers/TimerControlSet.kt @@ -27,6 +27,7 @@ import com.todoroo.astrid.ui.TimeDurationControlSet import org.tasks.R import org.tasks.Strings.isNullOrEmpty import org.tasks.dialogs.DialogBuilder +import org.tasks.injection.ActivityContext import org.tasks.injection.FragmentComponent import org.tasks.themes.Theme import org.tasks.ui.TaskEditControlFragment @@ -38,7 +39,7 @@ import javax.inject.Inject * @author Tim Su @todoroo.com> */ class TimerControlSet : TaskEditControlFragment() { - @Inject lateinit var activity: Activity + @Inject @ActivityContext lateinit var activity: Context @Inject lateinit var dialogBuilder: DialogBuilder @Inject lateinit var theme: Theme diff --git a/app/src/main/java/com/todoroo/astrid/timers/TimerPlugin.java b/app/src/main/java/com/todoroo/astrid/timers/TimerPlugin.java index c41c5e22f..b0c235293 100644 --- a/app/src/main/java/com/todoroo/astrid/timers/TimerPlugin.java +++ b/app/src/main/java/com/todoroo/astrid/timers/TimerPlugin.java @@ -8,7 +8,6 @@ package com.todoroo.astrid.timers; import static org.tasks.time.DateTimeUtils.currentTimeMillis; -import android.app.Application; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; @@ -25,6 +24,7 @@ import io.reactivex.Completable; import io.reactivex.schedulers.Schedulers; import javax.inject.Inject; import org.tasks.R; +import org.tasks.injection.ApplicationContext; import org.tasks.intents.TaskIntents; import org.tasks.notifications.NotificationManager; @@ -36,7 +36,7 @@ public class TimerPlugin { @Inject public TimerPlugin( - Application context, + @ApplicationContext Context context, NotificationManager notificationManager, TaskDao taskDao) { this.context = context; diff --git a/app/src/main/java/com/todoroo/astrid/ui/HideUntilControlSet.kt b/app/src/main/java/com/todoroo/astrid/ui/HideUntilControlSet.kt index 6acbbcb46..6e5ea2115 100644 --- a/app/src/main/java/com/todoroo/astrid/ui/HideUntilControlSet.kt +++ b/app/src/main/java/com/todoroo/astrid/ui/HideUntilControlSet.kt @@ -22,6 +22,7 @@ import org.tasks.R import org.tasks.activities.DateAndTimePickerActivity import org.tasks.date.DateTimeUtils import org.tasks.dialogs.MyTimePickerDialog +import org.tasks.injection.ActivityContext import org.tasks.injection.FragmentComponent import org.tasks.locale.Locale import org.tasks.preferences.Preferences @@ -39,7 +40,7 @@ import javax.inject.Inject class HideUntilControlSet : TaskEditControlFragment(), OnItemSelectedListener { private val spinnerItems: MutableList = ArrayList() - @Inject lateinit var activity: Activity + @Inject @ActivityContext lateinit var activity: Context @Inject lateinit var themeBase: ThemeBase @Inject lateinit var preferences: Preferences @Inject lateinit var locale: Locale diff --git a/app/src/main/java/com/todoroo/astrid/ui/ReminderControlSet.kt b/app/src/main/java/com/todoroo/astrid/ui/ReminderControlSet.kt index 217577826..6fc7989cf 100644 --- a/app/src/main/java/com/todoroo/astrid/ui/ReminderControlSet.kt +++ b/app/src/main/java/com/todoroo/astrid/ui/ReminderControlSet.kt @@ -28,6 +28,7 @@ import org.tasks.data.Alarm import org.tasks.date.DateTimeUtils import org.tasks.dialogs.DialogBuilder import org.tasks.dialogs.MyTimePickerDialog +import org.tasks.injection.ActivityContext import org.tasks.injection.FragmentComponent import org.tasks.locale.Locale import org.tasks.ui.TaskEditControlFragment @@ -43,7 +44,7 @@ import javax.inject.Inject class ReminderControlSet : TaskEditControlFragment() { private val alarms: MutableSet = LinkedHashSet() - @Inject lateinit var activity: Activity + @Inject @ActivityContext lateinit var activity: Context @Inject lateinit var alarmService: AlarmService @Inject lateinit var locale: Locale @Inject lateinit var dialogBuilder: DialogBuilder diff --git a/app/src/main/java/com/todoroo/astrid/voice/VoiceOutputAssistant.java b/app/src/main/java/com/todoroo/astrid/voice/VoiceOutputAssistant.java index 9b0bdfec1..c50a1627f 100644 --- a/app/src/main/java/com/todoroo/astrid/voice/VoiceOutputAssistant.java +++ b/app/src/main/java/com/todoroo/astrid/voice/VoiceOutputAssistant.java @@ -1,6 +1,5 @@ package com.todoroo.astrid.voice; -import android.app.Application; import android.content.Context; import android.media.AudioManager; import android.speech.tts.TextToSpeech; @@ -9,6 +8,7 @@ import java.util.HashMap; import java.util.Locale; import java.util.UUID; import javax.inject.Inject; +import org.tasks.injection.ApplicationContext; import timber.log.Timber; /** @author Arne Jans */ @@ -21,7 +21,7 @@ public class VoiceOutputAssistant implements OnInitListener { private String lastTextToSpeak; @Inject - public VoiceOutputAssistant(Application context) { + public VoiceOutputAssistant(@ApplicationContext Context context) { this.context = context; } diff --git a/app/src/main/java/org/tasks/LocalBroadcastManager.java b/app/src/main/java/org/tasks/LocalBroadcastManager.java index 930724948..5f849e3e8 100644 --- a/app/src/main/java/org/tasks/LocalBroadcastManager.java +++ b/app/src/main/java/org/tasks/LocalBroadcastManager.java @@ -1,11 +1,12 @@ package org.tasks; -import android.app.Application; import android.content.BroadcastReceiver; +import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import com.todoroo.astrid.api.AstridApiConstants; import javax.inject.Inject; +import org.tasks.injection.ApplicationContext; import org.tasks.widget.AppWidgetManager; public class LocalBroadcastManager { @@ -19,7 +20,7 @@ public class LocalBroadcastManager { private final AppWidgetManager appWidgetManager; @Inject - public LocalBroadcastManager(Application context, AppWidgetManager appWidgetManager) { + public LocalBroadcastManager(@ApplicationContext Context context, AppWidgetManager appWidgetManager) { this.appWidgetManager = appWidgetManager; localBroadcastManager = androidx.localbroadcastmanager.content.LocalBroadcastManager.getInstance(context); diff --git a/app/src/main/java/org/tasks/Notifier.kt b/app/src/main/java/org/tasks/Notifier.kt index 520521f4c..880445703 100644 --- a/app/src/main/java/org/tasks/Notifier.kt +++ b/app/src/main/java/org/tasks/Notifier.kt @@ -1,7 +1,7 @@ package org.tasks -import android.app.Application import android.app.PendingIntent +import android.content.Context import android.content.Intent import androidx.core.app.NotificationCompat import com.todoroo.andlib.utility.AndroidUtilities @@ -10,6 +10,7 @@ import com.todoroo.astrid.api.Filter import com.todoroo.astrid.dao.TaskDao import com.todoroo.astrid.reminders.ReminderService import com.todoroo.astrid.voice.VoiceOutputAssistant +import org.tasks.injection.ApplicationContext import org.tasks.notifications.AudioManager import org.tasks.notifications.Notification import org.tasks.notifications.NotificationManager @@ -23,7 +24,7 @@ import javax.inject.Inject import kotlin.math.min class Notifier @Inject constructor( - private val context: Application, + @param:ApplicationContext private val context: Context, private val taskDao: TaskDao, private val notificationManager: NotificationManager, private val telephonyManager: TelephonyManager, diff --git a/app/src/main/java/org/tasks/ShortcutManager.kt b/app/src/main/java/org/tasks/ShortcutManager.kt index 5bccf1e03..5c9589e2f 100644 --- a/app/src/main/java/org/tasks/ShortcutManager.kt +++ b/app/src/main/java/org/tasks/ShortcutManager.kt @@ -1,13 +1,14 @@ package org.tasks -import android.app.Application +import android.content.Context import android.content.pm.ShortcutManager import com.todoroo.andlib.utility.AndroidUtilities import org.tasks.injection.ApplicationScope +import org.tasks.injection.ApplicationContext import javax.inject.Inject @ApplicationScope -class ShortcutManager @Inject constructor(context: Application) { +class ShortcutManager @Inject constructor(@ApplicationContext context: Context) { private val shortcutManager: ShortcutManager? = if (AndroidUtilities.atLeastNougatMR1()) { context.getSystemService(ShortcutManager::class.java) } else { diff --git a/app/src/main/java/org/tasks/Tasks.kt b/app/src/main/java/org/tasks/Tasks.kt index 2fcda21d9..630398896 100644 --- a/app/src/main/java/org/tasks/Tasks.kt +++ b/app/src/main/java/org/tasks/Tasks.kt @@ -1,6 +1,5 @@ package org.tasks -import android.app.Application import android.content.BroadcastReceiver import android.content.Context import android.content.Intent @@ -15,6 +14,7 @@ import org.tasks.billing.BillingClient import org.tasks.billing.Inventory import org.tasks.files.FileHelper import org.tasks.injection.ApplicationComponent +import org.tasks.injection.ApplicationContext import org.tasks.injection.InjectingApplication import org.tasks.injection.InjectingJobIntentService import org.tasks.jobs.WorkManager @@ -30,6 +30,7 @@ import timber.log.Timber import javax.inject.Inject class Tasks : InjectingApplication(), Configuration.Provider { + @Inject @ApplicationContext lateinit var context: Context @Inject lateinit var preferences: Preferences @Inject lateinit var buildSetup: BuildSetup @Inject lateinit var inventory: Inventory @@ -64,15 +65,15 @@ class Tasks : InjectingApplication(), Configuration.Provider { } private fun doInBackground() { - NotificationSchedulerIntentService.enqueueWork(this, false) - CalendarNotificationIntentService.enqueueWork(this) + NotificationSchedulerIntentService.enqueueWork(context, false) + CalendarNotificationIntentService.enqueueWork(context) refreshScheduler.get().scheduleAll() workManager.get().updateBackgroundSync() workManager.get().scheduleMidnightRefresh() workManager.get().scheduleBackup() workManager.get().scheduleConfigRefresh() geofenceApi.get().registerAll() - FileHelper.delete(this, preferences.cacheDirectory) + FileHelper.delete(context, preferences.cacheDirectory) billingClient.get().queryPurchases() appWidgetManager.get().reconfigureWidgets() } diff --git a/app/src/main/java/org/tasks/activities/FilterSelectionActivity.java b/app/src/main/java/org/tasks/activities/FilterSelectionActivity.java index 8c4d1a38a..59140f733 100644 --- a/app/src/main/java/org/tasks/activities/FilterSelectionActivity.java +++ b/app/src/main/java/org/tasks/activities/FilterSelectionActivity.java @@ -1,6 +1,5 @@ package org.tasks.activities; -import android.app.Application; import android.appwidget.AppWidgetManager; import android.content.BroadcastReceiver; import android.content.Context; @@ -18,6 +17,7 @@ import org.tasks.LocalBroadcastManager; import org.tasks.dialogs.DialogBuilder; import org.tasks.filters.FilterProvider; import org.tasks.injection.ActivityComponent; +import org.tasks.injection.ApplicationContext; import org.tasks.injection.InjectingAppCompatActivity; import org.tasks.preferences.DefaultFilterProvider; import org.tasks.preferences.Preferences; @@ -31,7 +31,7 @@ public class FilterSelectionActivity extends InjectingAppCompatActivity { private static final String EXTRA_FILTER_SQL = "extra_filter_query"; private static final String EXTRA_FILTER_VALUES = "extra_filter_values"; - @Inject Application context; + @Inject @ApplicationContext Context context; @Inject DialogBuilder dialogBuilder; @Inject FilterAdapter filterAdapter; @Inject FilterProvider filterProvider; diff --git a/app/src/main/java/org/tasks/activities/GoogleTaskListSettingsActivity.java b/app/src/main/java/org/tasks/activities/GoogleTaskListSettingsActivity.java index ed07d41a5..dfc50b750 100644 --- a/app/src/main/java/org/tasks/activities/GoogleTaskListSettingsActivity.java +++ b/app/src/main/java/org/tasks/activities/GoogleTaskListSettingsActivity.java @@ -2,7 +2,6 @@ package org.tasks.activities; import static org.tasks.Strings.isNullOrEmpty; -import android.app.Application; import android.content.Context; import android.content.Intent; import android.os.Bundle; @@ -26,13 +25,14 @@ import org.tasks.data.GoogleTaskAccount; import org.tasks.data.GoogleTaskList; import org.tasks.data.GoogleTaskListDao; import org.tasks.injection.ActivityComponent; +import org.tasks.injection.ApplicationContext; import timber.log.Timber; public class GoogleTaskListSettingsActivity extends BaseListSettingsActivity { public static final String EXTRA_ACCOUNT = "extra_account"; public static final String EXTRA_STORE_DATA = "extra_store_data"; - @Inject Application context; + @Inject @ApplicationContext Context context; @Inject GoogleTaskListDao googleTaskListDao; @Inject GtasksListService gtasksListService; @Inject TaskDeleter taskDeleter; diff --git a/app/src/main/java/org/tasks/caldav/CaldavClient.java b/app/src/main/java/org/tasks/caldav/CaldavClient.java index 219706faa..4f9cbbc57 100644 --- a/app/src/main/java/org/tasks/caldav/CaldavClient.java +++ b/app/src/main/java/org/tasks/caldav/CaldavClient.java @@ -5,7 +5,6 @@ import static at.bitfire.dav4jvm.XmlUtils.NS_CARDDAV; import static at.bitfire.dav4jvm.XmlUtils.NS_WEBDAV; import static org.tasks.Strings.isNullOrEmpty; -import android.app.Application; import android.content.Context; import at.bitfire.cert4android.CustomCertManager; import at.bitfire.cert4android.CustomCertManager.CustomHostnameVerifier; @@ -44,6 +43,7 @@ import org.tasks.DebugNetworkInterceptor; import org.tasks.R; import org.tasks.data.CaldavAccount; import org.tasks.data.CaldavCalendar; +import org.tasks.injection.ApplicationContext; import org.tasks.preferences.Preferences; import org.tasks.security.KeyStoreEncryption; import org.tasks.ui.DisplayableException; @@ -65,7 +65,7 @@ public class CaldavClient { @Inject CaldavClient( - Application context, + @ApplicationContext Context context, KeyStoreEncryption encryption, Preferences preferences, DebugNetworkInterceptor interceptor) { diff --git a/app/src/main/java/org/tasks/caldav/CaldavSynchronizer.java b/app/src/main/java/org/tasks/caldav/CaldavSynchronizer.java index f6500136e..3d4bf7626 100644 --- a/app/src/main/java/org/tasks/caldav/CaldavSynchronizer.java +++ b/app/src/main/java/org/tasks/caldav/CaldavSynchronizer.java @@ -9,7 +9,6 @@ import static com.google.common.collect.Sets.newHashSet; import static org.tasks.Strings.isNullOrEmpty; import static org.tasks.time.DateTimeUtils.currentTimeMillis; -import android.app.Application; import android.content.Context; import androidx.annotation.Nullable; import at.bitfire.dav4jvm.DavCalendar; @@ -56,6 +55,7 @@ import org.tasks.data.CaldavAccount; import org.tasks.data.CaldavCalendar; import org.tasks.data.CaldavDao; import org.tasks.data.CaldavTask; +import org.tasks.injection.ApplicationContext; import timber.log.Timber; public class CaldavSynchronizer { @@ -77,7 +77,7 @@ public class CaldavSynchronizer { @Inject public CaldavSynchronizer( - Application context, + @ApplicationContext Context context, CaldavDao caldavDao, TaskDao taskDao, LocalBroadcastManager localBroadcastManager, diff --git a/app/src/main/java/org/tasks/calendars/CalendarEventAttendeeProvider.java b/app/src/main/java/org/tasks/calendars/CalendarEventAttendeeProvider.java index 331cf11c6..27ab41253 100644 --- a/app/src/main/java/org/tasks/calendars/CalendarEventAttendeeProvider.java +++ b/app/src/main/java/org/tasks/calendars/CalendarEventAttendeeProvider.java @@ -1,13 +1,14 @@ package org.tasks.calendars; -import android.app.Application; import android.content.ContentResolver; +import android.content.Context; import android.database.Cursor; import android.provider.CalendarContract; import java.util.ArrayList; import java.util.Collections; import java.util.List; import javax.inject.Inject; +import org.tasks.injection.ApplicationContext; import org.tasks.preferences.PermissionChecker; import timber.log.Timber; @@ -22,7 +23,7 @@ class CalendarEventAttendeeProvider { @Inject public CalendarEventAttendeeProvider( - Application context, PermissionChecker permissionChecker) { + @ApplicationContext Context context, PermissionChecker permissionChecker) { this.permissionChecker = permissionChecker; contentResolver = context.getContentResolver(); } diff --git a/app/src/main/java/org/tasks/calendars/CalendarEventProvider.java b/app/src/main/java/org/tasks/calendars/CalendarEventProvider.java index 69759fe45..b355efb6e 100644 --- a/app/src/main/java/org/tasks/calendars/CalendarEventProvider.java +++ b/app/src/main/java/org/tasks/calendars/CalendarEventProvider.java @@ -3,8 +3,8 @@ package org.tasks.calendars; import static android.provider.BaseColumns._ID; import static org.tasks.Strings.isNullOrEmpty; -import android.app.Application; import android.content.ContentResolver; +import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.provider.CalendarContract; @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import javax.inject.Inject; +import org.tasks.injection.ApplicationContext; import org.tasks.preferences.PermissionChecker; import timber.log.Timber; @@ -33,7 +34,7 @@ public class CalendarEventProvider { @Inject public CalendarEventProvider( - Application context, + @ApplicationContext Context context, PermissionChecker permissionChecker, CalendarEventAttendeeProvider calendarEventAttendeeProvider) { this.permissionChecker = permissionChecker; diff --git a/app/src/main/java/org/tasks/calendars/CalendarProvider.java b/app/src/main/java/org/tasks/calendars/CalendarProvider.java index 2bed3f95a..1372f073b 100644 --- a/app/src/main/java/org/tasks/calendars/CalendarProvider.java +++ b/app/src/main/java/org/tasks/calendars/CalendarProvider.java @@ -3,8 +3,8 @@ package org.tasks.calendars; import static android.provider.BaseColumns._ID; import static org.tasks.Strings.isNullOrEmpty; -import android.app.Application; import android.content.ContentResolver; +import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.provider.CalendarContract; @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import javax.inject.Inject; +import org.tasks.injection.ApplicationContext; import org.tasks.preferences.PermissionChecker; import timber.log.Timber; @@ -31,7 +32,7 @@ public class CalendarProvider { private final ContentResolver contentResolver; @Inject - public CalendarProvider(Application context, PermissionChecker permissionChecker) { + public CalendarProvider(@ApplicationContext Context context, PermissionChecker permissionChecker) { this.permissionChecker = permissionChecker; contentResolver = context.getContentResolver(); } diff --git a/app/src/main/java/org/tasks/dialogs/AddAttachmentDialog.java b/app/src/main/java/org/tasks/dialogs/AddAttachmentDialog.java index 4364cd2ef..744f5022d 100644 --- a/app/src/main/java/org/tasks/dialogs/AddAttachmentDialog.java +++ b/app/src/main/java/org/tasks/dialogs/AddAttachmentDialog.java @@ -3,8 +3,8 @@ package org.tasks.dialogs; import static org.tasks.dialogs.RecordAudioDialog.newRecordAudioDialog; import static org.tasks.files.FileHelper.newFilePickerIntent; -import android.app.Activity; import android.app.Dialog; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.provider.MediaStore.Images.Media; @@ -16,6 +16,7 @@ import javax.inject.Inject; import org.tasks.R; import org.tasks.activities.CameraActivity; import org.tasks.injection.DialogFragmentComponent; +import org.tasks.injection.ActivityContext; import org.tasks.injection.InjectingDialogFragment; import org.tasks.preferences.Device; @@ -26,7 +27,7 @@ public class AddAttachmentDialog extends InjectingDialogFragment { public static final int REQUEST_STORAGE = 12122; public static final int REQUEST_AUDIO = 12123; private static final String FRAG_TAG_RECORD_AUDIO = "frag_tag_record_audio"; - @Inject Activity context; + @Inject @ActivityContext Context context; @Inject DialogBuilder dialogBuilder; @Inject Device device; diff --git a/app/src/main/java/org/tasks/dialogs/GeofenceDialog.java b/app/src/main/java/org/tasks/dialogs/GeofenceDialog.java index a7268bb90..494e35eb0 100644 --- a/app/src/main/java/org/tasks/dialogs/GeofenceDialog.java +++ b/app/src/main/java/org/tasks/dialogs/GeofenceDialog.java @@ -2,8 +2,8 @@ package org.tasks.dialogs; import static android.app.Activity.RESULT_OK; -import android.app.Activity; import android.app.Dialog; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; @@ -21,6 +21,7 @@ import org.tasks.R; import org.tasks.data.Geofence; import org.tasks.data.Location; import org.tasks.injection.DialogFragmentComponent; +import org.tasks.injection.ActivityContext; import org.tasks.injection.InjectingDialogFragment; import org.tasks.locale.Locale; import org.tasks.preferences.PermissionChecker; @@ -34,7 +35,7 @@ public class GeofenceDialog extends InjectingDialogFragment { private static final int MAX_RADIUS = 1000; @Inject DialogBuilder dialogBuilder; - @Inject Activity context; + @Inject @ActivityContext Context context; @Inject Locale locale; @Inject PermissionChecker permissionChecker; @Inject Toaster toaster; diff --git a/app/src/main/java/org/tasks/dialogs/IconPickerDialog.java b/app/src/main/java/org/tasks/dialogs/IconPickerDialog.java index 245a686b4..5aa658b07 100644 --- a/app/src/main/java/org/tasks/dialogs/IconPickerDialog.java +++ b/app/src/main/java/org/tasks/dialogs/IconPickerDialog.java @@ -2,6 +2,7 @@ package org.tasks.dialogs; import android.app.Activity; import android.app.Dialog; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; @@ -17,6 +18,7 @@ import org.tasks.R; import org.tasks.billing.Inventory; import org.tasks.billing.PurchaseActivity; import org.tasks.injection.DialogFragmentComponent; +import org.tasks.injection.ActivityContext; import org.tasks.injection.InjectingDialogFragment; import org.tasks.themes.CustomIcons; @@ -28,7 +30,7 @@ public class IconPickerDialog extends InjectingDialogFragment { RecyclerView recyclerView; @Inject DialogBuilder dialogBuilder; - @Inject Activity context; + @Inject @ActivityContext Context context; @Inject Inventory inventory; private IconPickerCallback callback; diff --git a/app/src/main/java/org/tasks/dialogs/ImportTasksDialog.java b/app/src/main/java/org/tasks/dialogs/ImportTasksDialog.java index 7bec241e0..daf8d207b 100644 --- a/app/src/main/java/org/tasks/dialogs/ImportTasksDialog.java +++ b/app/src/main/java/org/tasks/dialogs/ImportTasksDialog.java @@ -3,6 +3,7 @@ package org.tasks.dialogs; import android.app.Activity; import android.app.Dialog; import android.app.ProgressDialog; +import android.content.Context; import android.content.res.Resources; import android.net.Uri; import android.os.Bundle; @@ -14,6 +15,7 @@ import org.tasks.R; import org.tasks.backup.TasksJsonImporter; import org.tasks.backup.TasksJsonImporter.ImportResult; import org.tasks.injection.DialogFragmentComponent; +import org.tasks.injection.ActivityContext; import org.tasks.injection.InjectingDialogFragment; import org.tasks.ui.Toaster; @@ -25,7 +27,7 @@ public class ImportTasksDialog extends InjectingDialogFragment { @Inject TasksXmlImporter xmlImporter; @Inject TasksJsonImporter jsonImporter; @Inject DialogBuilder dialogBuilder; - @Inject Activity context; + @Inject @ActivityContext Context context; @Inject Toaster toaster; public static ImportTasksDialog newImportTasksDialog(Uri data, String extension) { diff --git a/app/src/main/java/org/tasks/dialogs/Linkify.java b/app/src/main/java/org/tasks/dialogs/Linkify.java index 8e3b36e0e..84749ca15 100644 --- a/app/src/main/java/org/tasks/dialogs/Linkify.java +++ b/app/src/main/java/org/tasks/dialogs/Linkify.java @@ -3,7 +3,6 @@ package org.tasks.dialogs; import static java.util.Arrays.asList; import static org.tasks.Strings.isNullOrEmpty; -import android.app.Activity; import android.content.Context; import android.content.Intent; import android.net.Uri; @@ -17,6 +16,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import javax.inject.Inject; import org.tasks.R; +import org.tasks.injection.ActivityContext; public class Linkify { @@ -24,7 +24,7 @@ public class Linkify { private final DialogBuilder dialogBuilder; @Inject - public Linkify(Activity context, DialogBuilder dialogBuilder) { + public Linkify(@ActivityContext Context context, DialogBuilder dialogBuilder) { this.context = context; this.dialogBuilder = dialogBuilder; } diff --git a/app/src/main/java/org/tasks/drive/DriveInvoker.java b/app/src/main/java/org/tasks/drive/DriveInvoker.java index 6677b8f01..83c2621b7 100644 --- a/app/src/main/java/org/tasks/drive/DriveInvoker.java +++ b/app/src/main/java/org/tasks/drive/DriveInvoker.java @@ -2,7 +2,6 @@ package org.tasks.drive; import static com.todoroo.andlib.utility.DateUtilities.now; -import android.app.Application; import android.content.Context; import android.net.Uri; import com.google.api.client.http.HttpResponse; @@ -24,6 +23,7 @@ import org.tasks.BuildConfig; import org.tasks.DebugNetworkInterceptor; import org.tasks.R; import org.tasks.files.FileHelper; +import org.tasks.injection.ApplicationContext; import org.tasks.preferences.Preferences; import timber.log.Timber; @@ -39,7 +39,7 @@ public class DriveInvoker { @Inject public DriveInvoker( - Application context, + @ApplicationContext Context context, Preferences preferences, HttpCredentialsAdapter credentialsAdapter, DebugNetworkInterceptor interceptor) { diff --git a/app/src/main/java/org/tasks/etesync/EteSyncClient.java b/app/src/main/java/org/tasks/etesync/EteSyncClient.java index 6e8ceefcd..1f660a5a6 100644 --- a/app/src/main/java/org/tasks/etesync/EteSyncClient.java +++ b/app/src/main/java/org/tasks/etesync/EteSyncClient.java @@ -3,7 +3,6 @@ package org.tasks.etesync; import static com.google.common.collect.Lists.partition; import static com.google.common.collect.Lists.transform; -import android.app.Application; import android.content.Context; import androidx.annotation.Nullable; import androidx.core.util.Pair; @@ -45,6 +44,7 @@ import org.tasks.DebugNetworkInterceptor; import org.tasks.caldav.MemoryCookieStore; import org.tasks.data.CaldavAccount; import org.tasks.data.CaldavCalendar; +import org.tasks.injection.ApplicationContext; import org.tasks.preferences.Preferences; import org.tasks.security.KeyStoreEncryption; import timber.log.Timber; @@ -69,7 +69,7 @@ public class EteSyncClient { @Inject public EteSyncClient( - Application context, + @ApplicationContext Context context, KeyStoreEncryption encryption, Preferences preferences, DebugNetworkInterceptor interceptor) { diff --git a/app/src/main/java/org/tasks/etesync/EteSynchronizer.java b/app/src/main/java/org/tasks/etesync/EteSynchronizer.java index dbd919f38..99ff38f74 100644 --- a/app/src/main/java/org/tasks/etesync/EteSynchronizer.java +++ b/app/src/main/java/org/tasks/etesync/EteSynchronizer.java @@ -6,7 +6,6 @@ import static com.google.common.collect.Sets.newHashSet; import static java.util.Collections.emptySet; import static org.tasks.Strings.isNullOrEmpty; -import android.app.Application; import android.content.Context; import androidx.core.util.Pair; import at.bitfire.ical4android.ICalendar; @@ -43,6 +42,7 @@ import org.tasks.data.CaldavCalendar; import org.tasks.data.CaldavDao; import org.tasks.data.CaldavTask; import org.tasks.data.CaldavTaskContainer; +import org.tasks.injection.ApplicationContext; import timber.log.Timber; public class EteSynchronizer { @@ -62,7 +62,7 @@ public class EteSynchronizer { @Inject public EteSynchronizer( - Application context, + @ApplicationContext Context context, CaldavDao caldavDao, LocalBroadcastManager localBroadcastManager, TaskDeleter taskDeleter, diff --git a/app/src/main/java/org/tasks/filters/FilterCriteriaProvider.java b/app/src/main/java/org/tasks/filters/FilterCriteriaProvider.java index fe5e1f514..6d19a05ed 100644 --- a/app/src/main/java/org/tasks/filters/FilterCriteriaProvider.java +++ b/app/src/main/java/org/tasks/filters/FilterCriteriaProvider.java @@ -3,7 +3,6 @@ package org.tasks.filters; import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Sets.newLinkedHashSet; -import android.app.Application; import android.content.Context; import android.content.res.Resources; import com.todoroo.andlib.sql.Criterion; @@ -32,6 +31,7 @@ import org.tasks.data.GoogleTaskListDao; import org.tasks.data.Tag; import org.tasks.data.TagData; import org.tasks.data.TagDataDao; +import org.tasks.injection.ApplicationContext; public class FilterCriteriaProvider { @@ -52,7 +52,7 @@ public class FilterCriteriaProvider { @Inject public FilterCriteriaProvider( - Application context, + @ApplicationContext Context context, TagDataDao tagDataDao, GoogleTaskListDao googleTaskListDao, CaldavDao caldavDao) { diff --git a/app/src/main/java/org/tasks/filters/FilterProvider.kt b/app/src/main/java/org/tasks/filters/FilterProvider.kt index c104455eb..060fed1f3 100644 --- a/app/src/main/java/org/tasks/filters/FilterProvider.kt +++ b/app/src/main/java/org/tasks/filters/FilterProvider.kt @@ -1,6 +1,5 @@ package org.tasks.filters -import android.app.Application import android.content.Context import android.content.Intent import com.todoroo.andlib.utility.AndroidUtilities.assertNotMainThread @@ -19,6 +18,7 @@ import org.tasks.caldav.BaseCaldavCalendarSettingsActivity import org.tasks.data.* import org.tasks.data.CaldavAccount.Companion.TYPE_LOCAL import org.tasks.filters.NavigationDrawerSubheader.SubheaderType +import org.tasks.injection.ApplicationContext import org.tasks.location.LocationPickerActivity import org.tasks.preferences.HelpAndFeedback import org.tasks.preferences.MainPreferences @@ -27,7 +27,7 @@ import org.tasks.ui.NavigationDrawerFragment import javax.inject.Inject class FilterProvider @Inject constructor( - private val context: Application, + @param:ApplicationContext private val context: Context, private val inventory: Inventory, private val builtInFilterExposer: BuiltInFilterExposer, private val filterDao: FilterDao, diff --git a/app/src/main/java/org/tasks/fragments/TaskEditControlSetFragmentManager.java b/app/src/main/java/org/tasks/fragments/TaskEditControlSetFragmentManager.java index 4306be22c..82136cc26 100644 --- a/app/src/main/java/org/tasks/fragments/TaskEditControlSetFragmentManager.java +++ b/app/src/main/java/org/tasks/fragments/TaskEditControlSetFragmentManager.java @@ -1,6 +1,6 @@ package org.tasks.fragments; -import android.app.Activity; +import android.content.Context; import android.os.Bundle; import androidx.fragment.app.FragmentManager; import com.todoroo.astrid.activity.BeastModePreferences; @@ -19,13 +19,14 @@ import java.util.Map; import javax.inject.Inject; import org.tasks.BuildConfig; import org.tasks.R; +import org.tasks.injection.ActivityContext; import org.tasks.preferences.Preferences; import org.tasks.ui.CalendarControlSet; import org.tasks.ui.DeadlineControlSet; import org.tasks.ui.DescriptionControlSet; -import org.tasks.ui.ListFragment; import org.tasks.ui.LocationControlSet; import org.tasks.ui.PriorityControlSet; +import org.tasks.ui.ListFragment; import org.tasks.ui.SubtaskControlSet; import org.tasks.ui.TaskEditControlFragment; @@ -80,7 +81,7 @@ public class TaskEditControlSetFragmentManager { private int numRows; @Inject - public TaskEditControlSetFragmentManager(Activity context, Preferences preferences) { + public TaskEditControlSetFragmentManager(@ActivityContext Context context, Preferences preferences) { displayOrder = BeastModePreferences.constructOrderedControlList(preferences, context); displayOrder.add(0, context.getString(CommentBarFragment.TAG)); String hideAlwaysTrigger = context.getString(R.string.TEA_ctrl_hide_section_pref); diff --git a/app/src/main/java/org/tasks/gtasks/GoogleAccountManager.java b/app/src/main/java/org/tasks/gtasks/GoogleAccountManager.java index d2d5f2d14..106805b47 100644 --- a/app/src/main/java/org/tasks/gtasks/GoogleAccountManager.java +++ b/app/src/main/java/org/tasks/gtasks/GoogleAccountManager.java @@ -12,7 +12,7 @@ import android.accounts.AuthenticatorException; import android.accounts.OperationCanceledException; import android.annotation.SuppressLint; import android.app.Activity; -import android.app.Application; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import com.google.api.services.drive.DriveScopes; @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.List; import javax.inject.Inject; import org.tasks.R; +import org.tasks.injection.ApplicationContext; import org.tasks.play.AuthResultHandler; import org.tasks.preferences.PermissionChecker; import org.tasks.preferences.Preferences; @@ -38,7 +39,7 @@ public class GoogleAccountManager { @Inject public GoogleAccountManager( - Application context, PermissionChecker permissionChecker, Preferences preferences) { + @ApplicationContext Context context, PermissionChecker permissionChecker, Preferences preferences) { this.permissionChecker = permissionChecker; accountManager = android.accounts.AccountManager.get(context); this.preferences = preferences; diff --git a/app/src/main/java/org/tasks/gtasks/GoogleTaskSynchronizer.java b/app/src/main/java/org/tasks/gtasks/GoogleTaskSynchronizer.java index 7fb6b4963..9ca59b3d4 100644 --- a/app/src/main/java/org/tasks/gtasks/GoogleTaskSynchronizer.java +++ b/app/src/main/java/org/tasks/gtasks/GoogleTaskSynchronizer.java @@ -4,7 +4,6 @@ import static com.google.common.collect.Lists.transform; import static org.tasks.Strings.isNullOrEmpty; import static org.tasks.date.DateTimeUtils.newDateTime; -import android.app.Application; import android.content.Context; import androidx.annotation.Nullable; import com.google.api.client.googleapis.json.GoogleJsonResponseException; @@ -43,6 +42,7 @@ import org.tasks.data.GoogleTaskAccount; import org.tasks.data.GoogleTaskDao; import org.tasks.data.GoogleTaskList; import org.tasks.data.GoogleTaskListDao; +import org.tasks.injection.ApplicationContext; import org.tasks.preferences.DefaultFilterProvider; import org.tasks.preferences.PermissionChecker; import org.tasks.preferences.Preferences; @@ -82,7 +82,7 @@ public class GoogleTaskSynchronizer { @Inject public GoogleTaskSynchronizer( - Application context, + @ApplicationContext Context context, GoogleTaskListDao googleTaskListDao, GtasksListService gtasksListService, Preferences preferences, diff --git a/app/src/main/java/org/tasks/injection/ActivityContext.kt b/app/src/main/java/org/tasks/injection/ActivityContext.kt new file mode 100644 index 000000000..5fd36dec2 --- /dev/null +++ b/app/src/main/java/org/tasks/injection/ActivityContext.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 ActivityContext \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/ActivityModule.kt b/app/src/main/java/org/tasks/injection/ActivityModule.kt index 508369856..bead7a18a 100644 --- a/app/src/main/java/org/tasks/injection/ActivityModule.kt +++ b/app/src/main/java/org/tasks/injection/ActivityModule.kt @@ -1,6 +1,7 @@ package org.tasks.injection import android.app.Activity +import android.content.Context import dagger.Module import dagger.Provides import org.tasks.R @@ -14,6 +15,11 @@ import org.tasks.themes.ThemeColor @Module class ActivityModule(@get:Provides val activity: Activity) { + @get:ActivityContext + @get:Provides + val activityContext: Context + get() = activity + @Provides @ActivityScope fun getThemeBase(preferences: Preferences, inventory: Inventory): ThemeBase diff --git a/app/src/main/java/org/tasks/injection/ApplicationContext.kt b/app/src/main/java/org/tasks/injection/ApplicationContext.kt new file mode 100644 index 000000000..48fb3192f --- /dev/null +++ b/app/src/main/java/org/tasks/injection/ApplicationContext.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 ApplicationContext \ No newline at end of file diff --git a/app/src/main/java/org/tasks/injection/ApplicationModule.kt b/app/src/main/java/org/tasks/injection/ApplicationModule.kt index 23effb856..5e319f5a7 100644 --- a/app/src/main/java/org/tasks/injection/ApplicationModule.kt +++ b/app/src/main/java/org/tasks/injection/ApplicationModule.kt @@ -1,6 +1,6 @@ package org.tasks.injection -import android.app.Application +import android.content.Context import com.todoroo.astrid.dao.Database import com.todoroo.astrid.dao.TaskDao import dagger.Module @@ -17,7 +17,7 @@ import org.tasks.location.MapboxGeocoder import org.tasks.notifications.NotificationDao @Module -class ApplicationModule(@get:Provides val context: Application) { +class ApplicationModule(@get:Provides @get:ApplicationContext val context: Context) { @get:Provides val locale: Locale diff --git a/app/src/main/java/org/tasks/injection/Dagger.kt b/app/src/main/java/org/tasks/injection/Dagger.kt index 0ae9e93f6..5a794afd1 100644 --- a/app/src/main/java/org/tasks/injection/Dagger.kt +++ b/app/src/main/java/org/tasks/injection/Dagger.kt @@ -1,23 +1,19 @@ package org.tasks.injection -import android.app.Application +import android.content.Context import org.tasks.locale.Locale +import timber.log.Timber -internal class Dagger private constructor(context: Application) { - val applicationComponent: ApplicationComponent = - DaggerApplicationComponent.builder() - .applicationModule(ApplicationModule(context)) - .productionModule(ProductionModule()) - .build() +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: Application): Dagger { + operator fun get(context: Context): Dagger { if (instance == null) { synchronized(lock) { if (instance == null) { - Locale.getInstance(context) instance = Dagger(context) } } @@ -25,4 +21,17 @@ internal class Dagger private constructor(context: Application) { 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/InjectingApplication.kt b/app/src/main/java/org/tasks/injection/InjectingApplication.kt index 049d660ca..d8c06cd86 100644 --- a/app/src/main/java/org/tasks/injection/InjectingApplication.kt +++ b/app/src/main/java/org/tasks/injection/InjectingApplication.kt @@ -1,13 +1,15 @@ 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() - component = Dagger.Companion[this].applicationComponent + val context = Locale.getInstance(this).createConfigurationContext(applicationContext) + component = Dagger.Companion[context].applicationComponent inject(component) } diff --git a/app/src/main/java/org/tasks/injection/InjectingContentProvider.kt b/app/src/main/java/org/tasks/injection/InjectingContentProvider.kt index e20996a4e..1ca22189e 100644 --- a/app/src/main/java/org/tasks/injection/InjectingContentProvider.kt +++ b/app/src/main/java/org/tasks/injection/InjectingContentProvider.kt @@ -1,13 +1,12 @@ package org.tasks.injection -import android.app.Application import android.content.ContentProvider abstract class InjectingContentProvider : ContentProvider() { override fun onCreate(): Boolean { inject( DaggerContentProviderComponent.builder() - .applicationModule(ApplicationModule(context!!.applicationContext as Application)) + .applicationModule(ApplicationModule(context!!.applicationContext)) .productionModule(ProductionModule()) .contentProviderModule(ContentProviderModule()) .build()) diff --git a/app/src/main/java/org/tasks/injection/ProductionModule.kt b/app/src/main/java/org/tasks/injection/ProductionModule.kt index 389d9275c..099c19488 100644 --- a/app/src/main/java/org/tasks/injection/ProductionModule.kt +++ b/app/src/main/java/org/tasks/injection/ProductionModule.kt @@ -1,6 +1,6 @@ package org.tasks.injection -import android.app.Application +import android.content.Context import androidx.room.Room import com.todoroo.astrid.dao.Database import dagger.Module @@ -12,7 +12,7 @@ import org.tasks.preferences.Preferences internal class ProductionModule { @Provides @ApplicationScope - fun getAppDatabase(context: Application): Database { + fun getAppDatabase(@ApplicationContext context: Context): Database { return Room.databaseBuilder(context, Database::class.java, Database.NAME) .allowMainThreadQueries() // TODO: remove me .addMigrations(*Migrations.MIGRATIONS) @@ -20,7 +20,7 @@ internal class ProductionModule { } @Provides - fun getPreferences(context: Application): Preferences { + fun getPreferences(@ApplicationContext context: Context): Preferences { return Preferences(context) } } \ No newline at end of file diff --git a/app/src/main/java/org/tasks/jobs/AfterSaveWork.java b/app/src/main/java/org/tasks/jobs/AfterSaveWork.java index 4ea4ba9ab..842bca228 100644 --- a/app/src/main/java/org/tasks/jobs/AfterSaveWork.java +++ b/app/src/main/java/org/tasks/jobs/AfterSaveWork.java @@ -3,7 +3,6 @@ package org.tasks.jobs; import static com.todoroo.astrid.dao.TaskDao.TRANS_SUPPRESS_REFRESH; import static org.tasks.Strings.isNullOrEmpty; -import android.app.Application; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; @@ -25,6 +24,7 @@ import org.tasks.LocalBroadcastManager; import org.tasks.R; import org.tasks.data.CaldavAccount; import org.tasks.data.CaldavDao; +import org.tasks.injection.ApplicationContext; import org.tasks.injection.InjectingWorker; import org.tasks.injection.JobComponent; import org.tasks.location.GeofenceApi; @@ -43,7 +43,7 @@ public class AfterSaveWork extends InjectingWorker { private static final String EXTRA_SUPPRESS_REFRESH = "extra_suppress_refresh"; @Inject RepeatTaskHelper repeatTaskHelper; - @Inject Application context; + @Inject @ApplicationContext Context context; @Inject NotificationManager notificationManager; @Inject GeofenceApi geofenceApi; @Inject TimerPlugin timerPlugin; diff --git a/app/src/main/java/org/tasks/jobs/BackupWork.java b/app/src/main/java/org/tasks/jobs/BackupWork.java index 18ebde776..ada98e498 100644 --- a/app/src/main/java/org/tasks/jobs/BackupWork.java +++ b/app/src/main/java/org/tasks/jobs/BackupWork.java @@ -6,7 +6,6 @@ import static com.google.common.collect.Lists.newArrayList; import static com.todoroo.andlib.utility.DateUtilities.now; import static java.util.Collections.emptyList; -import android.app.Application; import android.content.ContentResolver; import android.content.Context; import android.net.Uri; @@ -23,6 +22,7 @@ import java.util.List; import javax.inject.Inject; import org.tasks.R; import org.tasks.backup.TasksJsonExporter; +import org.tasks.injection.ApplicationContext; import org.tasks.injection.JobComponent; import org.tasks.preferences.Preferences; import timber.log.Timber; @@ -37,7 +37,7 @@ public class BackupWork extends RepeatingWorker { (f1, f2) -> Long.compare(f2.lastModified(), f1.lastModified()); private static final Comparator DOCUMENT_FILE_COMPARATOR = (d1, d2) -> Long.compare(d2.lastModified(), d1.lastModified()); - @Inject Application context; + @Inject @ApplicationContext Context context; @Inject TasksJsonExporter tasksJsonExporter; @Inject Preferences preferences; @Inject WorkManager workManager; diff --git a/app/src/main/java/org/tasks/jobs/DriveUploader.java b/app/src/main/java/org/tasks/jobs/DriveUploader.java index f4593c057..c1fb3481e 100644 --- a/app/src/main/java/org/tasks/jobs/DriveUploader.java +++ b/app/src/main/java/org/tasks/jobs/DriveUploader.java @@ -4,7 +4,6 @@ import static com.google.common.collect.Iterables.skip; import static com.google.common.collect.Lists.newArrayList; import static org.tasks.Strings.isNullOrEmpty; -import android.app.Application; import android.content.Context; import android.net.Uri; import androidx.annotation.NonNull; @@ -23,6 +22,7 @@ import javax.inject.Inject; import javax.net.ssl.SSLException; import org.tasks.R; import org.tasks.drive.DriveInvoker; +import org.tasks.injection.ApplicationContext; import org.tasks.injection.InjectingWorker; import org.tasks.injection.JobComponent; import org.tasks.preferences.Preferences; @@ -36,7 +36,7 @@ public class DriveUploader extends InjectingWorker { private static final Comparator DRIVE_FILE_COMPARATOR = (f1, f2) -> Long.compare(f2.getModifiedTime().getValue(), f1.getModifiedTime().getValue()); - @Inject Application context; + @Inject @ApplicationContext Context context; @Inject DriveInvoker drive; @Inject Preferences preferences; diff --git a/app/src/main/java/org/tasks/jobs/WorkManager.kt b/app/src/main/java/org/tasks/jobs/WorkManager.kt index 69beea025..7d0589877 100644 --- a/app/src/main/java/org/tasks/jobs/WorkManager.kt +++ b/app/src/main/java/org/tasks/jobs/WorkManager.kt @@ -2,7 +2,6 @@ package org.tasks.jobs import android.annotation.SuppressLint import android.app.AlarmManager -import android.app.Application import android.app.PendingIntent import android.content.Context import android.content.Intent @@ -24,6 +23,7 @@ import org.tasks.data.Place import org.tasks.date.DateTimeUtils.midnight import org.tasks.date.DateTimeUtils.newDateTime import org.tasks.injection.ApplicationScope +import org.tasks.injection.ApplicationContext import org.tasks.preferences.Preferences import org.tasks.time.DateTimeUtils import timber.log.Timber @@ -34,7 +34,7 @@ import kotlin.math.max @ApplicationScope class WorkManager @Inject constructor( - private val context: Application, + @param:ApplicationContext private val context: Context, private val preferences: Preferences, private val googleTaskListDao: GoogleTaskListDao, private val caldavDao: CaldavDao) { diff --git a/app/src/main/java/org/tasks/locale/receiver/TaskerIntentService.java b/app/src/main/java/org/tasks/locale/receiver/TaskerIntentService.java index 35a8a2200..5ddd10c57 100644 --- a/app/src/main/java/org/tasks/locale/receiver/TaskerIntentService.java +++ b/app/src/main/java/org/tasks/locale/receiver/TaskerIntentService.java @@ -1,12 +1,13 @@ package org.tasks.locale.receiver; -import android.app.Application; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import androidx.annotation.NonNull; import com.todoroo.astrid.api.Filter; import javax.inject.Inject; import org.tasks.Notifier; +import org.tasks.injection.ApplicationContext; import org.tasks.injection.InjectingJobIntentService; import org.tasks.injection.ServiceComponent; import org.tasks.locale.bundle.ListNotificationBundle; @@ -16,7 +17,7 @@ import timber.log.Timber; public class TaskerIntentService extends InjectingJobIntentService { - @Inject Application context; + @Inject @ApplicationContext Context context; @Inject Notifier notifier; @Inject DefaultFilterProvider defaultFilterProvider; @Inject TaskerTaskCreator taskerTaskCreator; diff --git a/app/src/main/java/org/tasks/notifications/AudioManager.java b/app/src/main/java/org/tasks/notifications/AudioManager.java index 17d4c1db8..acb1fc452 100644 --- a/app/src/main/java/org/tasks/notifications/AudioManager.java +++ b/app/src/main/java/org/tasks/notifications/AudioManager.java @@ -1,15 +1,15 @@ package org.tasks.notifications; -import android.app.Application; import android.content.Context; import javax.inject.Inject; +import org.tasks.injection.ApplicationContext; public class AudioManager { private final android.media.AudioManager audioManager; @Inject - public AudioManager(Application context) { + public AudioManager(@ApplicationContext Context context) { audioManager = (android.media.AudioManager) context.getSystemService(Context.AUDIO_SERVICE); } diff --git a/app/src/main/java/org/tasks/notifications/NotificationManager.java b/app/src/main/java/org/tasks/notifications/NotificationManager.java index 6dd9f7e7c..999300412 100644 --- a/app/src/main/java/org/tasks/notifications/NotificationManager.java +++ b/app/src/main/java/org/tasks/notifications/NotificationManager.java @@ -17,7 +17,6 @@ import static java.util.Collections.singletonList; import static org.tasks.Strings.isNullOrEmpty; import android.annotation.SuppressLint; -import android.app.Application; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; @@ -44,6 +43,7 @@ import org.tasks.R; import org.tasks.data.LocationDao; import org.tasks.data.Place; import org.tasks.injection.ApplicationScope; +import org.tasks.injection.ApplicationContext; import org.tasks.intents.TaskIntents; import org.tasks.preferences.Preferences; import org.tasks.receivers.CompleteTaskReceiver; @@ -80,7 +80,7 @@ public class NotificationManager { @Inject public NotificationManager( - Application context, + @ApplicationContext Context context, Preferences preferences, NotificationDao notificationDao, TaskDao taskDao, diff --git a/app/src/main/java/org/tasks/notifications/TelephonyManager.java b/app/src/main/java/org/tasks/notifications/TelephonyManager.java index 41dfeb880..f9d99e1e1 100644 --- a/app/src/main/java/org/tasks/notifications/TelephonyManager.java +++ b/app/src/main/java/org/tasks/notifications/TelephonyManager.java @@ -1,15 +1,15 @@ package org.tasks.notifications; -import android.app.Application; import android.content.Context; import javax.inject.Inject; +import org.tasks.injection.ApplicationContext; public class TelephonyManager { private final android.telephony.TelephonyManager telephonyManager; @Inject - public TelephonyManager(Application context) { + public TelephonyManager(@ApplicationContext Context context) { telephonyManager = (android.telephony.TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); } diff --git a/app/src/main/java/org/tasks/preferences/DefaultFilterProvider.kt b/app/src/main/java/org/tasks/preferences/DefaultFilterProvider.kt index ead6ec420..0a4646d76 100644 --- a/app/src/main/java/org/tasks/preferences/DefaultFilterProvider.kt +++ b/app/src/main/java/org/tasks/preferences/DefaultFilterProvider.kt @@ -1,6 +1,5 @@ package org.tasks.preferences -import android.app.Application import android.content.Context import com.todoroo.astrid.api.* import com.todoroo.astrid.api.Filter @@ -10,11 +9,12 @@ import org.tasks.R import org.tasks.Strings.isNullOrEmpty import org.tasks.data.* import org.tasks.filters.PlaceFilter +import org.tasks.injection.ApplicationContext import timber.log.Timber import javax.inject.Inject class DefaultFilterProvider @Inject constructor( - private val context: Application, + @param:ApplicationContext private val context: Context, private val preferences: Preferences, private val filterDao: FilterDao, private val tagDataDao: TagDataDao, diff --git a/app/src/main/java/org/tasks/preferences/Device.java b/app/src/main/java/org/tasks/preferences/Device.java index 1f0fc2755..50053ef87 100644 --- a/app/src/main/java/org/tasks/preferences/Device.java +++ b/app/src/main/java/org/tasks/preferences/Device.java @@ -2,7 +2,6 @@ package org.tasks.preferences; import static java.util.Arrays.asList; -import android.app.Application; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; @@ -15,6 +14,7 @@ import java.util.List; import javax.inject.Inject; import org.tasks.BuildConfig; import org.tasks.R; +import org.tasks.injection.ApplicationContext; import org.tasks.locale.Locale; import timber.log.Timber; @@ -24,7 +24,7 @@ public class Device { private final Locale locale; @Inject - public Device(Application context, Locale locale) { + public Device(@ApplicationContext Context context, Locale locale) { this.context = context; this.locale = locale; } diff --git a/app/src/main/java/org/tasks/preferences/PermissionChecker.java b/app/src/main/java/org/tasks/preferences/PermissionChecker.java index fee5b862c..e3b45d750 100644 --- a/app/src/main/java/org/tasks/preferences/PermissionChecker.java +++ b/app/src/main/java/org/tasks/preferences/PermissionChecker.java @@ -4,10 +4,10 @@ import static com.todoroo.andlib.utility.AndroidUtilities.atLeastOreo; import static com.todoroo.andlib.utility.AndroidUtilities.atLeastQ; import android.Manifest.permission; -import android.app.Application; import android.content.Context; import android.content.pm.PackageManager; import javax.inject.Inject; +import org.tasks.injection.ApplicationContext; import timber.log.Timber; public class PermissionChecker { @@ -15,7 +15,7 @@ public class PermissionChecker { private final Context context; @Inject - PermissionChecker(Application context) { + PermissionChecker(@ApplicationContext Context context) { this.context = context; } diff --git a/app/src/main/java/org/tasks/receivers/RefreshReceiver.java b/app/src/main/java/org/tasks/receivers/RefreshReceiver.java index c8fc5df4f..d9f4b2407 100644 --- a/app/src/main/java/org/tasks/receivers/RefreshReceiver.java +++ b/app/src/main/java/org/tasks/receivers/RefreshReceiver.java @@ -1,6 +1,6 @@ package org.tasks.receivers; -import android.app.Application; +import android.content.Context; import android.content.Intent; import androidx.annotation.NonNull; import com.todoroo.astrid.api.Filter; @@ -8,6 +8,7 @@ import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.provider.Astrid2TaskProvider; import javax.inject.Inject; import org.tasks.R; +import org.tasks.injection.ApplicationContext; import org.tasks.injection.InjectingJobIntentService; import org.tasks.injection.ServiceComponent; import org.tasks.preferences.DefaultFilterProvider; @@ -15,7 +16,7 @@ import org.tasks.preferences.Preferences; public class RefreshReceiver extends InjectingJobIntentService { - @Inject Application context; + @Inject @ApplicationContext Context context; @Inject DefaultFilterProvider defaultFilterProvider; @Inject TaskDao taskDao; @Inject Preferences preferences; diff --git a/app/src/main/java/org/tasks/reminders/SnoozeDialog.java b/app/src/main/java/org/tasks/reminders/SnoozeDialog.java index 065a411fd..9a4cc9be8 100644 --- a/app/src/main/java/org/tasks/reminders/SnoozeDialog.java +++ b/app/src/main/java/org/tasks/reminders/SnoozeDialog.java @@ -2,8 +2,8 @@ package org.tasks.reminders; import static com.todoroo.andlib.utility.DateUtilities.getTimeString; -import android.app.Application; import android.app.Dialog; +import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import androidx.annotation.NonNull; @@ -13,6 +13,7 @@ import javax.inject.Inject; import org.tasks.R; import org.tasks.dialogs.DialogBuilder; import org.tasks.injection.DialogFragmentComponent; +import org.tasks.injection.ApplicationContext; import org.tasks.injection.InjectingDialogFragment; import org.tasks.preferences.Preferences; import org.tasks.time.DateTime; @@ -21,7 +22,7 @@ public class SnoozeDialog extends InjectingDialogFragment { private final List items = new ArrayList<>(); @Inject Preferences preferences; - @Inject Application context; + @Inject @ApplicationContext Context context; @Inject DialogBuilder dialogBuilder; private SnoozeCallback snoozeCallback; private DialogInterface.OnCancelListener onCancelListener; diff --git a/app/src/main/java/org/tasks/repeats/BasicRecurrenceDialog.java b/app/src/main/java/org/tasks/repeats/BasicRecurrenceDialog.java index f99ffd98d..7daab9bcd 100644 --- a/app/src/main/java/org/tasks/repeats/BasicRecurrenceDialog.java +++ b/app/src/main/java/org/tasks/repeats/BasicRecurrenceDialog.java @@ -11,8 +11,8 @@ import static org.tasks.Strings.isNullOrEmpty; import static org.tasks.repeats.CustomRecurrenceDialog.newCustomRecurrenceDialog; import static org.tasks.time.DateTimeUtils.currentTimeMillis; -import android.app.Activity; import android.app.Dialog; +import android.content.Context; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -24,6 +24,7 @@ import javax.inject.Inject; import org.tasks.R; import org.tasks.dialogs.DialogBuilder; import org.tasks.injection.DialogFragmentComponent; +import org.tasks.injection.ActivityContext; import org.tasks.injection.InjectingDialogFragment; import org.tasks.ui.SingleCheckedArrayAdapter; import timber.log.Timber; @@ -34,7 +35,7 @@ public class BasicRecurrenceDialog extends InjectingDialogFragment { private static final String EXTRA_DATE = "extra_date"; private static final String FRAG_TAG_CUSTOM_RECURRENCE = "frag_tag_custom_recurrence"; - @Inject Activity context; + @Inject @ActivityContext Context context; @Inject DialogBuilder dialogBuilder; @Inject RepeatRuleToString repeatRuleToString; diff --git a/app/src/main/java/org/tasks/repeats/CustomRecurrenceDialog.java b/app/src/main/java/org/tasks/repeats/CustomRecurrenceDialog.java index d34632b61..02c6d2067 100644 --- a/app/src/main/java/org/tasks/repeats/CustomRecurrenceDialog.java +++ b/app/src/main/java/org/tasks/repeats/CustomRecurrenceDialog.java @@ -14,6 +14,7 @@ import static org.tasks.time.DateTimeUtils.currentTimeMillis; import android.app.Activity; import android.app.Dialog; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.res.ColorStateList; @@ -49,7 +50,6 @@ import com.google.ical.values.WeekdayNum; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.astrid.repeats.RepeatControlSet; import java.text.DateFormatSymbols; -import java.time.format.FormatStyle; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; @@ -59,10 +59,12 @@ import org.tasks.R; import org.tasks.dialogs.DialogBuilder; import org.tasks.dialogs.MyDatePickerDialog; import org.tasks.injection.DialogFragmentComponent; +import org.tasks.injection.ActivityContext; import org.tasks.injection.InjectingDialogFragment; import org.tasks.locale.Locale; import org.tasks.preferences.ResourceResolver; import org.tasks.time.DateTime; +import java.time.format.FormatStyle; import timber.log.Timber; public class CustomRecurrenceDialog extends InjectingDialogFragment { @@ -74,7 +76,7 @@ public class CustomRecurrenceDialog extends InjectingDialogFragment { private static final String FRAG_TAG_DATE_PICKER = "frag_tag_date_picker"; private static final int REQUEST_PICK_DATE = 505; private final List repeatUntilOptions = new ArrayList<>(); - @Inject Activity context; + @Inject @ActivityContext Context context; @Inject DialogBuilder dialogBuilder; @Inject Locale locale; diff --git a/app/src/main/java/org/tasks/repeats/RepeatRuleToString.java b/app/src/main/java/org/tasks/repeats/RepeatRuleToString.java index 934575d2c..d4fdc1207 100644 --- a/app/src/main/java/org/tasks/repeats/RepeatRuleToString.java +++ b/app/src/main/java/org/tasks/repeats/RepeatRuleToString.java @@ -3,7 +3,6 @@ package org.tasks.repeats; import static com.google.ical.values.Frequency.MONTHLY; import static com.google.ical.values.Frequency.WEEKLY; -import android.app.Application; import android.content.Context; import com.google.common.base.Joiner; import com.google.ical.values.Frequency; @@ -18,6 +17,7 @@ import java.util.Calendar; import java.util.List; import javax.inject.Inject; import org.tasks.R; +import org.tasks.injection.ApplicationContext; import org.tasks.locale.Locale; import org.tasks.time.DateTime; @@ -28,7 +28,7 @@ public class RepeatRuleToString { private final List weekdays = Arrays.asList(Weekday.values()); @Inject - public RepeatRuleToString(Application context, Locale locale) { + public RepeatRuleToString(@ApplicationContext Context context, Locale locale) { this.context = context; this.locale = locale; } diff --git a/app/src/main/java/org/tasks/scheduling/AlarmManager.java b/app/src/main/java/org/tasks/scheduling/AlarmManager.java index 86e831c2f..01c29b65e 100644 --- a/app/src/main/java/org/tasks/scheduling/AlarmManager.java +++ b/app/src/main/java/org/tasks/scheduling/AlarmManager.java @@ -1,17 +1,17 @@ package org.tasks.scheduling; import android.annotation.SuppressLint; -import android.app.Application; import android.app.PendingIntent; import android.content.Context; import javax.inject.Inject; +import org.tasks.injection.ApplicationContext; public class AlarmManager { private final android.app.AlarmManager alarmManager; @Inject - public AlarmManager(Application context) { + public AlarmManager(@ApplicationContext Context context) { alarmManager = (android.app.AlarmManager) context.getSystemService(Context.ALARM_SERVICE); } diff --git a/app/src/main/java/org/tasks/scheduling/CalendarNotificationIntentService.java b/app/src/main/java/org/tasks/scheduling/CalendarNotificationIntentService.java index 03228088e..3dd9bd1e5 100644 --- a/app/src/main/java/org/tasks/scheduling/CalendarNotificationIntentService.java +++ b/app/src/main/java/org/tasks/scheduling/CalendarNotificationIntentService.java @@ -1,6 +1,5 @@ package org.tasks.scheduling; -import android.app.Application; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; @@ -14,6 +13,7 @@ import javax.inject.Inject; import org.tasks.R; import org.tasks.calendars.AndroidCalendarEvent; import org.tasks.calendars.CalendarEventProvider; +import org.tasks.injection.ApplicationContext; import org.tasks.injection.InjectingJobIntentService; import org.tasks.injection.ServiceComponent; import org.tasks.preferences.Preferences; @@ -26,7 +26,7 @@ public class CalendarNotificationIntentService extends RecurringIntervalIntentSe private static final String URI_PREFIX = "cal-reminder"; @Inject Preferences preferences; @Inject CalendarEventProvider calendarEventProvider; - @Inject Application context; + @Inject @ApplicationContext Context context; @Inject AlarmManager alarmManager; public static void enqueueWork(Context context) { diff --git a/app/src/main/java/org/tasks/scheduling/NotificationSchedulerIntentService.java b/app/src/main/java/org/tasks/scheduling/NotificationSchedulerIntentService.java index 89e311ae3..7c64d22ed 100644 --- a/app/src/main/java/org/tasks/scheduling/NotificationSchedulerIntentService.java +++ b/app/src/main/java/org/tasks/scheduling/NotificationSchedulerIntentService.java @@ -7,7 +7,6 @@ import static org.tasks.notifications.NotificationManager.NOTIFICATION_CHANNEL_T import static org.tasks.notifications.NotificationManager.NOTIFICATION_CHANNEL_TIMERS; import android.annotation.TargetApi; -import android.app.Application; import android.app.NotificationChannel; import android.content.Context; import android.content.Intent; @@ -17,6 +16,7 @@ import com.todoroo.astrid.alarms.AlarmService; import com.todoroo.astrid.reminders.ReminderService; import javax.inject.Inject; import org.tasks.R; +import org.tasks.injection.ApplicationContext; import org.tasks.injection.InjectingJobIntentService; import org.tasks.injection.ServiceComponent; import org.tasks.jobs.NotificationQueue; @@ -27,7 +27,7 @@ public class NotificationSchedulerIntentService extends InjectingJobIntentServic private static final String EXTRA_CANCEL_EXISTING_NOTIFICATIONS = "extra_cancel_existing_notifications"; - @Inject Application context; + @Inject @ApplicationContext Context context; @Inject AlarmService alarmService; @Inject ReminderService reminderService; @Inject NotificationQueue notificationQueue; diff --git a/app/src/main/java/org/tasks/tasklist/ViewHolderFactory.kt b/app/src/main/java/org/tasks/tasklist/ViewHolderFactory.kt index 252d397c4..20e3b1b94 100644 --- a/app/src/main/java/org/tasks/tasklist/ViewHolderFactory.kt +++ b/app/src/main/java/org/tasks/tasklist/ViewHolderFactory.kt @@ -9,6 +9,7 @@ import com.todoroo.andlib.utility.AndroidUtilities import com.todoroo.astrid.service.TaskCompleter import org.tasks.R import org.tasks.dialogs.Linkify +import org.tasks.injection.ActivityContext import org.tasks.preferences.Preferences import org.tasks.preferences.ResourceResolver import org.tasks.tasklist.TaskViewHolder.ViewHolderCallbacks @@ -18,7 +19,7 @@ import java.util.* import javax.inject.Inject class ViewHolderFactory @Inject constructor( - private val context: Activity, + @param:ActivityContext private val context: Context, private val preferences: Preferences, private val chipProvider: ChipProvider, private val checkBoxProvider: CheckBoxProvider, diff --git a/app/src/main/java/org/tasks/themes/ColorProvider.kt b/app/src/main/java/org/tasks/themes/ColorProvider.kt index 158a6e748..f321f50fc 100644 --- a/app/src/main/java/org/tasks/themes/ColorProvider.kt +++ b/app/src/main/java/org/tasks/themes/ColorProvider.kt @@ -1,15 +1,13 @@ package org.tasks.themes -import android.app.Activity import android.content.Context import androidx.annotation.ColorInt import org.tasks.R +import org.tasks.injection.ActivityContext import org.tasks.preferences.Preferences import javax.inject.Inject -class ColorProvider constructor(private val context: Context, preferences: Preferences) { - - @Inject constructor(activity: Activity, preferences: Preferences): this(activity as Context, preferences) +class ColorProvider @Inject constructor(@param:ActivityContext private val context: Context, preferences: Preferences) { companion object { const val BLUE_500 = -14575885 diff --git a/app/src/main/java/org/tasks/ui/CalendarControlSet.kt b/app/src/main/java/org/tasks/ui/CalendarControlSet.kt index 2a077b40c..caeca9df4 100644 --- a/app/src/main/java/org/tasks/ui/CalendarControlSet.kt +++ b/app/src/main/java/org/tasks/ui/CalendarControlSet.kt @@ -24,6 +24,7 @@ import org.tasks.calendars.CalendarEventProvider import org.tasks.calendars.CalendarPicker import org.tasks.calendars.CalendarProvider import org.tasks.dialogs.DialogBuilder +import org.tasks.injection.ActivityContext import org.tasks.injection.FragmentComponent import org.tasks.preferences.FragmentPermissionRequestor import org.tasks.preferences.PermissionChecker @@ -39,7 +40,7 @@ class CalendarControlSet : TaskEditControlFragment() { @BindView(R.id.calendar_display_which) lateinit var calendar: TextView - @Inject lateinit var activity: Activity + @Inject @ActivityContext lateinit var activity: Context @Inject lateinit var gcalHelper: GCalHelper @Inject lateinit var calendarProvider: CalendarProvider @Inject lateinit var preferences: Preferences diff --git a/app/src/main/java/org/tasks/ui/CheckBoxProvider.kt b/app/src/main/java/org/tasks/ui/CheckBoxProvider.kt index e0a4d8c45..02c13377c 100644 --- a/app/src/main/java/org/tasks/ui/CheckBoxProvider.kt +++ b/app/src/main/java/org/tasks/ui/CheckBoxProvider.kt @@ -1,6 +1,5 @@ package org.tasks.ui -import android.app.Activity import android.content.Context import android.graphics.Bitmap import android.graphics.Canvas @@ -8,13 +7,12 @@ import android.graphics.drawable.Drawable import androidx.annotation.DrawableRes import com.todoroo.astrid.data.Task import org.tasks.R +import org.tasks.injection.ActivityContext import org.tasks.themes.ColorProvider import org.tasks.themes.DrawableUtil import javax.inject.Inject -class CheckBoxProvider constructor(private val context: Context, private val colorProvider: ColorProvider) { - - @Inject constructor(context: Activity, colorProvider: ColorProvider): this(context as Context, colorProvider) +class CheckBoxProvider @Inject constructor(@param:ActivityContext private val context: Context, private val colorProvider: ColorProvider) { fun getCheckBox(task: Task) = getCheckBox(task.isCompleted, task.isRecurring, task.priority) diff --git a/app/src/main/java/org/tasks/ui/DeadlineControlSet.kt b/app/src/main/java/org/tasks/ui/DeadlineControlSet.kt index e7bc5d29f..355a23a73 100644 --- a/app/src/main/java/org/tasks/ui/DeadlineControlSet.kt +++ b/app/src/main/java/org/tasks/ui/DeadlineControlSet.kt @@ -17,6 +17,7 @@ import org.tasks.R import org.tasks.date.DateTimeUtils import org.tasks.dialogs.DateTimePicker import org.tasks.dialogs.DateTimePicker.Companion.newDateTimePicker +import org.tasks.injection.ActivityContext import org.tasks.injection.FragmentComponent import org.tasks.locale.Locale import org.tasks.preferences.Preferences @@ -25,7 +26,7 @@ import java.time.format.FormatStyle import javax.inject.Inject class DeadlineControlSet : TaskEditControlFragment() { - @Inject lateinit var activity: Activity + @Inject @ActivityContext lateinit var activity: Context @Inject lateinit var locale: Locale @Inject lateinit var preferences: Preferences diff --git a/app/src/main/java/org/tasks/ui/Toaster.java b/app/src/main/java/org/tasks/ui/Toaster.java index 6091c0093..4c72cd58c 100644 --- a/app/src/main/java/org/tasks/ui/Toaster.java +++ b/app/src/main/java/org/tasks/ui/Toaster.java @@ -3,11 +3,11 @@ package org.tasks.ui; import static android.widget.Toast.LENGTH_LONG; import static org.tasks.Strings.isNullOrEmpty; -import android.app.Activity; import android.content.Context; import android.widget.Toast; import androidx.annotation.StringRes; import javax.inject.Inject; +import org.tasks.injection.ActivityContext; import org.tasks.locale.Locale; public class Toaster { @@ -16,7 +16,7 @@ public class Toaster { private final Locale locale; @Inject - public Toaster(Activity context, Locale locale) { + public Toaster(@ActivityContext Context context, Locale locale) { this.context = context; this.locale = locale; } diff --git a/app/src/main/java/org/tasks/voice/VoiceCommandActivity.java b/app/src/main/java/org/tasks/voice/VoiceCommandActivity.java index 796766db5..1321ef4b3 100644 --- a/app/src/main/java/org/tasks/voice/VoiceCommandActivity.java +++ b/app/src/main/java/org/tasks/voice/VoiceCommandActivity.java @@ -2,7 +2,7 @@ package org.tasks.voice; import static org.tasks.Strings.isNullOrEmpty; -import android.app.Application; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.widget.Toast; @@ -10,12 +10,13 @@ import com.todoroo.astrid.service.TaskCreator; import javax.inject.Inject; import org.tasks.R; import org.tasks.injection.ActivityComponent; +import org.tasks.injection.ApplicationContext; import org.tasks.injection.InjectingAppCompatActivity; public class VoiceCommandActivity extends InjectingAppCompatActivity { @Inject TaskCreator taskCreator; - @Inject Application context; + @Inject @ApplicationContext Context context; @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/org/tasks/widget/AppWidgetManager.java b/app/src/main/java/org/tasks/widget/AppWidgetManager.java index 1ba6fc5ad..b6eda96f2 100644 --- a/app/src/main/java/org/tasks/widget/AppWidgetManager.java +++ b/app/src/main/java/org/tasks/widget/AppWidgetManager.java @@ -1,11 +1,11 @@ package org.tasks.widget; -import android.app.Application; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import javax.inject.Inject; import org.tasks.R; +import org.tasks.injection.ApplicationContext; public class AppWidgetManager { @@ -13,7 +13,7 @@ public class AppWidgetManager { private final Context context; @Inject - public AppWidgetManager(Application context) { + public AppWidgetManager(@ApplicationContext Context context) { this.context = context; appWidgetManager = android.appwidget.AppWidgetManager.getInstance(context); } diff --git a/app/src/main/java/org/tasks/widget/TasksWidget.java b/app/src/main/java/org/tasks/widget/TasksWidget.java index cedbf7ba8..92fca90ac 100644 --- a/app/src/main/java/org/tasks/widget/TasksWidget.java +++ b/app/src/main/java/org/tasks/widget/TasksWidget.java @@ -4,7 +4,6 @@ import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK; import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; -import android.app.Application; import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.content.Context; @@ -20,6 +19,7 @@ import javax.inject.Inject; import org.tasks.R; import org.tasks.activities.FilterSelectionActivity; import org.tasks.injection.BroadcastComponent; +import org.tasks.injection.ApplicationContext; import org.tasks.injection.InjectingAppWidgetProvider; import org.tasks.intents.TaskIntents; import org.tasks.locale.Locale; @@ -35,7 +35,7 @@ public class TasksWidget extends InjectingAppWidgetProvider { @Inject DefaultFilterProvider defaultFilterProvider; @Inject Locale locale; @Inject TaskDao taskDao; - @Inject Application context; + @Inject @ApplicationContext Context context; @Override protected void inject(BroadcastComponent component) {