Add firebase remote config and update job

pull/996/head
Alex Baker 5 years ago
parent 3a13d56060
commit 243b2fa642

@ -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")

@ -5,4 +5,6 @@ import javax.inject.Inject
class Firebase @Inject constructor() {
fun reportException(t: Throwable) = Timber.e(t)
fun updateRemoteConfig() {}
}

@ -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
})
}
}
}

@ -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();

@ -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);

@ -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);
}

@ -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);

@ -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)
}

@ -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)

@ -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;

@ -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;

@ -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"
}
Loading…
Cancel
Save