From f7cef139d49ac468cf5d3ad0c828a213541c84d7 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Sun, 7 Apr 2019 00:30:16 -0500 Subject: [PATCH] Fix amazon compile --- app/build.gradle | 11 ++- .../java/org/tasks/analytics/Tracker.java | 93 +++++++------------ .../java/org/tasks/gtasks/PlayServices.java | 11 +++ .../java/org/tasks/location/GeofenceApi.java | 6 ++ .../org/tasks/location/GoogleMapFragment.java | 33 +++++++ .../location/GooglePlacesSearchProvider.java | 34 +++++++ app/src/amazon/res/values/bools.xml | 4 + 7 files changed, 130 insertions(+), 62 deletions(-) create mode 100644 app/src/amazon/java/org/tasks/location/GoogleMapFragment.java create mode 100644 app/src/amazon/java/org/tasks/location/GooglePlacesSearchProvider.java create mode 100644 app/src/amazon/res/values/bools.xml diff --git a/app/build.gradle b/app/build.gradle index dce92aca9..4d7820ab7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -114,7 +114,9 @@ final BUTTERKNIFE_VERSION = '10.1.0' final STETHO_VERSION = '1.5.1' final WORK_VERSION = '2.0.0' final LEAKCANARY_VERSION = '1.6.3' -final ROOM_VERSION = '2.1.0-alpha06' +final ROOM_VERSION = '2.1.0-alpha04' +final CRASHLYTICS_VERSION = '2.9.9' +final FIREBASE_VERSION = '16.0.8' dependencies { implementation project(":dav4android") @@ -176,14 +178,15 @@ dependencies { implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.3.0' implementation'com.mapbox.mapboxsdk:mapbox-sdk-services:4.5.0' - googleplayImplementation 'com.crashlytics.sdk.android:crashlytics:2.9.9' - googleplayImplementation "com.google.firebase:firebase-core:16.0.8" + googleplayImplementation "com.crashlytics.sdk.android:crashlytics:${CRASHLYTICS_VERSION}" + googleplayImplementation "com.google.firebase:firebase-core:${FIREBASE_VERSION}" googleplayImplementation "com.google.android.gms:play-services-location:16.0.0" googleplayImplementation 'com.google.android.gms:play-services-maps:16.1.0' googleplayImplementation "com.google.android.gms:play-services-auth:16.0.1" googleplayImplementation 'com.google.android.libraries.places:places:1.1.0' - amazonImplementation "com.google.android.gms:play-services-analytics:16.0.8" + amazonImplementation "com.crashlytics.sdk.android:crashlytics:${CRASHLYTICS_VERSION}" + amazonImplementation "com.google.firebase:firebase-core:${FIREBASE_VERSION}" androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:${DAGGER_VERSION}" androidTestAnnotationProcessor "com.jakewharton:butterknife-compiler:${BUTTERKNIFE_VERSION}" diff --git a/app/src/amazon/java/org/tasks/analytics/Tracker.java b/app/src/amazon/java/org/tasks/analytics/Tracker.java index 46d5f208e..f291948d8 100644 --- a/app/src/amazon/java/org/tasks/analytics/Tracker.java +++ b/app/src/amazon/java/org/tasks/analytics/Tracker.java @@ -3,70 +3,48 @@ package org.tasks.analytics; import static org.tasks.billing.BillingClient.BillingResponseToString; import android.content.Context; +import android.os.Bundle; import com.android.billingclient.api.BillingClient.BillingResponse; -import com.google.android.gms.analytics.ExceptionParser; -import com.google.android.gms.analytics.ExceptionReporter; -import com.google.android.gms.analytics.GoogleAnalytics; -import com.google.android.gms.analytics.HitBuilders; -import com.google.android.gms.analytics.StandardExceptionParser; -import com.google.common.base.Strings; +import com.crashlytics.android.Crashlytics; +import com.google.firebase.analytics.FirebaseAnalytics; +import com.google.firebase.analytics.FirebaseAnalytics.Event; +import com.google.firebase.analytics.FirebaseAnalytics.Param; +import io.fabric.sdk.android.Fabric; import javax.inject.Inject; -import org.tasks.BuildConfig; -import org.tasks.R; import org.tasks.injection.ApplicationScope; import org.tasks.injection.ForApplication; +import org.tasks.preferences.Preferences; import timber.log.Timber; @ApplicationScope public class Tracker { - private final GoogleAnalytics analytics; - private final com.google.android.gms.analytics.Tracker tracker; - private final ExceptionParser exceptionParser; + private static boolean enabled; + + private final FirebaseAnalytics analytics; private final Context context; @Inject - public Tracker(@ForApplication Context context) { + public Tracker(@ForApplication Context context, Preferences preferences) { this.context = context; - analytics = GoogleAnalytics.getInstance(context); - tracker = analytics.newTracker(R.xml.google_analytics); - tracker.setAppVersion(Integer.toString(BuildConfig.VERSION_CODE)); - final StandardExceptionParser standardExceptionParser = - new StandardExceptionParser(context, null); - exceptionParser = - (thread, throwable) -> { - StringBuilder stack = - new StringBuilder() - .append(standardExceptionParser.getDescription(thread, throwable)) - .append("\n") - .append(throwable.getClass().getName()) - .append("\n"); - for (StackTraceElement element : throwable.getStackTrace()) { - stack.append(element.toString()).append("\n"); - } - return stack.toString(); - }; - ExceptionReporter reporter = - new ExceptionReporter(tracker, Thread.getDefaultUncaughtExceptionHandler(), context); - reporter.setExceptionParser(exceptionParser); - Thread.setDefaultUncaughtExceptionHandler(reporter); + enabled = preferences.isTrackingEnabled(); + if (enabled) { + analytics = FirebaseAnalytics.getInstance(context); + Fabric.with(context, new Crashlytics()); + } else { + analytics = null; + } } - public void setTrackingEnabled(boolean enabled) { - analytics.setAppOptOut(!enabled); + public static void report(Throwable t) { + Timber.e(t); + if (enabled) { + Crashlytics.logException(t); + } } public void reportException(Throwable t) { - reportException(Thread.currentThread(), t); - } - - public void reportException(Thread thread, Throwable t) { - Timber.e(t, t.getMessage()); - tracker.send( - new HitBuilders.ExceptionBuilder() - .setDescription(exceptionParser.getDescription(thread.getName(), t)) - .setFatal(false) - .build()); + report(t); } public void reportEvent(Tracking.Events event) { @@ -85,21 +63,20 @@ public class Tracker { reportEvent(event.category, action, label); } - private void reportEvent(int category, String action, String label) { - HitBuilders.EventBuilder eventBuilder = - new HitBuilders.EventBuilder().setCategory(context.getString(category)).setAction(action); - if (!Strings.isNullOrEmpty(label)) { - eventBuilder.setLabel(label); + private void reportEvent(int categoryRes, String action, String label) { + if (!enabled) { + return; } - tracker.send(eventBuilder.build()); } public void reportIabResult(@BillingResponse int response, String sku) { - tracker.send( - new HitBuilders.EventBuilder() - .setCategory(context.getString(R.string.tracking_category_iab)) - .setAction(sku) - .setLabel(BillingResponseToString(response)) - .build()); + if (!enabled) { + return; + } + + Bundle bundle = new Bundle(); + bundle.putString(Param.ITEM_ID, sku); + bundle.putString(Param.SUCCESS, BillingResponseToString(response)); + analytics.logEvent(Event.ECOMMERCE_PURCHASE, bundle); } } diff --git a/app/src/amazon/java/org/tasks/gtasks/PlayServices.java b/app/src/amazon/java/org/tasks/gtasks/PlayServices.java index 1b6da2c10..38b6d35f8 100644 --- a/app/src/amazon/java/org/tasks/gtasks/PlayServices.java +++ b/app/src/amazon/java/org/tasks/gtasks/PlayServices.java @@ -1,6 +1,10 @@ package org.tasks.gtasks; import android.app.Activity; +import com.todoroo.astrid.activity.MainActivity; +import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity; +import io.reactivex.disposables.Disposable; +import io.reactivex.disposables.Disposables; import javax.inject.Inject; import org.tasks.drive.DriveLoginActivity; import org.tasks.play.AuthResultHandler; @@ -26,4 +30,11 @@ public class PlayServices { public void getDriveAuthToken( DriveLoginActivity driveLoginActivity, String a, AuthResultHandler authResultHandler) {} + + public Disposable check(MainActivity mainActivity) { + return Disposables.empty(); + } + + public void getTasksAuthToken( + GtasksLoginActivity gtasksLoginActivity, String a, AuthResultHandler authResultHandler) {} } diff --git a/app/src/amazon/java/org/tasks/location/GeofenceApi.java b/app/src/amazon/java/org/tasks/location/GeofenceApi.java index e77a061a1..df276cad0 100644 --- a/app/src/amazon/java/org/tasks/location/GeofenceApi.java +++ b/app/src/amazon/java/org/tasks/location/GeofenceApi.java @@ -15,4 +15,10 @@ public class GeofenceApi { public void cancel(Location geofence) {} public void cancel(List geofences) {} + + public void cancel(long taskId) {} + + public void register(long taskId) {} + + public void registerAll() {} } diff --git a/app/src/amazon/java/org/tasks/location/GoogleMapFragment.java b/app/src/amazon/java/org/tasks/location/GoogleMapFragment.java new file mode 100644 index 000000000..343ba1af4 --- /dev/null +++ b/app/src/amazon/java/org/tasks/location/GoogleMapFragment.java @@ -0,0 +1,33 @@ +package org.tasks.location; + +import android.content.Context; +import androidx.fragment.app.FragmentManager; +import java.util.List; +import org.tasks.data.Place; + +public class GoogleMapFragment implements MapFragment { + + public GoogleMapFragment(Context context) {} + + @Override + public void init(FragmentManager fragmentManager, MapFragmentCallback callback, boolean dark) {} + + @Override + public MapPosition getMapPosition() { + return null; + } + + @Override + public void movePosition(MapPosition mapPosition, boolean animate) {} + + @Override + public void setMarkers(List places) {} + + @Override + public void showMyLocation() {} + + @Override + public int getMarkerId() { + return 0; + } +} diff --git a/app/src/amazon/java/org/tasks/location/GooglePlacesSearchProvider.java b/app/src/amazon/java/org/tasks/location/GooglePlacesSearchProvider.java new file mode 100644 index 000000000..7ff0ca69b --- /dev/null +++ b/app/src/amazon/java/org/tasks/location/GooglePlacesSearchProvider.java @@ -0,0 +1,34 @@ +package org.tasks.location; + +import android.content.Context; +import android.os.Bundle; +import java.util.List; +import org.tasks.Callback; +import org.tasks.data.Place; + +public class GooglePlacesSearchProvider implements PlaceSearchProvider { + + public GooglePlacesSearchProvider(Context context) {} + + @Override + public void restoreState(Bundle savedInstanceState) {} + + @Override + public void saveState(Bundle outState) {} + + @Override + public int getAttributionRes(boolean dark) { + return 0; + } + + @Override + public void search( + String query, + MapPosition bias, + Callback> onSuccess, + Callback onError) {} + + @Override + public void fetch( + PlaceSearchResult placeSearchResult, Callback onSuccess, Callback onError) {} +} diff --git a/app/src/amazon/res/values/bools.xml b/app/src/amazon/res/values/bools.xml new file mode 100644 index 000000000..30b01d340 --- /dev/null +++ b/app/src/amazon/res/values/bools.xml @@ -0,0 +1,4 @@ + + + false + \ No newline at end of file