Skip to content

Commit

Permalink
Merge pull request #80 from qonversion/release/2.2.0
Browse files Browse the repository at this point in the history
Release/2.2.0
  • Loading branch information
Maria-Bordunova authored Dec 11, 2020
2 parents bdec36e + 1e5eddf commit a5f7559
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 24 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official

libraryVersion = 2.1.1
libraryVersion = 2.2.0

10 changes: 5 additions & 5 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {

consumerProguardFiles 'consumer-rules.pro'
group = 'com.qonversion.android.sdk'
version = '2.1.1'
version = '2.2.0'
}

buildTypes {
Expand Down Expand Up @@ -56,10 +56,10 @@ bintray {
name = 'com.qonversion.android.sdk'

version {
name = '2.1.1'
name = '2.2.0'
desc = 'qonversion-android-sdk'
released = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZ", Locale.ENGLISH).format(new Date())
vcsTag = '2.1.1'
vcsTag = '2.2.0'
}

licenses = ['MIT']
Expand All @@ -72,7 +72,7 @@ bintray {
MyPublication(MavenPublication) {
groupId 'com.qonversion.android.sdk'
artifactId 'sdk'
version '2.1.1'
version '2.2.0'
}
}
}
Expand Down Expand Up @@ -102,7 +102,7 @@ ext {

PUBLISH_GROUP_ID = 'com.qonversion.android.sdk'
PUBLISH_ARTIFACT_ID = 'sdk'
PUBLISH_VERSION = '2.1.1'
PUBLISH_VERSION = '2.2.0'

kotlinVersion = '1.3.61'
moshiVersion = '1.9.2'
Expand Down
11 changes: 9 additions & 2 deletions sdk/src/main/java/com/qonversion/android/sdk/Qonversion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import com.qonversion.android.sdk.validator.TokenValidator

object Qonversion : LifecycleDelegate {

private const val SDK_VERSION = "2.1.1"
private const val SDK_VERSION = "2.2.0"

private lateinit var repository: QonversionRepository
private var userPropertiesManager: QUserPropertiesManager? = null
private var attributionManager: QAttributionManager? = null
private var productCenterManager: QProductCenterManager? = null
private var logger = ConsoleLogger()
private var isDebugMode = false

init {
val lifecycleHandler = AppLifecycleHandler(this)
Expand Down Expand Up @@ -70,7 +71,8 @@ object Qonversion : LifecycleDelegate {
logger,
environment,
config,
null
null,
isDebugMode
)

this.repository = repository
Expand Down Expand Up @@ -237,6 +239,11 @@ object Qonversion : LifecycleDelegate {
?: logLaunchErrorForFunctionName(object {}.javaClass.enclosingMethod?.name)
}

@JvmStatic
fun setDebugMode() {
isDebugMode = true
}

// Private functions

private fun logLaunchErrorForFunctionName(functionName: String?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Application
import com.android.billingclient.api.PurchaseHistoryRecord
import com.qonversion.android.sdk.api.Api
import com.qonversion.android.sdk.billing.milliSecondsToSeconds
import com.qonversion.android.sdk.billing.stringValue
import com.qonversion.android.sdk.dto.*
import com.qonversion.android.sdk.dto.purchase.History
import com.qonversion.android.sdk.dto.purchase.Inapp
Expand Down Expand Up @@ -33,13 +34,19 @@ class QonversionRepository private constructor(
private val logger: Logger,
private val internalUserId: String?,
private val requestQueue: RequestsQueue,
private val requestValidator: Validator<QonversionRequest>
private val requestValidator: Validator<QonversionRequest>,
private val isDebugMode: Boolean
) {
private var advertisingId: String? = null

// Public functions

fun init(installDate: Long, idfa: String? = null, purchases: List<Purchase>? = null, callback: QonversionLaunchCallback?) {
fun init(
installDate: Long,
idfa: String? = null,
purchases: List<Purchase>? = null,
callback: QonversionLaunchCallback?
) {
advertisingId = idfa
initRequest(installDate, trackingEnabled, key, sdkVersion, idfa, purchases, callback)
}
Expand All @@ -52,7 +59,11 @@ class QonversionRepository private constructor(
purchaseRequest(installDate, purchase, callback)
}

fun restore(installDate: Long, historyRecords: List<PurchaseHistoryRecord>, callback: QonversionPermissionsCallback?) {
fun restore(
installDate: Long,
historyRecords: List<PurchaseHistoryRecord>,
callback: QonversionPermissionsCallback?
) {
restoreRequest(installDate, historyRecords, callback)
}

Expand All @@ -79,7 +90,10 @@ class QonversionRepository private constructor(

// Private functions

private fun createAttributionRequest(conversionInfo: Map<String, Any>, from: String): QonversionRequest {
private fun createAttributionRequest(
conversionInfo: Map<String, Any>,
from: String
): QonversionRequest {
val uid = storage.load()
val tracking = if(trackingEnabled) 1 else 0
return AttributionRequest(
Expand Down Expand Up @@ -140,6 +154,7 @@ class QonversionRepository private constructor(
accessToken = key,
clientUid = uid,
customUid = internalUserId,
debugMode = isDebugMode.stringValue(),
purchase = convertPurchaseDetails(purchase),
introductoryOffer = convertIntroductoryPurchaseDetail(purchase)
)
Expand Down Expand Up @@ -195,7 +210,7 @@ class QonversionRepository private constructor(
}

private fun convertPurchaseDetails(purchase: Purchase): PurchaseDetails {
val purchaseDetail = PurchaseDetails(
return PurchaseDetails(
purchase.productId,
purchase.purchaseToken,
purchase.purchaseTime,
Expand All @@ -207,20 +222,16 @@ class QonversionRepository private constructor(
purchase.periodUnitsCount,
null
)

return purchaseDetail
}

private fun convertHistory(historyRecords: List<PurchaseHistoryRecord>): List<History> {
val histories: List<History> = historyRecords.map {
return historyRecords.map {
History(
it.sku,
it.purchaseToken,
it.purchaseTime.milliSecondsToSeconds()
)
}

return histories
}

private fun restoreRequest(
Expand All @@ -238,6 +249,7 @@ class QonversionRepository private constructor(
accessToken = key,
clientUid = uid,
customUid = internalUserId,
debugMode = isDebugMode.stringValue(),
history = history
)

Expand All @@ -255,7 +267,10 @@ class QonversionRepository private constructor(
}
}

private fun handlePermissionsResponse(response: retrofit2.Response<BaseResponse<QLaunchResult>>, callback: QonversionPermissionsCallback?) {
private fun handlePermissionsResponse(
response: retrofit2.Response<BaseResponse<QLaunchResult>>,
callback: QonversionPermissionsCallback?
) {
val body = response.body()
if (body != null && body.success) {
callback?.onSuccess(body.data.permissions)
Expand Down Expand Up @@ -284,6 +299,7 @@ class QonversionRepository private constructor(
accessToken = key,
clientUid = uid,
customUid = internalUserId,
debugMode = isDebugMode.stringValue(),
purchases = inapps
)

Expand Down Expand Up @@ -347,7 +363,8 @@ class QonversionRepository private constructor(
logger: Logger,
environmentProvider: EnvironmentProvider,
config: QonversionConfig,
internalUserId: String?
internalUserId: String?,
isDebugMode: Boolean
): QonversionRepository {

val client = OkHttpClient.Builder()
Expand Down Expand Up @@ -384,7 +401,8 @@ class QonversionRepository private constructor(
logger,
internalUserId,
requestQueue,
RequestValidator()
RequestValidator(),
isDebugMode
)
}
}
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/main/java/com/qonversion/android/sdk/billing/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ fun Int.toBoolean() = if (this == 0) false else true

fun Boolean.toInt() = if (this) 1 else 0

fun Boolean.stringValue() = if (this) "1" else "0"

fun BillingResult.getDescription() =
"DebugMessage: $debugMessage; ResponseCodeName: ${responseCode.getDescription()}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ data class InitRequest(
@Json(name = "q_uid") override val clientUid: String?,
@Json(name = "custom_uid") override val customUid: String?,
@Json(name = "receipt") override val receipt: String = "",
@Json(name = "debug_mode") override val debugMode: String,
@Json(name = "purchases") val purchases: List<Inapp>? = null
): RequestData()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.qonversion.android.sdk.dto

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import com.qonversion.android.sdk.dto.purchase.Inapp
import com.qonversion.android.sdk.dto.purchase.IntroductoryOfferDetails
import com.qonversion.android.sdk.dto.purchase.PurchaseDetails

Expand All @@ -15,6 +14,7 @@ data class PurchaseRequest(
@Json(name = "q_uid") override val clientUid: String?,
@Json(name = "custom_uid") override val customUid: String?,
@Json(name = "receipt") override val receipt: String = "",
@Json(name = "debug_mode") override val debugMode: String,
@Json(name = "purchase") val purchase: PurchaseDetails,
@Json(name = "introductory_offer") val introductoryOffer: IntroductoryOfferDetails?
): RequestData()
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ abstract class RequestData {
abstract val clientUid: String?
abstract val customUid: String?
abstract val receipt: String
abstract val debugMode: String
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.qonversion.android.sdk.dto

import com.qonversion.android.sdk.dto.purchase.History
import com.qonversion.android.sdk.dto.purchase.Inapp
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

Expand All @@ -14,5 +13,6 @@ data class RestoreRequest(
@Json(name = "q_uid") override val clientUid: String?,
@Json(name = "custom_uid") override val customUid: String?,
@Json(name = "receipt") override val receipt: String = "",
@Json(name = "debug_mode") override val debugMode: String,
@Json(name = "history") val history: List<History>
): RequestData()
1 change: 0 additions & 1 deletion sdk/src/main/java/com/qonversion/android/sdk/errors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ fun <T> Response<T>.toQonversionError(): QonversionError {
val message = "message"
var errorMessage = "failed to parse the backend response"


errorBody()?.let {
try {
val jsonObjError = JSONObject(it.string())
Expand Down

0 comments on commit a5f7559

Please sign in to comment.