From c48db47016cd71444df997db735cb0d1e9ce68a0 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sun, 14 Jan 2018 20:47:37 -0500 Subject: [PATCH] Create flavor for F-Droid which doesn't have analytics --- qksms/build.gradle | 14 +++++- qksms/src/main/java/common/di/AppModule.kt | 7 +++ qksms/src/main/java/common/util/Analytics.kt | 22 +--------- .../java/common/util/AnalyticsImpl.kt | 31 +++++++++++++ .../java/common/util/AnalyticsImpl.kt | 43 +++++++++++++++++++ 5 files changed, 95 insertions(+), 22 deletions(-) create mode 100644 qksms/src/noAnalytics/java/common/util/AnalyticsImpl.kt create mode 100644 qksms/src/withAnalytics/java/common/util/AnalyticsImpl.kt diff --git a/qksms/build.gradle b/qksms/build.gradle index 30b6907f..809e4126 100644 --- a/qksms/build.gradle +++ b/qksms/build.gradle @@ -7,6 +7,8 @@ apply plugin: 'kotlin-kapt' android { compileSdkVersion 27 buildToolsVersion "27.0.2" + flavorDimensions "analytics" + defaultConfig { applicationId "com.moez.QKSMS" minSdkVersion 21 @@ -19,6 +21,7 @@ android { buildConfigField "String", "BUGSNAG_API_KEY", "\"${System.getenv("BUGSNAG_API_KEY")}\"" buildConfigField "String", "MIXPANEL_API_KEY", "\"${System.getenv("MIXPANEL_API_KEY")}\"" } + buildTypes { release { minifyEnabled false @@ -28,13 +31,20 @@ android { applicationIdSuffix ".debug" } } + compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + lintOptions { abortOnError false } + + productFlavors { + withAnalytics { dimension "analytics" } + noAnalytics { dimension "analytics" } + } } dependencies { @@ -43,7 +53,6 @@ dependencies { }) compile "android.arch.lifecycle:extensions:1.0.0" compile "android.arch.lifecycle:runtime:1.0.3" - compile 'com.amplitude:android-sdk:2.16.0' compile 'com.android.support:appcompat-v7:27.0.2' compile 'com.android.support.constraint:constraint-layout:1.1.0-beta4' compile 'com.android.support:design:27.0.2' @@ -55,7 +64,6 @@ dependencies { compile 'com.jakewharton.rxbinding2:rxbinding-kotlin:2.0.0' compile 'com.jakewharton.rxbinding2:rxbinding-support-v4-kotlin:2.0.0' compile 'com.jakewharton.timber:timber:4.5.1' - compile 'com.mixpanel.android:mixpanel-android:5.2.1' compile 'com.mlsdev.rximagepicker:library:2.0.2' compile 'com.uber.autodispose:autodispose-android-archcomponents-kotlin:0.5.1' compile 'com.uber.autodispose:autodispose-android-archcomponents-test-kotlin:0.5.1' @@ -76,4 +84,6 @@ dependencies { testCompile 'junit:junit:4.12' testCompile 'org.mockito:mockito-core:1.10.19' provided 'javax.annotation:jsr250-api:1.0' + withAnalyticsCompile 'com.amplitude:android-sdk:2.16.0' + withAnalyticsCompile 'com.mixpanel.android:mixpanel-android:5.2.1' } diff --git a/qksms/src/main/java/common/di/AppModule.kt b/qksms/src/main/java/common/di/AppModule.kt index 2dd33fe8..15ca34cc 100644 --- a/qksms/src/main/java/common/di/AppModule.kt +++ b/qksms/src/main/java/common/di/AppModule.kt @@ -22,6 +22,8 @@ import android.app.Application import android.content.Context import android.preference.PreferenceManager import com.f2prateek.rx.preferences2.RxSharedPreferences +import common.util.Analytics +import common.util.AnalyticsImpl import dagger.Module import dagger.Provides import javax.inject.Singleton @@ -42,4 +44,9 @@ class AppModule(private var application: Application) { return RxSharedPreferences.create(preferences) } + @Provides + fun provideAnalytics(analytics: AnalyticsImpl): Analytics { + return analytics + } + } \ No newline at end of file diff --git a/qksms/src/main/java/common/util/Analytics.kt b/qksms/src/main/java/common/util/Analytics.kt index d3344323..12b56077 100644 --- a/qksms/src/main/java/common/util/Analytics.kt +++ b/qksms/src/main/java/common/util/Analytics.kt @@ -18,26 +18,8 @@ */ package common.util -import android.content.Context -import com.amplitude.api.Amplitude -import com.amplitude.api.AmplitudeClient -import com.mixpanel.android.mpmetrics.MixpanelAPI -import com.moez.QKSMS.BuildConfig -import javax.inject.Inject -import javax.inject.Singleton +interface Analytics { -@Singleton -class Analytics @Inject constructor(context: Context) { - - private val amplitude: AmplitudeClient = Amplitude.getInstance().initialize(context, BuildConfig.AMPLITUDE_API_KEY) - private val mixpanel: MixpanelAPI = MixpanelAPI.getInstance(context, BuildConfig.MIXPANEL_API_KEY) - - fun track(event: String) { - amplitude.logEvent(event) - - synchronized(mixpanel, { - mixpanel.track(event) - }) - } + fun track(event: String) } \ No newline at end of file diff --git a/qksms/src/noAnalytics/java/common/util/AnalyticsImpl.kt b/qksms/src/noAnalytics/java/common/util/AnalyticsImpl.kt new file mode 100644 index 00000000..fa6f9734 --- /dev/null +++ b/qksms/src/noAnalytics/java/common/util/AnalyticsImpl.kt @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * This file is part of QKSMS. + * + * QKSMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * QKSMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with QKSMS. If not, see . + */ +package common.util + +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class AnalyticsImpl @Inject constructor() : Analytics { + + override fun track(event: String) { + // Do nothing + } + +} diff --git a/qksms/src/withAnalytics/java/common/util/AnalyticsImpl.kt b/qksms/src/withAnalytics/java/common/util/AnalyticsImpl.kt new file mode 100644 index 00000000..6c16efd2 --- /dev/null +++ b/qksms/src/withAnalytics/java/common/util/AnalyticsImpl.kt @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * This file is part of QKSMS. + * + * QKSMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * QKSMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with QKSMS. If not, see . + */ +package common.util + +import android.content.Context +import com.amplitude.api.Amplitude +import com.amplitude.api.AmplitudeClient +import com.mixpanel.android.mpmetrics.MixpanelAPI +import com.moez.QKSMS.BuildConfig +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class AnalyticsImpl @Inject constructor(context: Context): Analytics { + + private val amplitude: AmplitudeClient = Amplitude.getInstance().initialize(context, BuildConfig.AMPLITUDE_API_KEY) + private val mixpanel: MixpanelAPI = MixpanelAPI.getInstance(context, BuildConfig.MIXPANEL_API_KEY) + + override fun track(event: String) { + amplitude.logEvent(event) + + synchronized(mixpanel, { + mixpanel.track(event) + }) + } + +}