mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
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:
@@ -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
|
||||
|
||||
}
|
||||
-9
@@ -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) }
|
||||
|
||||
|
||||
+1
-3
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user