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