Twidere-App-Android-Twitter.../twidere/src/main/kotlin/org/mariotaku/twidere/model/analyzer/PurchaseFinished.kt

41 lines
1.3 KiB
Kotlin
Raw Normal View History

2017-01-07 11:02:32 +01:00
package org.mariotaku.twidere.model.analyzer
import android.app.Activity
import android.content.Intent
import org.mariotaku.twidere.constant.*
import org.mariotaku.twidere.util.Analyzer
/**
* Created by mariotaku on 2017/1/7.
*/
2017-01-07 12:16:17 +01:00
data class PurchaseFinished(val productName: String) : Analyzer.Event {
override val name: String = "Purchase Finished"
2017-01-07 11:02:32 +01:00
override var accountType: String? = null
var price: Double = Double.NaN
var currency: String? = null
companion object {
const val NAME_EXTRA_FEATURES = "Enhanced Features"
internal fun getFailReason(resultCode: Int): String {
return when (resultCode) {
Activity.RESULT_CANCELED -> "cancelled"
RESULT_SERVICE_UNAVAILABLE -> "service unavailable"
RESULT_INTERNAL_ERROR -> "internal error"
RESULT_NOT_PURCHASED -> "not purchased"
else -> "unknown"
}
}
2017-01-07 12:16:17 +01:00
fun create(name: String, data: Intent?): PurchaseFinished {
val result = PurchaseFinished(name)
2017-01-07 11:02:32 +01:00
if (data != null) {
result.price = data.getDoubleExtra(EXTRA_PRICE, Double.NaN)
result.currency = data.getStringExtra(EXTRA_CURRENCY)
}
return result
}
}
}