improved analyzer events
This commit is contained in:
parent
ac7af6abac
commit
dd815fef84
|
@ -59,7 +59,7 @@ class GooglePlayInAppPurchaseActivity : BaseActivity(), BillingProcessor.IBillin
|
|||
override fun onBillingInitialized() {
|
||||
// See https://github.com/anjlab/android-inapp-billing-v3/issues/156
|
||||
if (intent.action == ACTION_RESTORE_PURCHASE) {
|
||||
performRestorePurchase()
|
||||
getProductDetailsAndFinish()
|
||||
} else {
|
||||
billingProcessor.purchase(this, productId)
|
||||
}
|
||||
|
@ -91,10 +91,11 @@ class GooglePlayInAppPurchaseActivity : BaseActivity(), BillingProcessor.IBillin
|
|||
finish()
|
||||
}
|
||||
|
||||
private fun performRestorePurchase() {
|
||||
|
||||
private fun getProductDetailsAndFinish() {
|
||||
executeAfterFragmentResumed {
|
||||
val weakThis = WeakReference(it as GooglePlayInAppPurchaseActivity)
|
||||
val dfRef = WeakReference(ProgressDialogFragment.show(it.supportFragmentManager, "consume_purchase_progress"))
|
||||
val dfRef = WeakReference(ProgressDialogFragment.show(it.supportFragmentManager, TAG_PURCHASE_PROCESS))
|
||||
task {
|
||||
val activity = weakThis.get() ?: throw PurchaseException(BILLING_RESPONSE_RESULT_USER_CANCELED)
|
||||
val productId = activity.productId
|
||||
|
@ -116,38 +117,7 @@ class GooglePlayInAppPurchaseActivity : BaseActivity(), BillingProcessor.IBillin
|
|||
}.alwaysUi {
|
||||
weakThis.get()?.executeAfterFragmentResumed {
|
||||
val fm = weakThis.get()?.supportFragmentManager
|
||||
val df = dfRef.get() ?: (fm?.findFragmentByTag("consume_purchase_progress") as? DialogFragment)
|
||||
df?.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getProductDetailsAndFinish() {
|
||||
executeAfterFragmentResumed {
|
||||
val weakThis = WeakReference(it as GooglePlayInAppPurchaseActivity)
|
||||
val dfRef = WeakReference(ProgressDialogFragment.show(it.supportFragmentManager, "consume_purchase_progress"))
|
||||
task {
|
||||
val activity = weakThis.get() ?: throw PurchaseException(BILLING_RESPONSE_RESULT_USER_CANCELED)
|
||||
val bp = activity.billingProcessor
|
||||
bp.loadOwnedPurchasesFromGoogle()
|
||||
val skuDetails = bp.getPurchaseListingDetails(productId)
|
||||
?: throw PurchaseException(BILLING_RESPONSE_RESULT_ERROR)
|
||||
val transactionDetails = bp.getPurchaseTransactionDetails(productId)
|
||||
?: throw PurchaseException(BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED)
|
||||
return@task Pair(skuDetails, transactionDetails)
|
||||
}.successUi { result ->
|
||||
weakThis.get()?.handlePurchased(result.first, result.second)
|
||||
}.failUi { error ->
|
||||
if (error is PurchaseException) {
|
||||
weakThis.get()?.handleError(error.code)
|
||||
} else {
|
||||
weakThis.get()?.handleError(BILLING_RESPONSE_RESULT_ERROR)
|
||||
}
|
||||
}.alwaysUi {
|
||||
weakThis.get()?.executeAfterFragmentResumed {
|
||||
val fm = weakThis.get()?.supportFragmentManager
|
||||
val df = dfRef.get() ?: (fm?.findFragmentByTag("consume_purchase_progress") as? DialogFragment)
|
||||
val df = dfRef.get() ?: (fm?.findFragmentByTag(TAG_PURCHASE_PROCESS) as? DialogFragment)
|
||||
df?.dismiss()
|
||||
}
|
||||
}
|
||||
|
@ -170,6 +140,8 @@ class GooglePlayInAppPurchaseActivity : BaseActivity(), BillingProcessor.IBillin
|
|||
class PurchaseException(val code: Int) : Exception()
|
||||
|
||||
companion object {
|
||||
private const val TAG_PURCHASE_PROCESS = "get_purchase_process"
|
||||
|
||||
const val EXTRA_PRODUCT_ID = "product_id"
|
||||
const val ACTION_RESTORE_PURCHASE = "${INTENT_PACKAGE_PREFIX}RESTORE_PURCHASE"
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.mariotaku.twidere.util
|
|||
import android.accounts.Account
|
||||
import android.accounts.AccountManager
|
||||
import android.accounts.OnAccountsUpdateListener
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
import android.os.Build
|
||||
import com.crashlytics.android.Crashlytics
|
||||
|
@ -33,10 +32,7 @@ import org.mariotaku.ktextension.configure
|
|||
import org.mariotaku.twidere.BuildConfig
|
||||
import org.mariotaku.twidere.Constants
|
||||
import org.mariotaku.twidere.TwidereConstants.ACCOUNT_TYPE
|
||||
import org.mariotaku.twidere.model.analyzer.Purchase
|
||||
import org.mariotaku.twidere.model.analyzer.Search
|
||||
import org.mariotaku.twidere.model.analyzer.Share
|
||||
import org.mariotaku.twidere.model.analyzer.SignIn
|
||||
import org.mariotaku.twidere.model.analyzer.*
|
||||
import java.math.BigDecimal
|
||||
import java.util.*
|
||||
|
||||
|
@ -85,10 +81,23 @@ class FabricAnalyzer : Analyzer(), Constants {
|
|||
putAttributes(event)
|
||||
})
|
||||
}
|
||||
is Purchase -> {
|
||||
is PurchaseConfirm -> {
|
||||
answers.logStartCheckout(configure(StartCheckoutEvent()) {
|
||||
event.forEachValues { name, value ->
|
||||
putCustomAttribute(name, value)
|
||||
}
|
||||
})
|
||||
}
|
||||
is PurchaseIntroduction -> {
|
||||
answers.logAddToCart(configure(AddToCartEvent()) {
|
||||
event.forEachValues { name, value ->
|
||||
putCustomAttribute(name, value)
|
||||
}
|
||||
})
|
||||
}
|
||||
is PurchaseFinished -> {
|
||||
answers.logPurchase(configure(PurchaseEvent()) {
|
||||
putItemName(event.productName)
|
||||
putSuccess(event.resultCode == Activity.RESULT_OK)
|
||||
if (!event.price.isNaN() && event.currency != null) {
|
||||
putCurrency(Currency.getInstance(event.currency) ?: Currency.getInstance(Locale.getDefault()))
|
||||
putItemPrice(BigDecimal(event.price))
|
||||
|
|
|
@ -6,8 +6,7 @@ import org.mariotaku.twidere.model.ParcelableMedia
|
|||
* Created by mariotaku on 2017/1/7.
|
||||
*/
|
||||
|
||||
fun parcelableMediaTypeString(@ParcelableMedia.Type type: Int): String {
|
||||
if (type <= 0) return "none"
|
||||
fun parcelableMediaTypeString(@ParcelableMedia.Type type: Int): String? {
|
||||
return when (type) {
|
||||
ParcelableMedia.Type.IMAGE -> "image"
|
||||
ParcelableMedia.Type.VIDEO -> "video"
|
||||
|
@ -15,6 +14,6 @@ fun parcelableMediaTypeString(@ParcelableMedia.Type type: Int): String {
|
|||
ParcelableMedia.Type.CARD_ANIMATED_GIF -> "gif"
|
||||
ParcelableMedia.Type.EXTERNAL_PLAYER -> "external"
|
||||
ParcelableMedia.Type.VARIABLE_TYPE -> "variable"
|
||||
else -> "unknown"
|
||||
else -> null
|
||||
}
|
||||
}
|
|
@ -6,4 +6,4 @@ import org.mariotaku.twidere.model.ParcelableStatus
|
|||
* Created by mariotaku on 2017/1/7.
|
||||
*/
|
||||
val ParcelableStatus.media_type: Int
|
||||
get() = (media ?: quoted_media)?.firstOrNull()?.type ?: 0
|
||||
get() = media?.firstOrNull()?.type ?: 0
|
|
@ -6,6 +6,10 @@ import android.support.v7.app.AlertDialog
|
|||
import android.view.View
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_REQUEST_CODE
|
||||
import org.mariotaku.twidere.model.analyzer.PurchaseConfirm
|
||||
import org.mariotaku.twidere.model.analyzer.PurchaseFinished
|
||||
import org.mariotaku.twidere.model.analyzer.PurchaseIntroduction
|
||||
import org.mariotaku.twidere.util.Analyzer
|
||||
import org.mariotaku.twidere.util.premium.ExtraFeaturesService
|
||||
|
||||
/**
|
||||
|
@ -36,6 +40,7 @@ class ExtraFeaturesIntroductionDialogFragment : BaseDialogFragment() {
|
|||
} else {
|
||||
activity.startActivityForResult(purchaseIntent, requestCode)
|
||||
}
|
||||
Analyzer.log(PurchaseConfirm(PurchaseFinished.NAME_EXTRA_FEATURES))
|
||||
}
|
||||
builder.setNegativeButton(R.string.action_later) { dialog, which ->
|
||||
|
||||
|
@ -55,6 +60,9 @@ class ExtraFeaturesIntroductionDialogFragment : BaseDialogFragment() {
|
|||
View.GONE
|
||||
}
|
||||
}
|
||||
if (savedInstanceState == null) {
|
||||
Analyzer.log(PurchaseIntroduction(PurchaseFinished.NAME_EXTRA_FEATURES, "introduction dialog"))
|
||||
}
|
||||
return dialog
|
||||
}
|
||||
}
|
||||
|
|
|
@ -437,7 +437,10 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
|
|||
event.isHasTranslateFeature = false
|
||||
}
|
||||
statusEvent = event
|
||||
Analyzer.log(StatusView(details?.type, status.media_type))
|
||||
Analyzer.log(StatusView(details?.type, status.media_type).apply {
|
||||
this.type = StatusView.getStatusType(status)
|
||||
this.source = HtmlEscapeHelper.toPlainText(status.source)
|
||||
})
|
||||
} else if (readPosition != null) {
|
||||
restoreReadPosition(readPosition)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.mariotaku.twidere.fragment.filter
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.database.Cursor
|
||||
|
@ -28,7 +29,7 @@ import org.mariotaku.twidere.fragment.ExtraFeaturesIntroductionDialogFragment
|
|||
import org.mariotaku.twidere.model.ParcelableUser
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.`FiltersData$UserItemCursorIndices`
|
||||
import org.mariotaku.twidere.model.analyzer.Purchase
|
||||
import org.mariotaku.twidere.model.analyzer.PurchaseFinished
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore
|
||||
import org.mariotaku.twidere.util.Analyzer
|
||||
import org.mariotaku.twidere.util.ContentValuesCreator
|
||||
|
@ -91,7 +92,9 @@ class FilteredUsersFragment : BaseFiltersFragment() {
|
|||
startActivityForResult(intent, REQUEST_ADD_USER_SELECT_ACCOUNT)
|
||||
}
|
||||
REQUEST_PURCHASE_EXTRA_FEATURES -> {
|
||||
Analyzer.log(Purchase.fromActivityResult(Purchase.NAME_EXTRA_FEATURES, resultCode, data))
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
Analyzer.log(PurchaseFinished.create(PurchaseFinished.NAME_EXTRA_FEATURES, data))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,9 @@ import org.mariotaku.twidere.R
|
|||
import org.mariotaku.twidere.constant.RESULT_NOT_PURCHASED
|
||||
import org.mariotaku.twidere.constant.RESULT_SERVICE_UNAVAILABLE
|
||||
import org.mariotaku.twidere.fragment.BaseSupportFragment
|
||||
import org.mariotaku.twidere.model.analyzer.Purchase
|
||||
import org.mariotaku.twidere.model.analyzer.PurchaseConfirm
|
||||
import org.mariotaku.twidere.model.analyzer.PurchaseFinished
|
||||
import org.mariotaku.twidere.model.analyzer.PurchaseIntroduction
|
||||
import org.mariotaku.twidere.util.Analyzer
|
||||
import org.mariotaku.twidere.util.premium.ExtraFeaturesService
|
||||
|
||||
|
@ -33,6 +35,7 @@ class ExtraFeaturesIntroductionCardFragment : BaseSupportFragment() {
|
|||
super.onActivityCreated(savedInstanceState)
|
||||
extraFeaturesService = ExtraFeaturesService.newInstance(context)
|
||||
purchaseButton.setOnClickListener {
|
||||
Analyzer.log(PurchaseConfirm(PurchaseFinished.NAME_EXTRA_FEATURES))
|
||||
startActivityForResult(extraFeaturesService.createPurchaseIntent(context), REQUEST_PURCHASE)
|
||||
}
|
||||
val restorePurchaseIntent = extraFeaturesService.createRestorePurchaseIntent(context)
|
||||
|
@ -47,14 +50,17 @@ class ExtraFeaturesIntroductionCardFragment : BaseSupportFragment() {
|
|||
restorePurchaseButton.visibility = View.GONE
|
||||
restorePurchaseButton.setOnClickListener(null)
|
||||
}
|
||||
if (savedInstanceState == null) {
|
||||
Analyzer.log(PurchaseIntroduction(PurchaseFinished.NAME_EXTRA_FEATURES, "enhanced features dashboard"))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
when (requestCode) {
|
||||
REQUEST_PURCHASE -> {
|
||||
Analyzer.log(Purchase.fromActivityResult(Purchase.NAME_EXTRA_FEATURES, resultCode, data))
|
||||
when (resultCode) {
|
||||
Activity.RESULT_OK -> {
|
||||
Analyzer.log(PurchaseFinished.create(PurchaseFinished.NAME_EXTRA_FEATURES, data))
|
||||
activity?.recreate()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package org.mariotaku.twidere.model.analyzer
|
||||
|
||||
import org.mariotaku.twidere.util.Analyzer
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2017/1/7.
|
||||
*/
|
||||
|
||||
data class PurchaseConfirm(val productName: String) : Analyzer.Event {
|
||||
override val name: String = "Purchase Confirm"
|
||||
override val accountType: String? = null
|
||||
override fun forEachValues(action: (String, String?) -> Unit) {
|
||||
action("Product Name", productName)
|
||||
}
|
||||
}
|
|
@ -9,19 +9,12 @@ import org.mariotaku.twidere.util.Analyzer
|
|||
* Created by mariotaku on 2017/1/7.
|
||||
*/
|
||||
|
||||
data class Purchase(val productName: String) : Analyzer.Event {
|
||||
override val name: String = "Purchase"
|
||||
data class PurchaseFinished(val productName: String) : Analyzer.Event {
|
||||
override val name: String = "Purchase Finished"
|
||||
override var accountType: String? = null
|
||||
var resultCode: Int = Activity.RESULT_OK
|
||||
var price: Double = Double.NaN
|
||||
var currency: String? = null
|
||||
|
||||
override fun forEachValues(action: (String, String?) -> Unit) {
|
||||
if (resultCode != Activity.RESULT_OK) {
|
||||
action("Fail reason", getFailReason(resultCode))
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val NAME_EXTRA_FEATURES = "Enhanced Features"
|
||||
|
||||
|
@ -35,9 +28,8 @@ data class Purchase(val productName: String) : Analyzer.Event {
|
|||
}
|
||||
}
|
||||
|
||||
fun fromActivityResult(name: String, resultCode: Int, data: Intent?): Purchase {
|
||||
val result = Purchase(name)
|
||||
result.resultCode = resultCode
|
||||
fun create(name: String, data: Intent?): PurchaseFinished {
|
||||
val result = PurchaseFinished(name)
|
||||
if (data != null) {
|
||||
result.price = data.getDoubleExtra(EXTRA_PRICE, Double.NaN)
|
||||
result.currency = data.getStringExtra(EXTRA_CURRENCY)
|
|
@ -0,0 +1,16 @@
|
|||
package org.mariotaku.twidere.model.analyzer
|
||||
|
||||
import org.mariotaku.twidere.util.Analyzer
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2017/1/7.
|
||||
*/
|
||||
|
||||
data class PurchaseIntroduction(val productName: String, val source: String) : Analyzer.Event {
|
||||
override val name: String = "Purchase Introduction"
|
||||
override val accountType: String? = null
|
||||
override fun forEachValues(action: (String, String?) -> Unit) {
|
||||
action("Product Name", productName)
|
||||
action("Source", source)
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package org.mariotaku.twidere.model.analyzer
|
|||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.extension.model.parcelableMediaTypeString
|
||||
import org.mariotaku.twidere.model.ParcelableMedia
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.util.Analyzer
|
||||
|
||||
/**
|
||||
|
@ -15,8 +16,31 @@ data class StatusView(
|
|||
) : Analyzer.Event {
|
||||
|
||||
override val name: String = "Status View"
|
||||
var type: String? = null
|
||||
var source: String? = null
|
||||
|
||||
override fun forEachValues(action: (String, String?) -> Unit) {
|
||||
action("Media Type", parcelableMediaTypeString(mediaType))
|
||||
val mediaType = parcelableMediaTypeString(mediaType)
|
||||
if (mediaType != null) {
|
||||
action("Media Type", mediaType)
|
||||
}
|
||||
if (type != null) {
|
||||
action("Type", type)
|
||||
}
|
||||
if (source != null) {
|
||||
action("Source", source)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun getStatusType(status: ParcelableStatus): String {
|
||||
if (status.is_retweet) {
|
||||
return "retweet"
|
||||
} else if (status.is_quote) {
|
||||
return "quote"
|
||||
}
|
||||
return "tweet"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue