Replace ApplicationScope with Singleton

pull/1020/head
Alex Baker 4 years ago
parent 4a39b7e9ee
commit c9407d3ef8

@ -17,8 +17,9 @@ import com.todoroo.astrid.sync.NewSyncTestCase
import dagger.Component
import org.tasks.data.*
import org.tasks.jobs.BackupServiceTests
import javax.inject.Singleton
@ApplicationScope
@Singleton
@Component(modules = [TestModule::class])
interface TestComponent : ApplicationComponent {
fun inject(tests: GtasksListServiceTest)

@ -9,11 +9,12 @@ import org.tasks.TestUtilities
import org.tasks.preferences.PermissionChecker
import org.tasks.preferences.PermissivePermissionChecker
import org.tasks.preferences.Preferences
import javax.inject.Singleton
@Module(includes = [ApplicationModule::class])
class TestModule {
@Provides
@ApplicationScope
@Singleton
fun getDatabase(@ApplicationContext context: Context): Database {
return Room.inMemoryDatabaseBuilder(context, Database::class.java)
.fallbackToDestructiveMigration()

@ -11,15 +11,15 @@ import com.google.firebase.remoteconfig.ktx.remoteConfigSettings
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
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import javax.inject.Singleton
@ApplicationScope
@Singleton
class Firebase @Inject constructor(@param:ApplicationContext val context: Context, preferences: Preferences) {
private var enabled: Boolean = preferences.isTrackingEnabled

@ -10,9 +10,9 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.tasks.data.Alarm;
import org.tasks.data.AlarmDao;
import org.tasks.injection.ApplicationScope;
import org.tasks.jobs.AlarmEntry;
import org.tasks.jobs.NotificationQueue;
@ -21,7 +21,7 @@ import org.tasks.jobs.NotificationQueue;
*
* @author Tim Su <tim@todoroo.com>
*/
@ApplicationScope
@Singleton
public class AlarmService {
private static final long NO_ALARM = Long.MAX_VALUE;

@ -14,14 +14,14 @@ import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task;
import java.util.List;
import javax.inject.Inject;
import org.tasks.injection.ApplicationScope;
import javax.inject.Singleton;
import org.tasks.jobs.NotificationQueue;
import org.tasks.jobs.ReminderEntry;
import org.tasks.preferences.Preferences;
import org.tasks.reminders.Random;
import org.tasks.time.DateTime;
@ApplicationScope
@Singleton
public final class ReminderService {
public static final int TYPE_DUE = 0;

@ -3,11 +3,11 @@ package org.tasks
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
import javax.inject.Singleton
@ApplicationScope
@Singleton
class ShortcutManager @Inject constructor(@ApplicationContext context: Context) {
private val shortcutManager: ShortcutManager? = if (AndroidUtilities.atLeastNougatMR1()) {
context.getSystemService(ShortcutManager::class.java)

@ -3,14 +3,14 @@ package org.tasks.billing;
import java.util.HashMap;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.tasks.BuildConfig;
import org.tasks.LocalBroadcastManager;
import org.tasks.R;
import org.tasks.injection.ApplicationScope;
import org.tasks.preferences.Preferences;
import timber.log.Timber;
@ApplicationScope
@Singleton
public class Inventory {
private static final String SKU_VIP = "vip";

@ -5,8 +5,9 @@ import org.tasks.Tasks
import org.tasks.backup.TasksBackupAgent
import org.tasks.dashclock.DashClockExtension
import org.tasks.widget.ScrollableWidgetUpdateService
import javax.inject.Singleton
@ApplicationScope
@Singleton
@Component(modules = [ApplicationModule::class, ProductionModule::class])
interface ApplicationComponent {
operator fun plus(module: ActivityModule): ActivityComponent

@ -15,6 +15,7 @@ import org.tasks.locale.Locale
import org.tasks.location.Geocoder
import org.tasks.location.MapboxGeocoder
import org.tasks.notifications.NotificationDao
import javax.inject.Singleton
@Module
class ApplicationModule(@get:Provides @get:ApplicationContext val context: Context) {
@ -24,59 +25,59 @@ class ApplicationModule(@get:Provides @get:ApplicationContext val context: Conte
get() = Locale.getInstance(context)
@Provides
@ApplicationScope
@Singleton
fun getJavaLocale(locale: Locale): java.util.Locale = locale.locale
@Provides
@ApplicationScope
@Singleton
fun getNotificationDao(db: Database): NotificationDao = db.notificationDao()
@Provides
@ApplicationScope
@Singleton
fun getTagDataDao(db: Database): TagDataDao = db.tagDataDao
@Provides
@ApplicationScope
@Singleton
fun getUserActivityDao(db: Database): UserActivityDao = db.userActivityDao
@Provides
@ApplicationScope
@Singleton
fun getTaskAttachmentDao(db: Database): TaskAttachmentDao = db.taskAttachmentDao
@Provides
@ApplicationScope
@Singleton
fun getTaskListMetadataDao(db: Database): TaskListMetadataDao = db.taskListMetadataDao
@Provides
@ApplicationScope
@Singleton
fun getGoogleTaskDao(db: Database): GoogleTaskDao = db.googleTaskDao
@Provides
@ApplicationScope
@Singleton
fun getAlarmDao(db: Database): AlarmDao = db.alarmDao
@Provides
@ApplicationScope
@Singleton
fun getGeofenceDao(db: Database): LocationDao = db.locationDao
@Provides
@ApplicationScope
@Singleton
fun getTagDao(db: Database): TagDao = db.tagDao
@Provides
@ApplicationScope
@Singleton
fun getFilterDao(db: Database): FilterDao = db.filterDao
@Provides
@ApplicationScope
@Singleton
fun getGoogleTaskListDao(db: Database): GoogleTaskListDao = db.googleTaskListDao
@Provides
@ApplicationScope
@Singleton
fun getCaldavDao(db: Database): CaldavDao = db.caldavDao
@Provides
@ApplicationScope
@Singleton
fun getTaskDao(db: Database, workManager: WorkManager): TaskDao {
val taskDao = db.taskDao
taskDao.initialize(workManager)
@ -84,7 +85,7 @@ class ApplicationModule(@get:Provides @get:ApplicationContext val context: Conte
}
@Provides
@ApplicationScope
@Singleton
fun getDeletionDao(db: Database): DeletionDao = db.deletionDao
@Provides

@ -1,7 +0,0 @@
package org.tasks.injection
import javax.inject.Scope
@Scope
@Retention(AnnotationRetention.RUNTIME)
annotation class ApplicationScope

@ -2,8 +2,9 @@ package org.tasks.injection
import com.todoroo.astrid.provider.Astrid2TaskProvider
import dagger.Component
import javax.inject.Singleton
@ApplicationScope
@Singleton
@Component(modules = [ContentProviderModule::class])
interface ContentProviderComponent {
fun inject(contentProvider: Astrid2TaskProvider)

@ -7,11 +7,12 @@ import dagger.Module
import dagger.Provides
import org.tasks.db.Migrations
import org.tasks.preferences.Preferences
import javax.inject.Singleton
@Module(includes = [ApplicationModule::class])
internal class ProductionModule {
@Provides
@ApplicationScope
@Singleton
fun getAppDatabase(@ApplicationContext context: Context): Database {
return Room.databaseBuilder(context, Database::class.java, Database.NAME)
.allowMainThreadQueries() // TODO: remove me

@ -4,13 +4,13 @@ import com.google.common.collect.Ordering
import com.google.common.collect.TreeMultimap
import com.google.common.primitives.Ints
import kotlinx.collections.immutable.toImmutableList
import org.tasks.injection.ApplicationScope
import org.tasks.preferences.Preferences
import org.tasks.time.DateTime
import java.util.*
import javax.inject.Inject
import javax.inject.Singleton
@ApplicationScope
@Singleton
class NotificationQueue @Inject constructor(private val preferences: Preferences, private val workManager: WorkManager) {
private val jobs = TreeMultimap.create(Ordering.natural<Long>(), Comparator { l: NotificationQueueEntry, r: NotificationQueueEntry -> Ints.compare(l.hashCode(), r.hashCode()) })

@ -22,7 +22,6 @@ import org.tasks.data.GoogleTaskListDao
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
@ -30,9 +29,10 @@ import timber.log.Timber
import java.util.*
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.math.max
@ApplicationScope
@Singleton
class WorkManager @Inject constructor(
@param:ApplicationContext private val context: Context,
private val preferences: Preferences,

@ -38,11 +38,11 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.tasks.LocalBroadcastManager;
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;
@ -55,7 +55,7 @@ import org.tasks.themes.ColorProvider;
import org.tasks.time.DateTime;
import timber.log.Timber;
@ApplicationScope
@Singleton
public class NotificationManager {
public static final String NOTIFICATION_CHANNEL_DEFAULT = "notifications";

@ -10,12 +10,12 @@ import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.tasks.R;
import org.tasks.injection.ApplicationScope;
import org.tasks.jobs.WorkManager;
import org.tasks.preferences.Preferences;
@ApplicationScope
@Singleton
public class RefreshScheduler {
private final Preferences preferences;

@ -5,7 +5,6 @@ import android.security.keystore.KeyGenParameterSpec
import android.security.keystore.KeyProperties
import android.util.Base64
import org.tasks.Strings.isNullOrEmpty
import org.tasks.injection.ApplicationScope
import timber.log.Timber
import java.nio.charset.StandardCharsets
import java.security.KeyStore
@ -14,8 +13,9 @@ import java.util.*
import javax.crypto.*
import javax.crypto.spec.GCMParameterSpec
import javax.inject.Inject
import javax.inject.Singleton
@ApplicationScope
@Singleton
class KeyStoreEncryption @Inject constructor() {
private val keyStore: KeyStore = KeyStore.getInstance(ANDROID_KEYSTORE)

@ -8,6 +8,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.tasks.LocalBroadcastManager;
import org.tasks.data.CaldavCalendar;
import org.tasks.data.CaldavDao;
@ -15,9 +16,8 @@ import org.tasks.data.GoogleTaskList;
import org.tasks.data.GoogleTaskListDao;
import org.tasks.data.TagData;
import org.tasks.data.TagDataDao;
import org.tasks.injection.ApplicationScope;
@ApplicationScope
@Singleton
public class ChipListCache {
private final Map<String, GtasksFilter> googleTaskLists = new HashMap<>();

Loading…
Cancel
Save