Remove all mentions of analytics

The analytics build configuration has not been used or updated for a while. This removes some dependencies, and some deprecated code sections.
This commit is contained in:
Inhishonor
2025-06-13 10:21:16 -07:00
parent 0eeb643e6f
commit f3b178e182
27 changed files with 49 additions and 681 deletions
+3 -3
View File
@@ -30,7 +30,7 @@ jobs:
- name: Build APK
run: |
./gradlew assembleNoAnalyticsRelease \
./gradlew assembleRelease \
-Pandroid.injected.signing.store.file=${{ github.workspace }}/my-release-key.keystore \
-Pandroid.injected.signing.store.password=${{ secrets.KEYSTORE_PASSWORD }} \
-Pandroid.injected.signing.key.alias=${{ secrets.KEY_ALIAS }} \
@@ -38,13 +38,13 @@ jobs:
--stacktrace
- name: Rename APK
run: mv presentation/build/outputs/apk/noAnalytics/release/QUIK-v*-noAnalytics-release.apk presentation/build/outputs/apk/noAnalytics/release/QUIK-noAnalytics-release.apk
run: mv presentation/build/outputs/apk/release/QUIK-v*-release.apk presentation/build/outputs/apk/release/QUIK-release.apk
- name: Upload APK
uses: actions/upload-artifact@v4
with:
name: apk
path: presentation/build/outputs/apk/noAnalytics/release/QUIK-noAnalytics-release.apk
path: presentation/build/outputs/apk/release/QUIK-release.apk
release:
name: validate fdroid APK
+4 -4
View File
@@ -31,7 +31,7 @@ jobs:
- name: Build APK
run: |
./gradlew assembleNoAnalyticsRelease \
./gradlew assembleRelease \
-Pandroid.injected.signing.store.file=${{ github.workspace }}/my-release-key.keystore \
-Pandroid.injected.signing.store.password=${{ secrets.KEYSTORE_PASSWORD }} \
-Pandroid.injected.signing.key.alias=${{ secrets.KEY_ALIAS }} \
@@ -39,13 +39,13 @@ jobs:
--stacktrace
- name: Rename APK
run: mv presentation/build/outputs/apk/noAnalytics/release/QUIK-v*-noAnalytics-release.apk presentation/build/outputs/apk/noAnalytics/release/QUIK-noAnalytics-release.apk
run: mv presentation/build/outputs/apk/release/QUIK-v*-release.apk presentation/build/outputs/apk/release/QUIK-release.apk
- name: Upload APK
uses: actions/upload-artifact@v4
with:
name: apk
path: presentation/build/outputs/apk/noAnalytics/release/QUIK-noAnalytics-release.apk
path: presentation/build/outputs/apk/release/QUIK-release.apk
release:
name: Release APK
@@ -78,7 +78,7 @@ jobs:
with:
prerelease: true
tag_name: "v${{ env.DATETIME }}"
files: QUIK-noAnalytics-release.apk
files: QUIK-release.apk
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+4 -4
View File
@@ -25,20 +25,20 @@ jobs:
- name: Build with Gradle
run: |
./gradlew assembleNoAnalyticsDebug \
./gradlew assembleDebug \
-Dandroid.injected.signing.store.file=${{ github.workspace }}/my-release-key.keystore
- name: Run Tests
run: ./gradlew test
- name: List APK Output Directory
run: ls -R presentation/build/outputs/apk/noAnalytics/debug
run: ls -R presentation/build/outputs/apk/debug
- name: Rename APK
run: mv presentation/build/outputs/apk/noAnalytics/debug/QUIK-v*-noAnalytics-debug.apk presentation/build/outputs/apk/noAnalytics/debug/QUIK-noAnalytics-debug.apk
run: mv presentation/build/outputs/apk/debug/QUIK-v*-debug.apk presentation/build/outputs/apk/debug/QUIK-debug.apk
- name: Upload App
uses: actions/upload-artifact@v4
with:
name: apk-debug
path: presentation/build/outputs/apk/noAnalytics/debug/QUIK-noAnalytics-debug.apk
path: presentation/build/outputs/apk/debug/QUIK-debug.apk
-7
View File
@@ -23,7 +23,6 @@ apply plugin: 'kotlin-kapt'
android {
compileSdk 34
publishNonDefault true
flavorDimensions "analytics"
compileOptions {
sourceCompatibility 1.8
@@ -38,10 +37,6 @@ android {
buildConfigField "String", "AMPLITUDE_API_KEY", "\"${System.getenv("AMPLITUDE_API_KEY")}\""
}
productFlavors {
withAnalytics { dimension "analytics" }
noAnalytics { dimension "analytics" }
}
namespace 'dev.octoshrimpy.quik.data'
}
@@ -103,8 +98,6 @@ dependencies {
implementation project(':common')
implementation project(':domain')
withAnalyticsImplementation 'com.android.installreferrer:installreferrer:1.1'
withAnalyticsImplementation "com.amplitude:android-sdk:2.16.0"
}
repositories {
@@ -0,0 +1,10 @@
package dev.octoshrimpy.quik.manager
import javax.inject.Inject
class ReferralManagerImpl @Inject constructor() : ReferralManager {
override suspend fun trackReferrer() {
}
}
@@ -19,14 +19,12 @@
package dev.octoshrimpy.quik.mapper
import com.f2prateek.rx.preferences2.RxSharedPreferences
import dev.octoshrimpy.quik.manager.AnalyticsManager
import dev.octoshrimpy.quik.manager.RatingManager
import io.reactivex.rxkotlin.Observables
import javax.inject.Inject
class RatingManagerImpl @Inject constructor(
rxPrefs: RxSharedPreferences,
private val analyticsManager: AnalyticsManager
) : RatingManager {
companion object {
@@ -50,12 +48,10 @@ class RatingManagerImpl @Inject constructor(
}
override fun rate() {
// analyticsManager.track("Clicked Rate")
rated.set(true)
}
override fun dismiss() {
// analyticsManager.track("Clicked Rate (Dismiss)")
dismissed.set(true)
}
@@ -1,42 +0,0 @@
/*
* 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 dev.octoshrimpy.quik.manager
import org.json.JSONObject
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class AnalyticsManagerImpl @Inject constructor() : AnalyticsManager {
override fun track(event: String, vararg properties: Pair<String, Any>) {
// Log the event, but don't do anything else
JSONObject(properties
.associateBy { pair -> pair.first }
.mapValues { pair -> pair.value.second })
.also { Timber.v("$event: $it") }
}
override fun setUserProperty(key: String, value: Any) {
Timber.v("$key: $value")
}
}
@@ -1,29 +0,0 @@
/*
* Copyright (C) 2020 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 dev.octoshrimpy.quik.manager
import javax.inject.Inject
class ReferralManagerImpl @Inject constructor() : ReferralManager {
override suspend fun trackReferrer() {
}
}
@@ -1,74 +0,0 @@
/*
* 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 dev.octoshrimpy.quik.manager
import android.content.Context
import com.amplitude.api.Amplitude
import com.amplitude.api.AmplitudeClient
import com.amplitude.api.Identify
import dev.octoshrimpy.quik.data.BuildConfig
import org.json.JSONArray
import org.json.JSONObject
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class AnalyticsManagerImpl @Inject constructor(context: Context) : AnalyticsManager {
private val amplitude: AmplitudeClient = Amplitude.getInstance().initialize(context, BuildConfig.AMPLITUDE_API_KEY)
init {
amplitude.trackSessionEvents(true)
}
override fun track(event: String, vararg properties: Pair<String, Any>) {
val propertiesJson = JSONObject(properties
.associateBy { pair -> pair.first }
.mapValues { pair -> pair.value.second })
.also { Timber.v("$event: $it") }
amplitude.logEvent(event, propertiesJson)
}
override fun setUserProperty(key: String, value: Any) {
Timber.v("$key: $value")
// Set the value in Amplitude
val identify = Identify()
when (value) {
is Boolean -> identify.set(key, value)
is BooleanArray -> identify.set(key, value)
is Double -> identify.set(key, value)
is DoubleArray -> identify.set(key, value)
is Float -> identify.set(key, value)
is FloatArray -> identify.set(key, value)
is Int -> identify.set(key, value)
is IntArray -> identify.set(key, value)
is Long -> identify.set(key, value)
is LongArray -> identify.set(key, value)
is String -> identify.set(key, value)
is JSONArray -> identify.set(key, value)
is JSONObject -> identify.set(key, value)
else -> Timber.e("Value of type ${value::class.java} not supported")
}
amplitude.identify(identify)
}
}
@@ -1,76 +0,0 @@
/*
* Copyright (C) 2020 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 dev.octoshrimpy.quik.manager
import android.content.Context
import com.android.installreferrer.api.InstallReferrerClient
import com.android.installreferrer.api.InstallReferrerStateListener
import dev.octoshrimpy.quik.util.Preferences
import kotlinx.coroutines.suspendCancellableCoroutine
import javax.inject.Inject
import kotlin.coroutines.resume
class ReferralManagerImpl @Inject constructor(
private val analytics: AnalyticsManager,
private val context: Context,
private val prefs: Preferences
) : ReferralManager {
override suspend fun trackReferrer() {
if (prefs.didSetReferrer.get()) {
return
}
context.packageManager.getInstallerPackageName(context.packageName)?.let { installer ->
analytics.setUserProperty("Installer", installer)
}
val referrerClient = InstallReferrerClient.newBuilder(context).build()
val responseCode = suspendCancellableCoroutine<Int> { cont ->
referrerClient.startConnection(object : InstallReferrerStateListener {
override fun onInstallReferrerSetupFinished(responseCode: Int) {
cont.resume(responseCode)
}
override fun onInstallReferrerServiceDisconnected() {
cont.resume(InstallReferrerClient.InstallReferrerResponse.SERVICE_DISCONNECTED)
}
})
cont.invokeOnCancellation {
referrerClient.endConnection()
}
}
when (responseCode) {
InstallReferrerClient.InstallReferrerResponse.OK -> {
analytics.setUserProperty("Referrer", referrerClient.installReferrer.installReferrer)
prefs.didSetReferrer.set(true)
}
InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED -> {
prefs.didSetReferrer.set(true)
}
}
referrerClient.endConnection()
}
}
@@ -20,11 +20,10 @@ package dev.octoshrimpy.quik.experiment
import android.content.Context
import android.preference.PreferenceManager
import dev.octoshrimpy.quik.manager.AnalyticsManager
import java.util.Locale
import java.util.Random
abstract class Experiment<T>(val context: Context, val analytics: AnalyticsManager) {
abstract class Experiment<T>(val context: Context) {
private val prefs by lazy { PreferenceManager.getDefaultSharedPreferences(context) }
private val prefKey: String
@@ -49,7 +48,6 @@ abstract class Experiment<T>(val context: Context, val analytics: AnalyticsManag
else -> { // Variant hasn't been set yet
variants[Random().nextInt(variants.size)].also { variant ->
analytics.setUserProperty("Experiment: $key", variant.key)
prefs.edit().putString(prefKey, variant.key).apply()
}.value
}
@@ -1,27 +0,0 @@
/*
* 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 dev.octoshrimpy.quik.manager
interface AnalyticsManager {
fun track(event: String, vararg properties: Pair<String, Any>)
fun setUserProperty(key: String, value: Any)
}
+2 -24
View File
@@ -24,7 +24,6 @@ apply plugin: 'kotlin-kapt'
android {
compileSdk 34
flavorDimensions "analytics"
defaultConfig {
applicationId 'dev.octoshrimpy.quik'
@@ -86,12 +85,6 @@ android {
jvmTarget = "1.8"
}
productFlavors {
withAnalytics { dimension "analytics" }
noAnalytics {
}
}
lint {
abortOnError false
}
@@ -108,10 +101,8 @@ androidExtensions {
}
configurations {
noAnalyticsDebug
noAnalyticsRelease
withAnalyticsDebug
withAnalyticsRelease
debug
release
}
dependencies {
@@ -218,20 +209,7 @@ dependencies {
implementation project(':data')
implementation project(':domain')
withAnalyticsImplementation 'com.google.firebase:firebase-crashlytics:17.3.0'
withAnalyticsImplementation "com.android.billingclient:billing:$billing_version"
withAnalyticsImplementation "com.android.billingclient:billing-ktx:$billing_version"
noAnalyticsDebug project(path: ':data', configuration: 'noAnalyticsDebug')
noAnalyticsRelease project(path: ':data', configuration: 'noAnalyticsRelease')
withAnalyticsDebug project(path: ':data', configuration: 'withAnalyticsDebug')
withAnalyticsRelease project(path: ':data', configuration: 'withAnalyticsRelease')
}
if (getGradle().getStartParameter().getTaskRequests().toString().contains("WithAnalytics")) {
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
}
// Check to make sure that the keystore file is present when building a release
gradle.taskGraph.whenReady { taskGraph ->
if ((taskGraph.hasTask(':assembleRelease') ||
@@ -40,7 +40,6 @@ import dev.octoshrimpy.quik.feature.notificationprefs.NotificationPrefsActivity
import dev.octoshrimpy.quik.feature.plus.PlusActivity
import dev.octoshrimpy.quik.feature.scheduled.ScheduledActivity
import dev.octoshrimpy.quik.feature.settings.SettingsActivity
import dev.octoshrimpy.quik.manager.AnalyticsManager
import dev.octoshrimpy.quik.manager.BillingManager
import dev.octoshrimpy.quik.manager.NotificationManager
import dev.octoshrimpy.quik.manager.PermissionManager
@@ -51,7 +50,6 @@ import javax.inject.Singleton
@Singleton
class Navigator @Inject constructor(
private val context: Context,
private val analyticsManager: AnalyticsManager,
private val billingManager: BillingManager,
private val notificationManager: NotificationManager,
private val permissions: PermissionManager
@@ -75,7 +73,6 @@ class Navigator @Inject constructor(
* one of [main_menu, compose_schedule, settings_night, settings_theme]
*/
fun showQksmsPlusActivity(source: String) {
// analyticsManager.track("Viewed QKSMS+", Pair("source", source))
val intent = Intent(context, PlusActivity::class.java)
startActivity(intent)
}
@@ -160,12 +157,10 @@ class Navigator @Inject constructor(
}
fun showBackup() {
// analyticsManager.track("Viewed Backup")
startActivity(Intent(context, BackupActivity::class.java))
}
fun showScheduled() {
// analyticsManager.track("Viewed Scheduled")
val intent = Intent(context, ScheduledActivity::class.java)
startActivity(intent)
}
@@ -264,14 +259,12 @@ class Navigator @Inject constructor(
.append("Device: ${Build.BRAND} ${Build.MODEL}\n")
.append("SDK: ${Build.VERSION.SDK_INT}\n")
.append("Upgraded"
.takeIf { BuildConfig.FLAVOR != "noAnalytics" }
.takeIf { billingManager.upgradeStatus.blockingFirst() } ?: "")
.toString())
startActivityExternal(intent)
}
fun showInvite() {
// analyticsManager.track("Clicked Invite")
Intent(Intent.ACTION_SEND)
.setType("text/plain")
.putExtra(Intent.EXTRA_TEXT, "https://github.com/octoshrimpy/quik/releases/latest")
@@ -36,12 +36,10 @@ import dagger.android.HasActivityInjector
import dagger.android.HasBroadcastReceiverInjector
import dagger.android.HasServiceInjector
import dev.octoshrimpy.quik.R
import dev.octoshrimpy.quik.common.util.CrashlyticsTree
import dev.octoshrimpy.quik.common.util.FileLoggingTree
import dev.octoshrimpy.quik.injection.AppComponentManager
import dev.octoshrimpy.quik.injection.appComponent
import dev.octoshrimpy.quik.interactor.SpeakThreads
import dev.octoshrimpy.quik.manager.AnalyticsManager
import dev.octoshrimpy.quik.manager.BillingManager
import dev.octoshrimpy.quik.manager.ReferralManager
import dev.octoshrimpy.quik.migration.QkMigration
@@ -62,8 +60,6 @@ class QKApplication : Application(), HasActivityInjector, HasBroadcastReceiverIn
* Inject these so that they are forced to initialize
*/
@Suppress("unused")
@Inject lateinit var analyticsManager: AnalyticsManager
@Suppress("unused")
@Inject lateinit var qkMigration: QkMigration
@Inject lateinit var billingManager: BillingManager
@@ -106,7 +102,7 @@ class QKApplication : Application(), HasActivityInjector, HasBroadcastReceiverIn
nightModeManager.updateCurrentTheme()
// configure timber logging
Timber.plant(Timber.DebugTree(), CrashlyticsTree(), fileLoggingTree)
Timber.plant(Timber.DebugTree(), fileLoggingTree)
// configure emoji compatibility with bundled package
// (bundled library works with no play-services/gsm os versions)
@@ -0,0 +1,21 @@
package dev.octoshrimpy.quik.common.util
import android.app.Activity
import dev.octoshrimpy.quik.manager.BillingManager
import io.reactivex.Observable
import io.reactivex.subjects.BehaviorSubject
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class BillingManagerImpl @Inject constructor(
): BillingManager {
override val products: Observable<List<BillingManager.Product>> = BehaviorSubject.createDefault(listOf())
override val upgradeStatus: Observable<Boolean> = BehaviorSubject.createDefault(true)
override suspend fun checkForPurchases() = Unit
override suspend fun queryProducts() = Unit
override suspend fun initiatePurchaseFlow(activity: Activity, sku: String) = Unit
}
@@ -11,7 +11,6 @@ import dev.octoshrimpy.quik.blocking.QksmsBlockingClient
import dev.octoshrimpy.quik.blocking.ShouldIAnswerBlockingClient
import dev.octoshrimpy.quik.common.Navigator
import dev.octoshrimpy.quik.common.base.QkPresenter
import dev.octoshrimpy.quik.manager.AnalyticsManager
import dev.octoshrimpy.quik.repository.ConversationRepository
import dev.octoshrimpy.quik.util.Preferences
import io.reactivex.Observable
@@ -21,7 +20,6 @@ import io.reactivex.schedulers.Schedulers
import javax.inject.Inject
class BlockingManagerPresenter @Inject constructor(
private val analytics: AnalyticsManager,
private val callBlocker: CallBlockerBlockingClient,
private val callControl: CallControlBlockingClient,
private val context: Context,
@@ -69,7 +67,6 @@ class BlockingManagerPresenter @Inject constructor(
.switchMap { numbers -> qksms.block(numbers).andThen(Observable.just(Unit)) } // Hack
.autoDisposable(view.scope())
.subscribe {
analytics.setUserProperty("Blocking Manager", "QKSMS")
prefs.blockingManager.set(Preferences.BLOCKING_MANAGER_QKSMS)
}
@@ -77,7 +74,6 @@ class BlockingManagerPresenter @Inject constructor(
.filter {
val installed = callBlocker.isAvailable()
if (!installed) {
analytics.track("Install Call Blocker")
navigator.installCallBlocker()
}
@@ -86,7 +82,6 @@ class BlockingManagerPresenter @Inject constructor(
}
.autoDisposable(view.scope())
.subscribe {
analytics.setUserProperty("Blocking Manager", "Call Blocker")
prefs.blockingManager.set(Preferences.BLOCKING_MANAGER_CB)
}
@@ -94,7 +89,6 @@ class BlockingManagerPresenter @Inject constructor(
.filter {
val installed = callControl.isAvailable()
if (!installed) {
analytics.track("Install Call Control")
navigator.installCallControl()
}
@@ -119,7 +113,6 @@ class BlockingManagerPresenter @Inject constructor(
.autoDisposable(view.scope())
.subscribe {
callControl.shouldBlock("callcontrol").blockingGet()
analytics.setUserProperty("Blocking Manager", "Call Control")
prefs.blockingManager.set(Preferences.BLOCKING_MANAGER_CC)
}
@@ -127,7 +120,6 @@ class BlockingManagerPresenter @Inject constructor(
.filter {
val installed = shouldIAnswer.isAvailable()
if (!installed) {
analytics.track("Install SIA")
navigator.installSia()
}
@@ -136,7 +128,6 @@ class BlockingManagerPresenter @Inject constructor(
}
.autoDisposable(view.scope())
.subscribe {
analytics.setUserProperty("Blocking Manager", "SIA")
prefs.blockingManager.set(Preferences.BLOCKING_MANAGER_SIA)
}
}
@@ -21,13 +21,11 @@ package dev.octoshrimpy.quik.feature.main
import android.content.Context
import dev.octoshrimpy.quik.experiment.Experiment
import dev.octoshrimpy.quik.experiment.Variant
import dev.octoshrimpy.quik.manager.AnalyticsManager
import javax.inject.Inject
class DrawerBadgesExperiment @Inject constructor(
context: Context,
analyticsManager: AnalyticsManager
) : Experiment<Boolean>(context, analyticsManager) {
) : Experiment<Boolean>(context) {
override val key: String = "Drawer Badges"
@@ -25,7 +25,6 @@ import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProviders
import com.jakewharton.rxbinding2.view.clicks
import dagger.android.AndroidInjection
import dev.octoshrimpy.quik.BuildConfig
import dev.octoshrimpy.quik.R
import dev.octoshrimpy.quik.common.base.QkThemedActivity
import dev.octoshrimpy.quik.common.util.FontProvider
@@ -102,7 +101,7 @@ class PlusActivity : QkThemedActivity(), PlusView {
upgrade.text = getString(upgradeButtonExperiment.variant, state.upgradePrice, state.currency)
upgradeDonate.text = getString(R.string.qksms_plus_upgrade_donate, state.upgradeDonatePrice, state.currency)
val fdroid = BuildConfig.FLAVOR == "noAnalytics"
val fdroid = true
free.setVisible(fdroid)
toUpgrade.setVisible(!fdroid && !state.upgraded)
@@ -22,14 +22,12 @@ import com.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.autoDisposable
import dev.octoshrimpy.quik.common.Navigator
import dev.octoshrimpy.quik.common.base.QkViewModel
import dev.octoshrimpy.quik.manager.AnalyticsManager
import dev.octoshrimpy.quik.manager.BillingManager
import io.reactivex.Observable
import io.reactivex.rxkotlin.plusAssign
import javax.inject.Inject
class PlusViewModel @Inject constructor(
private val analyticsManager: AnalyticsManager,
private val billingManager: BillingManager,
private val navigator: Navigator
) : QkViewModel<PlusView, PlusState>(PlusState()) {
@@ -55,7 +53,6 @@ class PlusViewModel @Inject constructor(
Observable.merge(
view.upgradeIntent.map { BillingManager.SKU_PLUS },
view.upgradeDonateIntent.map { BillingManager.SKU_PLUS_DONATE })
// .doOnNext { sku -> analyticsManager.track("Clicked Upgrade", Pair("sku", sku)) }
.autoDisposable(view.scope())
.subscribe { sku -> view.initiatePurchaseFlow(billingManager, sku) }
@@ -22,13 +22,11 @@ import android.content.Context
import dev.octoshrimpy.quik.R
import dev.octoshrimpy.quik.experiment.Experiment
import dev.octoshrimpy.quik.experiment.Variant
import dev.octoshrimpy.quik.manager.AnalyticsManager
import javax.inject.Inject
class UpgradeButtonExperiment @Inject constructor(
context: Context,
analytics: AnalyticsManager
) : Experiment<Int>(context, analytics) {
) : Experiment<Int>(context) {
override val key: String = "Upgrade Button"
@@ -29,7 +29,6 @@ import dev.octoshrimpy.quik.common.util.DateFormatter
import dev.octoshrimpy.quik.common.util.extensions.makeToast
import dev.octoshrimpy.quik.interactor.DeleteOldMessages
import dev.octoshrimpy.quik.interactor.SyncMessages
import dev.octoshrimpy.quik.manager.AnalyticsManager
import dev.octoshrimpy.quik.manager.BillingManager
import dev.octoshrimpy.quik.repository.MessageRepository
import dev.octoshrimpy.quik.repository.SyncRepository
@@ -47,7 +46,6 @@ import javax.inject.Inject
class SettingsPresenter @Inject constructor(
colors: Colors,
syncRepo: SyncRepository,
private val analytics: AnalyticsManager,
private val context: Context,
private val billingManager: BillingManager,
private val dateFormatter: DateFormatter,
@@ -205,7 +203,6 @@ class SettingsPresenter @Inject constructor(
R.id.textSize -> view.showTextSizePicker()
R.id.autoColor -> {
analytics.setUserProperty("Preference: Auto Color", !prefs.autoColor.get())
prefs.autoColor.set(!prefs.autoColor.get())
}
@@ -44,8 +44,6 @@ import dev.octoshrimpy.quik.manager.ActiveConversationManager
import dev.octoshrimpy.quik.manager.ActiveConversationManagerImpl
import dev.octoshrimpy.quik.manager.AlarmManager
import dev.octoshrimpy.quik.manager.AlarmManagerImpl
import dev.octoshrimpy.quik.manager.AnalyticsManager
import dev.octoshrimpy.quik.manager.AnalyticsManagerImpl
import dev.octoshrimpy.quik.manager.BillingManager
import dev.octoshrimpy.quik.manager.ChangelogManager
import dev.octoshrimpy.quik.manager.ChangelogManagerImpl
@@ -143,9 +141,6 @@ class AppModule(private var application: Application) {
@Provides
fun provideAlarmManager(manager: AlarmManagerImpl): AlarmManager = manager
@Provides
fun provideAnalyticsManager(manager: AnalyticsManagerImpl): AnalyticsManager = manager
@Provides
fun blockingClient(manager: BlockingManager): BlockingClient = manager
@@ -1,39 +0,0 @@
/*
* Copyright (C) 2020 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 dev.octoshrimpy.quik.common.util
import android.app.Activity
import dev.octoshrimpy.quik.manager.BillingManager
import io.reactivex.Observable
import io.reactivex.subjects.BehaviorSubject
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class BillingManagerImpl @Inject constructor(
): BillingManager {
override val products: Observable<List<BillingManager.Product>> = BehaviorSubject.createDefault(listOf())
override val upgradeStatus: Observable<Boolean> = BehaviorSubject.createDefault(true)
override suspend fun checkForPurchases() = Unit
override suspend fun queryProducts() = Unit
override suspend fun initiatePurchaseFlow(activity: Activity, sku: String) = Unit
}
@@ -1,29 +0,0 @@
/*
* 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 dev.octoshrimpy.quik.common.util
import timber.log.Timber
class CrashlyticsTree : Timber.Tree() {
override fun log(priority: Int, tag: String?, message: String?, throwable: Throwable?) {
// Do nothing for noAnalytics build flavor
}
}
@@ -1,234 +0,0 @@
/*
* Copyright (C) 2020 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 dev.octoshrimpy.quik.common.util
import android.app.Activity
import android.content.Context
import com.android.billingclient.api.AcknowledgePurchaseParams
import com.android.billingclient.api.BillingClient
import com.android.billingclient.api.BillingClientStateListener
import com.android.billingclient.api.BillingFlowParams
import com.android.billingclient.api.BillingResult
import com.android.billingclient.api.ProductDetails
import com.android.billingclient.api.Purchase
import com.android.billingclient.api.Purchase.PurchaseState
import com.android.billingclient.api.PurchasesUpdatedListener
import com.android.billingclient.api.QueryProductDetailsParams
import com.android.billingclient.api.QueryPurchaseHistoryParams
import com.android.billingclient.api.QueryPurchasesParams
import com.android.billingclient.api.acknowledgePurchase
import com.android.billingclient.api.queryProductDetails
import com.android.billingclient.api.queryPurchaseHistory
import com.android.billingclient.api.queryPurchasesAsync
import dev.octoshrimpy.quik.manager.AnalyticsManager
import dev.octoshrimpy.quik.manager.BillingManager
import io.reactivex.Observable
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.Subject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class BillingManagerImpl @Inject constructor(
context: Context,
private val analyticsManager: AnalyticsManager
) : BillingManager, BillingClientStateListener, PurchasesUpdatedListener {
private val productsSubject: Subject<List<ProductDetails>> = BehaviorSubject.create()
override val products: Observable<List<BillingManager.Product>> = productsSubject
.map { productDetailsList ->
productDetailsList.map { productDetails ->
BillingManager.Product(
sku = productDetails.productId,
price = productDetails.oneTimePurchaseOfferDetails!!.formattedPrice,
priceCurrencyCode = productDetails.oneTimePurchaseOfferDetails!!.priceCurrencyCode
)
}
}
private val purchaseListSubject = BehaviorSubject.create<List<Purchase>>()
override val upgradeStatus: Observable<Boolean> = purchaseListSubject
.map { purchases ->
purchases
.filter { it.purchaseState == Purchase.PurchaseState.PURCHASED }
.flatMap { it.products }
.any { it in skus }
}
.distinctUntilChanged()
.doOnNext { upgraded -> analyticsManager.setUserProperty("Upgraded", upgraded) }
private val skus = listOf(BillingManager.SKU_PLUS, BillingManager.SKU_PLUS_DONATE)
private val billingClient: BillingClient = BillingClient.newBuilder(context)
.setListener(this)
.enablePendingPurchases()
.build()
private val billingClientState = MutableSharedFlow<Int>(
replay = 1,
onBufferOverflow = BufferOverflow.DROP_OLDEST
)
init {
billingClientState.tryEmit(BillingClient.BillingResponseCode.SERVICE_DISCONNECTED)
}
override suspend fun checkForPurchases() = executeServiceRequest {
// Query from the local cache first
queryPurchases()
// Update the cache, then read from it again
queryPurchaseHistory()
queryPurchases()
}
override suspend fun queryProducts() = executeServiceRequest {
val productList = skus.map { sku ->
QueryProductDetailsParams.Product.newBuilder()
.setProductId(sku)
.setProductType(BillingClient.ProductType.INAPP)
.build()
}
val params = QueryProductDetailsParams.newBuilder()
.setProductList(productList)
val result = billingClient.queryProductDetails(params.build())
if (result.billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
productsSubject.onNext(result.productDetailsList.orEmpty())
} else {
Timber.w("Error querying products", result.billingResult)
}
}
override suspend fun initiatePurchaseFlow(activity: Activity, sku: String) = executeServiceRequest {
val queryProductDetailsParams = QueryProductDetailsParams.newBuilder()
.setProductList(listOf(
QueryProductDetailsParams.Product.newBuilder()
.setProductId(sku)
.setProductType(BillingClient.ProductType.INAPP)
.build()
))
.build()
val productDetailsResult = withContext(Dispatchers.IO) {
billingClient.queryProductDetails(queryProductDetailsParams)
}
if (productDetailsResult.billingResult.responseCode != BillingClient.BillingResponseCode.OK) {
Timber.w("Error querying product details", productDetailsResult.billingResult)
return@executeServiceRequest
}
val productDetailsParams = BillingFlowParams.ProductDetailsParams.newBuilder()
.setProductDetails(productDetailsResult.productDetailsList!!.first())
.build()
val billingFlowParams = BillingFlowParams.newBuilder()
.setProductDetailsParamsList(listOf(productDetailsParams))
.build()
billingClient.launchBillingFlow(activity, billingFlowParams)
}
override fun onPurchasesUpdated(result: BillingResult, purchases: List<Purchase>?) {
if (result.responseCode == BillingClient.BillingResponseCode.OK) {
GlobalScope.launch(Dispatchers.IO) {
handlePurchases(purchases.orEmpty())
}
} else {
Timber.w("Error purchasing", result)
}
}
/**
* Queries the local purchases saved in Google Play's cache
*/
private suspend fun queryPurchases() {
val params = QueryPurchasesParams.newBuilder()
.setProductType(BillingClient.ProductType.INAPP)
.build()
val result = billingClient.queryPurchasesAsync(params)
if (result.billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
handlePurchases(result.purchasesList)
} else {
Timber.w("Error checking for purchases", result.billingResult)
}
}
/**
* Fetches the list of purchases and updates the local cache
*/
private suspend fun queryPurchaseHistory() {
val params = QueryPurchaseHistoryParams.newBuilder()
.setProductType(BillingClient.ProductType.INAPP)
.build()
val result = billingClient.queryPurchaseHistory(params)
if (result.billingResult.responseCode != BillingClient.BillingResponseCode.OK) {
Timber.w("Error querying purchase history", result.billingResult)
return
}
}
private suspend fun handlePurchases(purchases: List<Purchase>) = executeServiceRequest {
purchases.forEach { purchase ->
if (!purchase.isAcknowledged && purchase.purchaseState == PurchaseState.PURCHASED) {
val params = AcknowledgePurchaseParams.newBuilder()
.setPurchaseToken(purchase.purchaseToken)
.build()
Timber.i("Acknowledging purchase ${purchase.orderId}")
val result = billingClient.acknowledgePurchase(params)
Timber.i("Acknowledgement result: ${result.responseCode}, ${result.debugMessage}")
}
}
purchaseListSubject.onNext(purchases)
}
private suspend fun executeServiceRequest(runnable: suspend () -> Unit) {
if (billingClientState.first() != BillingClient.BillingResponseCode.OK) {
Timber.i("Starting billing service")
billingClient.startConnection(this)
}
billingClientState.first { state -> state == BillingClient.BillingResponseCode.OK }
runnable()
}
override fun onBillingSetupFinished(result: BillingResult) {
Timber.i("Billing response: ${result.responseCode}")
billingClientState.tryEmit(result.responseCode)
}
override fun onBillingServiceDisconnected() {
Timber.i("Billing service disconnected")
billingClientState.tryEmit(BillingClient.BillingResponseCode.SERVICE_DISCONNECTED)
}
}
@@ -1,42 +0,0 @@
/*
* 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 dev.octoshrimpy.quik.common.util
import android.util.Log
import com.google.firebase.crashlytics.FirebaseCrashlytics
import timber.log.Timber
class CrashlyticsTree : Timber.Tree() {
override fun log(priority: Int, tag: String?, message: String?, throwable: Throwable?) {
val crashlytics = FirebaseCrashlytics.getInstance()
val priorityString = when (priority) {
Log.VERBOSE -> "V"
Log.DEBUG -> "D"
Log.INFO -> "I"
Log.WARN -> "W"
Log.ERROR -> "E"
else -> "WTF"
}
crashlytics.log("$priorityString/$tag: $message")
throwable?.run(crashlytics::recordException)
}
}