Skip to content

Commit

Permalink
Release 7.4.0
Browse files Browse the repository at this point in the history
Release 7.4.0
  • Loading branch information
SpertsyanKM authored May 6, 2024
2 parents 12376c2 + f1cfa45 commit 240e1d9
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask
buildscript {
ext {
release = [
versionName: "7.3.4",
versionName: "7.4.0",
versionCode: 1
]
}
Expand Down
1 change: 1 addition & 0 deletions config/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
<ID>ReturnCount:ExceptionHandler.kt$ExceptionHandler$private fun isQonversionException(exception: Throwable): Boolean</ID>
<ID>ReturnCount:QExceptionManager.kt$QExceptionManager$private fun getContentOfCrashReport(filename: String): CrashRequest.ExceptionInfo?</ID>
<ID>ReturnCount:QProductCenterManager.kt$QProductCenterManager$@Synchronized private fun executeProductsBlocks(loadStoreProductsError: QonversionError? = null)</ID>
<ID>ReturnCount:QProductCenterManager.kt$QProductCenterManager$fun identify(identityId: String, callback: QonversionUserCallback? = null)</ID>
<ID>ReturnCount:ScreenPresenter.kt$ScreenPresenter$override fun shouldOverrideUrlLoading(url: String?): Boolean</ID>
<ID>SpacingAroundColon:com.qonversion.android.sdk.internal.requests.ProviderDataRequestTest.kt:45</ID>
<ID>SpacingAroundCurly:com.qonversion.android.sdk.automations.internal.QAutomationsManagerTest.kt:263</ID>
Expand Down
2 changes: 1 addition & 1 deletion fastlane/report.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@



<testcase classname="fastlane.lanes" name="0: default_platform" time="0.000322">
<testcase classname="fastlane.lanes" name="0: default_platform" time="0.000217">

</testcase>

Expand Down
7 changes: 7 additions & 0 deletions sdk/src/main/java/com/qonversion/android/sdk/Qonversion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ interface Qonversion {
*/
fun identify(userID: String)

/**
* Call this function to link a user to his unique ID in your system and share purchase data.
* @param userID - unique user ID in your system
* @param callback - callback that will be called when response is received
*/
fun identify(userID: String, callback: QonversionUserCallback)

/**
* Call this function to unlink a user from his unique ID in your system and his purchase data.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.qonversion.android.sdk.internal.services.QUserInfoService
import javax.inject.Inject

interface IdentityManagerCallback {
fun onSuccess(identityID: String)
fun onSuccess(qonversionUid: String)
fun onError(error: QonversionError)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ internal class QProductCenterManager internal constructor(

private var processingPartnersIdentityId: String? = null
private var pendingPartnersIdentityId: String? = null
private var pendingIdentityCallbacks = mutableMapOf<String, MutableList<QonversionUserCallback>>()
private var unhandledLogoutAvailable: Boolean = false

private var installDate: Long = 0
Expand Down Expand Up @@ -163,24 +164,30 @@ internal class QProductCenterManager internal constructor(
})
}

fun identify(userID: String) {
if (processingPartnersIdentityId == userID || identityManager.currentPartnersIdentityId == userID) {
fun identify(identityId: String, callback: QonversionUserCallback? = null) {
if (identityManager.currentPartnersIdentityId == identityId) {
callback?.let { getUserInfo(callback) }
return
}

addIdentityCallback(identityId, callback)
if (processingPartnersIdentityId == identityId) {
return
}

unhandledLogoutAvailable = false

pendingPartnersIdentityId = userID
pendingPartnersIdentityId = identityId
if (!isLaunchingFinished || isRestoreInProgress) {
return
}

processingPartnersIdentityId = userID
processingPartnersIdentityId = identityId

if (launchError != null) {
val callback = object : QonversionLaunchCallback {
val launchCallback = object : QonversionLaunchCallback {
override fun onSuccess(launchResult: QLaunchResult) {
processIdentity(userID)
processIdentity(identityId)
}

override fun onError(error: QonversionError, httpCode: Int?) {
Expand All @@ -191,28 +198,37 @@ internal class QProductCenterManager internal constructor(
}
}

val initRequestData = InitRequestData(installDate, advertisingID, callback = callback)
val initRequestData = InitRequestData(installDate, advertisingID, callback = launchCallback)
repository.init(initRequestData)
} else {
processIdentity(userID)
processIdentity(identityId)
}
}

private fun processIdentity(userID: String) {
private fun processIdentity(identityId: String) {
val currentUserID = userInfoService.obtainUserID()

identityManager.identify(userID, object : IdentityManagerCallback {
override fun onSuccess(identityID: String) {
identityManager.identify(identityId, object : IdentityManagerCallback {
override fun onSuccess(qonversionUid: String) {
pendingPartnersIdentityId = null
processingPartnersIdentityId = null

if (currentUserID == identityID) {
if (currentUserID == qonversionUid) {
handlePendingRequests()
fireIdentitySuccess(identityId)
} else {
internalConfig.uid = identityID
internalConfig.uid = qonversionUid
remoteConfigManager.onUserUpdate()
launchResultCache.clearPermissionsCache()
launch()
launch(object : QonversionLaunchCallback {
override fun onSuccess(launchResult: QLaunchResult) {
fireIdentitySuccess(identityId)
}

override fun onError(error: QonversionError, httpCode: Int?) {
fireIdentityError(identityId, error)
}
})
}
}

Expand All @@ -221,6 +237,8 @@ internal class QProductCenterManager internal constructor(

executeEntitlementsBlock(error)
remoteConfigManager.userChangingRequestFailedWithError(error)

fireIdentityError(identityId, error)
}
})
}
Expand Down Expand Up @@ -1005,4 +1023,35 @@ internal class QProductCenterManager internal constructor(
httpCode?.isInternalServerError() == true
)
}

private fun addIdentityCallback(identityId: String, callback: QonversionUserCallback?) {
if (callback == null) {
return
}

val callbacks = pendingIdentityCallbacks[identityId] ?: mutableListOf()
callbacks.add(callback)
pendingIdentityCallbacks[identityId] = callbacks
}

private fun fireIdentitySuccess(identityId: String) {
val callbacks = pendingIdentityCallbacks[identityId] ?: return
pendingIdentityCallbacks[identityId] = mutableListOf()

getUserInfo(object : QonversionUserCallback {
override fun onSuccess(user: QUser) {
callbacks.forEach { it.onSuccess(user) }
}

override fun onError(error: QonversionError) {
callbacks.forEach { it.onError(error) }
}
})
}

private fun fireIdentityError(identityId: String, error: QonversionError) {
val callbacks = pendingIdentityCallbacks[identityId] ?: return
pendingIdentityCallbacks[identityId] = mutableListOf()
callbacks.forEach { it.onError(error) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.qonversion.android.sdk.dto.QPurchaseUpdateModel
import com.qonversion.android.sdk.dto.entitlements.QEntitlement
import com.qonversion.android.sdk.dto.QRemoteConfig
import com.qonversion.android.sdk.dto.QRemoteConfigList
import com.qonversion.android.sdk.dto.QUser
import com.qonversion.android.sdk.dto.properties.QUserPropertyKey
import com.qonversion.android.sdk.dto.QonversionError
import com.qonversion.android.sdk.dto.eligibility.QEligibility
Expand Down Expand Up @@ -303,12 +304,16 @@ internal class QonversionInternal(
productCenterManager.identify(userID)
}

override fun identify(userID: String, callback: QonversionUserCallback) {
productCenterManager.identify(userID, callback)
}

override fun logout() {
productCenterManager.logout()
}

override fun userInfo(callback: QonversionUserCallback) {
productCenterManager.getUserInfo(callback)
productCenterManager.getUserInfo(mainUserCallback(callback))
}

override fun attribution(data: Map<String, Any>, provider: QAttributionProvider) {
Expand Down Expand Up @@ -341,6 +346,15 @@ internal class QonversionInternal(
postToMainThread { callback.onError(error) }
}

private fun mainUserCallback(callback: QonversionUserCallback): QonversionUserCallback =
object : QonversionUserCallback {
override fun onSuccess(user: QUser) =
postToMainThread { callback.onSuccess(user) }

override fun onError(error: QonversionError) =
postToMainThread { callback.onError(error) }
}

private fun postToMainThread(runnable: () -> Unit) {
if (Looper.myLooper() == Looper.getMainLooper()) {
runnable()
Expand Down

0 comments on commit 240e1d9

Please sign in to comment.