diff --git a/app/build.gradle.kts b/app/build.gradle.kts index cbc13dae8..7d625b91d 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -192,6 +192,7 @@ dependencies { googleplayImplementation("com.crashlytics.sdk.android:crashlytics:${Versions.crashlytics}") googleplayImplementation("com.google.firebase:firebase-analytics:${Versions.analytics}") + googleplayImplementation("com.google.firebase:firebase-config-ktx:${Versions.remote_config}") googleplayImplementation("com.google.android.gms:play-services-location:17.0.0") googleplayImplementation("com.google.android.gms:play-services-maps:17.0.0") googleplayImplementation("com.google.android.libraries.places:places:2.2.0") diff --git a/app/src/generic/java/org/tasks/analytics/Firebase.kt b/app/src/generic/java/org/tasks/analytics/Firebase.kt index 419fbe882..97e1aab73 100644 --- a/app/src/generic/java/org/tasks/analytics/Firebase.kt +++ b/app/src/generic/java/org/tasks/analytics/Firebase.kt @@ -5,4 +5,6 @@ import javax.inject.Inject class Firebase @Inject constructor() { fun reportException(t: Throwable) = Timber.e(t) + + fun updateRemoteConfig() {} } \ 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 90e6ec0dd..0dc948e89 100644 --- a/app/src/googleplay/java/org/tasks/analytics/Firebase.kt +++ b/app/src/googleplay/java/org/tasks/analytics/Firebase.kt @@ -5,10 +5,13 @@ import android.os.Bundle import com.android.billingclient.api.BillingClient.BillingResponse import com.crashlytics.android.Crashlytics import com.google.firebase.analytics.FirebaseAnalytics +import com.google.firebase.remoteconfig.FirebaseRemoteConfig +import com.google.firebase.remoteconfig.ktx.remoteConfigSettings import io.fabric.sdk.android.Fabric import org.tasks.billing.BillingClientImpl import org.tasks.injection.ApplicationScope import org.tasks.injection.ForApplication +import org.tasks.jobs.RemoteConfigWork import org.tasks.preferences.Preferences import timber.log.Timber import javax.inject.Inject @@ -18,6 +21,7 @@ class Firebase @Inject constructor(@ForApplication context: Context?, preference private var enabled: Boolean = preferences.isTrackingEnabled private var analytics: FirebaseAnalytics? = null + private var remoteConfig: FirebaseRemoteConfig? = null fun reportException(t: Throwable?) { Timber.e(t) @@ -36,11 +40,24 @@ class Firebase @Inject constructor(@ForApplication context: Context?, preference analytics!!.logEvent(FirebaseAnalytics.Event.ECOMMERCE_PURCHASE, bundle) } + fun updateRemoteConfig() { + if (!enabled) { + return + } + remoteConfig?.fetchAndActivate()?.addOnSuccessListener { + Timber.d(it.toString()) + } + } + init { if (enabled) { analytics = FirebaseAnalytics.getInstance(context!!) analytics?.setAnalyticsCollectionEnabled(true) Fabric.with(context, Crashlytics()) + remoteConfig = FirebaseRemoteConfig.getInstance() + remoteConfig?.setConfigSettingsAsync(remoteConfigSettings { + minimumFetchIntervalInSeconds = RemoteConfigWork.WORK_INTERVAL_HOURS + }) } } } \ No newline at end of file diff --git a/app/src/main/java/org/tasks/Tasks.java b/app/src/main/java/org/tasks/Tasks.java index 775d2c5fe..d52e9e5e9 100644 --- a/app/src/main/java/org/tasks/Tasks.java +++ b/app/src/main/java/org/tasks/Tasks.java @@ -89,6 +89,7 @@ public class Tasks extends InjectingApplication implements Configuration.Provide workManager.get().updateBackgroundSync(); workManager.get().scheduleMidnightRefresh(); workManager.get().scheduleBackup(); + workManager.get().scheduleConfigRefresh(); geofenceApi.get().registerAll(); FileHelper.delete(context, preferences.getCacheDirectory()); billingClient.get().queryPurchases(); diff --git a/app/src/main/java/org/tasks/injection/InjectingWorker.java b/app/src/main/java/org/tasks/injection/InjectingWorker.java index c104fd88d..42e05255a 100644 --- a/app/src/main/java/org/tasks/injection/InjectingWorker.java +++ b/app/src/main/java/org/tasks/injection/InjectingWorker.java @@ -10,7 +10,7 @@ import timber.log.Timber; public abstract class InjectingWorker extends Worker { - @Inject Firebase firebase; + @Inject protected Firebase firebase; public InjectingWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); diff --git a/app/src/main/java/org/tasks/injection/JobComponent.java b/app/src/main/java/org/tasks/injection/JobComponent.java index a54ba228f..1e8264e2a 100644 --- a/app/src/main/java/org/tasks/injection/JobComponent.java +++ b/app/src/main/java/org/tasks/injection/JobComponent.java @@ -7,6 +7,7 @@ import org.tasks.jobs.CleanupWork; import org.tasks.jobs.DriveUploader; import org.tasks.jobs.MidnightRefreshWork; import org.tasks.jobs.RefreshWork; +import org.tasks.jobs.RemoteConfigWork; import org.tasks.jobs.ReverseGeocodeWork; import org.tasks.jobs.SyncWork; @@ -28,4 +29,6 @@ public interface JobComponent { void inject(DriveUploader driveUploader); void inject(ReverseGeocodeWork reverseGeocodeWork); + + void inject(RemoteConfigWork remoteConfigWork); } diff --git a/app/src/main/java/org/tasks/jobs/DriveUploader.java b/app/src/main/java/org/tasks/jobs/DriveUploader.java index 64afb2213..1eadc2545 100644 --- a/app/src/main/java/org/tasks/jobs/DriveUploader.java +++ b/app/src/main/java/org/tasks/jobs/DriveUploader.java @@ -21,7 +21,6 @@ import java.util.List; import javax.inject.Inject; import javax.net.ssl.SSLException; import org.tasks.R; -import org.tasks.analytics.Firebase; import org.tasks.drive.DriveInvoker; import org.tasks.injection.ForApplication; import org.tasks.injection.InjectingWorker; @@ -40,7 +39,6 @@ public class DriveUploader extends InjectingWorker { @Inject @ForApplication Context context; @Inject DriveInvoker drive; @Inject Preferences preferences; - @Inject Firebase firebase; public DriveUploader(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); diff --git a/app/src/main/java/org/tasks/jobs/RemoteConfigWork.kt b/app/src/main/java/org/tasks/jobs/RemoteConfigWork.kt new file mode 100644 index 000000000..a988f1ee4 --- /dev/null +++ b/app/src/main/java/org/tasks/jobs/RemoteConfigWork.kt @@ -0,0 +1,20 @@ +package org.tasks.jobs + +import android.content.Context +import androidx.work.WorkerParameters +import org.tasks.BuildConfig +import org.tasks.injection.InjectingWorker +import org.tasks.injection.JobComponent + +class RemoteConfigWork(context: Context, workerParams: WorkerParameters) : InjectingWorker(context, workerParams) { + companion object { + @JvmField val WORK_INTERVAL_HOURS: Long = if (BuildConfig.DEBUG) 1 else 12 + } + + override fun run(): Result { + firebase.updateRemoteConfig() + return Result.success() + } + + override fun inject(component: JobComponent) = component.inject(this) +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/jobs/ReverseGeocodeWork.kt b/app/src/main/java/org/tasks/jobs/ReverseGeocodeWork.kt index 4c6fb1f5c..40b3964d5 100644 --- a/app/src/main/java/org/tasks/jobs/ReverseGeocodeWork.kt +++ b/app/src/main/java/org/tasks/jobs/ReverseGeocodeWork.kt @@ -3,7 +3,6 @@ package org.tasks.jobs import android.content.Context import androidx.work.WorkerParameters import org.tasks.LocalBroadcastManager -import org.tasks.analytics.Firebase import org.tasks.data.LocationDao import org.tasks.injection.InjectingWorker import org.tasks.injection.JobComponent @@ -21,7 +20,6 @@ class ReverseGeocodeWork(context: Context, workerParams: WorkerParameters) : Inj @Inject lateinit var localBroadcastManager: LocalBroadcastManager @Inject lateinit var geocoder: Geocoder @Inject lateinit var locationDao: LocationDao - @Inject lateinit var firebase: Firebase public override fun run(): Result { val id = inputData.getLong(PLACE_ID, 0) diff --git a/app/src/main/java/org/tasks/jobs/SyncWork.java b/app/src/main/java/org/tasks/jobs/SyncWork.java index 9515b7364..5f051491e 100644 --- a/app/src/main/java/org/tasks/jobs/SyncWork.java +++ b/app/src/main/java/org/tasks/jobs/SyncWork.java @@ -10,7 +10,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import javax.inject.Inject; import org.tasks.LocalBroadcastManager; -import org.tasks.analytics.Firebase; import org.tasks.caldav.CaldavSynchronizer; import org.tasks.data.CaldavAccount; import org.tasks.data.CaldavDao; @@ -32,7 +31,6 @@ public class SyncWork extends InjectingWorker { @Inject GoogleTaskSynchronizer googleTaskSynchronizer; @Inject LocalBroadcastManager localBroadcastManager; @Inject Preferences preferences; - @Inject Firebase firebase; @Inject CaldavDao caldavDao; @Inject GoogleTaskListDao googleTaskListDao; @Inject SyncAdapters syncAdapters; diff --git a/app/src/main/java/org/tasks/jobs/WorkManager.java b/app/src/main/java/org/tasks/jobs/WorkManager.java index 797c8679b..cfd09c780 100644 --- a/app/src/main/java/org/tasks/jobs/WorkManager.java +++ b/app/src/main/java/org/tasks/jobs/WorkManager.java @@ -55,6 +55,7 @@ public class WorkManager { private static final String TAG_MIDNIGHT_REFRESH = "tag_midnight_refresh"; private static final String TAG_SYNC = "tag_sync"; private static final String TAG_BACKGROUND_SYNC = "tag_background_sync"; + private static final String TAG_REMOTE_CONFIG = "tag_remote_config"; private final Context context; private final Preferences preferences; @@ -211,6 +212,18 @@ public class WorkManager { Math.min(newDateTime(lastBackup).plusDays(1).getMillis(), midnight())); } + public void scheduleConfigRefresh() { + workManager.enqueueUniquePeriodicWork( + TAG_REMOTE_CONFIG, + ExistingPeriodicWorkPolicy.KEEP, + new PeriodicWorkRequest.Builder( + RemoteConfigWork.class, RemoteConfigWork.WORK_INTERVAL_HOURS, TimeUnit.HOURS) + .setBackoffCriteria(BackoffPolicy.EXPONENTIAL, 1, TimeUnit.MINUTES) + .setConstraints( + new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build()) + .build()); + } + public void scheduleDriveUpload(Uri uri, boolean purge) { if (!preferences.getBoolean(R.string.p_google_drive_backup, false)) { return; diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index feb7852f9..3d16d668f 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -9,6 +9,7 @@ object Versions { const val room = "2.2.5" const val crashlytics = "2.10.1" const val analytics = "17.4.0" + const val remote_config = "19.1.4" const val okhttp = "3.12.10" // 3.13 minSdk is 21 const val flipper = "0.40.0" } \ No newline at end of file