Create flavor for F-Droid which doesn't have analytics

This commit is contained in:
Moez Bhatti
2018-01-14 20:47:37 -05:00
parent 3ca5bfe6d7
commit c48db47016
5 changed files with 95 additions and 22 deletions
+12 -2
View File
@@ -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'
}
@@ -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
}
}
+2 -20
View File
@@ -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)
}
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package common.util
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class AnalyticsImpl @Inject constructor() : Analytics {
override fun track(event: String) {
// Do nothing
}
}
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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)
})
}
}