Skip to content

Commit

Permalink
Release 7.0.0
Browse files Browse the repository at this point in the history
Release 7.0.0
  • Loading branch information
SpertsyanKM authored Jan 22, 2024
2 parents 96fbea4 + f4fae95 commit f8eb05c
Show file tree
Hide file tree
Showing 84 changed files with 2,553 additions and 3,963 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ buildscript {
}

android {
compileSdkVersion 33
compileSdk 33
defaultConfig {
applicationId "com.qonversion.sample"
minSdkVersion 16
minSdkVersion 19
targetSdkVersion 33
versionCode 1
versionName "1.0.0"
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/com/qonversion/android/app/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.qonversion.android.sdk.automations.dto.QActionResult
import com.qonversion.android.sdk.automations.dto.QActionResultType
import com.qonversion.android.sdk.automations.dto.QScreenPresentationConfig
import com.qonversion.android.sdk.automations.dto.QScreenPresentationStyle
import com.qonversion.android.sdk.dto.QPurchaseModel
import com.qonversion.android.sdk.dto.entitlements.QEntitlement
import com.qonversion.android.sdk.dto.QonversionError
import com.qonversion.android.sdk.dto.products.QProduct
Expand Down Expand Up @@ -137,8 +138,11 @@ class HomeFragment : Fragment() {
val subscription = products[productIdSubs]
if (subscription != null) {
binding.buttonSubscribe.text = String.format(
"%s %s / %s", getStr(R.string.subscribe_for),
subscription.prettyPrice, subscription.duration?.name
"%s %s / %d %s",
getStr(R.string.subscribe_for),
subscription.prettyPrice,
subscription.subscriptionPeriod?.unitCount,
subscription.subscriptionPeriod?.unit?.name,
)
}

Expand Down Expand Up @@ -172,7 +176,7 @@ class HomeFragment : Fragment() {
private fun purchase(productId: String) {
Qonversion.shared.purchase(
requireActivity(),
productId,
QPurchaseModel(productId),
callback = object : QonversionEntitlementsCallback {
override fun onSuccess(entitlements: Map<String, QEntitlement>) {
when (productId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import com.android.billingclient.api.BillingClientStateListener;
import com.android.billingclient.api.BillingFlowParams;
import com.android.billingclient.api.BillingResult;
import com.android.billingclient.api.*;
import com.android.billingclient.api.SkuDetailsParams;
import com.android.billingclient.api.ProductDetails;
import com.android.billingclient.api.QueryProductDetailsParams;
import com.qonversion.android.sdk.Qonversion;

import java.util.Collections;
Expand All @@ -22,12 +22,11 @@

public class ManualTrackingActivity extends AppCompatActivity {

private static final String SKU_ID = "your_sku_id";
private static final String PRODUCT_ID = "your_product_id";

private BillingClient client;

@SuppressWarnings("deprecation")
private final Map<String, SkuDetails> skuDetails = new HashMap<>();
private final Map<String, ProductDetails> productDetails = new HashMap<>();

@Override
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
Expand All @@ -36,18 +35,16 @@ public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableB
client = BillingClient
.newBuilder(this)
.enablePendingPurchases()
.setListener((billingResult, list) -> {
.setListener((billingResult, purchases) -> {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
if (list != null && !list.isEmpty()) {
if (purchases != null && !purchases.isEmpty()) {
Qonversion.getSharedInstance().syncPurchases();
}
}
})
.build();


launchBilling();

}

private void launchBilling() {
Expand All @@ -56,18 +53,21 @@ private void launchBilling() {
public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {

@SuppressWarnings("deprecation")
final SkuDetailsParams params = SkuDetailsParams
final QueryProductDetailsParams.Product product = QueryProductDetailsParams.Product
.newBuilder()
.setProductId(PRODUCT_ID)
.setProductType(BillingClient.ProductType.INAPP)
.build();

final QueryProductDetailsParams params = QueryProductDetailsParams
.newBuilder()
.setSkusList(Collections.singletonList(SKU_ID))
.setType(BillingClient.SkuType.INAPP)
.setProductList(Collections.singletonList(product))
.build();

//noinspection deprecation
client.querySkuDetailsAsync(params, (queryBillingResult, list) -> {
client.queryProductDetailsAsync(params, (queryBillingResult, details) -> {
if (queryBillingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
if (list != null && !list.isEmpty()) {
skuDetails.put(SKU_ID, list.get(0));
if (!details.isEmpty()) {
productDetails.put(PRODUCT_ID, details.get(0));
}
launchBillingFlow();
}
Expand All @@ -84,11 +84,16 @@ public void onBillingServiceDisconnected() {
}

private void launchBillingFlow() {
@SuppressWarnings("deprecation")
final BillingFlowParams.ProductDetailsParams productDetailsParams = BillingFlowParams.ProductDetailsParams
.newBuilder()
.setProductDetails(Objects.requireNonNull(productDetails.get(PRODUCT_ID)))
.build();

final BillingFlowParams params = BillingFlowParams
.newBuilder()
.setSkuDetails(Objects.requireNonNull(skuDetails.get(SKU_ID)))
.setProductDetailsParamsList(Collections.singletonList(productDetailsParams))
.build();

client.launchBillingFlow(this, params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,87 @@ package com.qonversion.android.app
import android.os.Bundle
import android.os.PersistableBundle
import androidx.appcompat.app.AppCompatActivity
import com.android.billingclient.api.*
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.QueryProductDetailsParams
import com.qonversion.android.sdk.Qonversion
import java.util.*

class ManualTrackingActivityKt : AppCompatActivity() {
private var client: BillingClient? = null
@Suppress("DEPRECATION")
private val skuDetails: MutableMap<String, SkuDetails?> =
HashMap()
private lateinit var client: BillingClient

override fun onCreate(
savedInstanceState: Bundle?,
persistentState: PersistableBundle?
) {
private val productDetails: MutableMap<String, ProductDetails> = HashMap()

override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)
client = BillingClient
.newBuilder(this)
.enablePendingPurchases()
.setListener { billingResult, list ->
.setListener { billingResult, purchases ->
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
if (!list.isNullOrEmpty()) {
if (!purchases.isNullOrEmpty()) {
Qonversion.shared.syncPurchases()
}
}
}
.build()

launchBilling()
}

private fun launchBilling() {
client!!.startConnection(object : BillingClientStateListener {
client.startConnection(object : BillingClientStateListener {
override fun onBillingSetupFinished(billingResult: BillingResult) {
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
querySkuDetailsAsync()
queryProductDetailsAsync()
}
}

override fun onBillingServiceDisconnected() { // ignore in example
override fun onBillingServiceDisconnected() {
// ignore in example
}
})
}

private fun querySkuDetailsAsync() {
@Suppress("DEPRECATION")
val params =
SkuDetailsParams
.newBuilder()
.setSkusList(listOf(SKU_ID))
.setType(BillingClient.SkuType.INAPP)
.build()
private fun queryProductDetailsAsync() {
val product = QueryProductDetailsParams.Product
.newBuilder()
.setProductId(PRODUCT_ID)
.setProductType(BillingClient.ProductType.INAPP)
.build()

val params = QueryProductDetailsParams
.newBuilder()
.setProductList(listOf(product))
.build()

@Suppress("DEPRECATION")
client!!.querySkuDetailsAsync(
params
) { billingResult, list ->
client.queryProductDetailsAsync(params) { billingResult, details ->
if (billingResult.responseCode == BillingClient.BillingResponseCode.OK) {
if (list!!.isNotEmpty()) {
skuDetails[SKU_ID] = list[0]
if (details.isNotEmpty()) {
productDetails[PRODUCT_ID] = details.first()
}
launchBillingFlow()
}
}
}

private fun launchBillingFlow() {
@Suppress("DEPRECATION")
val params =
BillingFlowParams
.newBuilder()
.setSkuDetails(skuDetails[SKU_ID]!!)
.build()
client!!.launchBillingFlow(this, params)
val productDetailsParams = BillingFlowParams.ProductDetailsParams
.newBuilder()
.setProductDetails(productDetails[PRODUCT_ID]!!)
.build()

val params = BillingFlowParams
.newBuilder()
.setProductDetailsParamsList(listOf(productDetailsParams))
.build()

client.launchBillingFlow(this, params)
}

companion object {
private const val SKU_ID = "your_sku_id"
private const val PRODUCT_ID = "your_product_id"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class OfferingsFragment : Fragment() {
}

private fun purchase(product: QProduct) {
Qonversion.shared.purchase(requireActivity(), product, callback = object :
Qonversion.shared.purchase(requireActivity(), product.toPurchaseModel(), callback = object :
QonversionEntitlementsCallback {
override fun onSuccess(entitlements: Map<String, QEntitlement>) {
Toast.makeText(context, "Purchase succeeded", Toast.LENGTH_LONG).show()
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask
buildscript {
ext {
release = [
versionName: "6.3.2",
versionName: "7.0.0",
versionCode: 1
]
}
ext.kotlin_version = '1.6.21'
ext.kotlin_version = '1.8.22'
repositories {
mavenCentral()
google()
Expand Down
Loading

0 comments on commit f8eb05c

Please sign in to comment.