Skip to content

Commit

Permalink
Update Google Play Billing
Browse files Browse the repository at this point in the history
  • Loading branch information
Chainfire committed Nov 18, 2022
1 parent 513f8c1 commit 86ec5c2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 32 deletions.
37 changes: 22 additions & 15 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "eu.chainfire.holeylight"
minSdkVersion 28
targetSdkVersion 30
versionCode 100
versionName "1.00"
versionCode 101
versionName "1.01"
}
buildTypes {
release {
Expand Down Expand Up @@ -35,6 +35,11 @@ android {
}
}
}
lintOptions {
// Upgrading to Google Play Billing 5.1.0 broke building Signed APKs
// Be sure to run Verification -> lintVitalRelease manually before releasing
checkReleaseBuilds false
}
}

dependencies {
Expand All @@ -43,25 +48,27 @@ dependencies {
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0-alpha2'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.android.billingclient:billing:3.0.2'
implementation 'com.android.billingclient:billing:5.1.0'
implementation 'com.airbnb.android:lottie:3.0.0'
implementation 'com.github.duanhong169:colorpicker:1.1.6'
}

task buildTranslationArray << {
def foundLocales = new StringBuilder()
foundLocales.append("new String[]{")
task buildTranslationArray {
doLast {
def foundLocales = new StringBuilder()
foundLocales.append("new String[]{")

fileTree("src/main/res").visit { FileVisitDetails details ->
if(details.file.path.endsWith("strings.xml")){
def languageCode = details.file.parent.tokenize('/').last().tokenize('\\').last().replaceAll('values-','').replaceAll('-r','-')
languageCode = (languageCode == "values") ? "en" : languageCode;
foundLocales.append("\"").append(languageCode).append("\"").append(",")
fileTree("src/main/res").visit { FileVisitDetails details ->
if(details.file.path.endsWith("strings.xml")){
def languageCode = details.file.parent.tokenize('/').last().tokenize('\\').last().replaceAll('values-','').replaceAll('-r','-')
languageCode = (languageCode == "values") ? "en" : languageCode;
foundLocales.append("\"").append(languageCode).append("\"").append(",")
}
}
}

foundLocales.append("}")
def foundLocalesString = foundLocales.toString().replaceAll(',}','}')
android.defaultConfig.buildConfigField "String[]", "TRANSLATION_ARRAY", foundLocalesString
foundLocales.append("}")
def foundLocalesString = foundLocales.toString().replaceAll(',}','}')
android.defaultConfig.buildConfigField "String[]", "TRANSLATION_ARRAY", foundLocalesString
}
}
preBuild.dependsOn buildTranslationArray
46 changes: 32 additions & 14 deletions app/src/main/java/eu/chainfire/holeylight/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
import com.android.billingclient.api.BillingFlowParams;
import com.android.billingclient.api.BillingResult;
import com.android.billingclient.api.Purchase;
import com.android.billingclient.api.PurchasesResponseListener;
import com.android.billingclient.api.PurchasesUpdatedListener;
import com.android.billingclient.api.QueryPurchasesParams;
import com.android.billingclient.api.SkuDetails;
import com.android.billingclient.api.SkuDetailsParams;

Expand Down Expand Up @@ -672,7 +674,9 @@ public void run() {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
if (purchases != null) {
for (Purchase purchase : purchases) {
Slog.d("IAP", "purchaseUpdate: %s", purchase.getSku());
for (String product : purchase.getProducts()) {
Slog.d("IAP", "purchaseUpdate: %s", product);
}
handlePurchase(purchase);
}
}
Expand Down Expand Up @@ -711,17 +715,22 @@ public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
}
}
});
Purchase.PurchasesResult purchasesResult = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
if (purchasesResult.getBillingResult() != null && purchasesResult.getBillingResult().getResponseCode() == BillingClient.BillingResponseCode.OK) {
List<Purchase> purchases = purchasesResult.getPurchasesList();
if (purchases != null) {
for (Purchase purchase : purchases) {
Slog.d("IAP", "queryPurchases: %s", purchase.getSku());
handlePurchase(purchase);
settings.incUpdateCounter();

billingClient.queryPurchasesAsync(QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.INAPP).build(), new PurchasesResponseListener() {
@Override
public void onQueryPurchasesResponse(@NonNull BillingResult billingResult, @NonNull List<Purchase> purchases) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
for (Purchase purchase : purchases) {
for (String product : purchase.getProducts()) {
Slog.d("IAP", "queryPurchases: %s", product);
}
handlePurchase(purchase);
}
}
settings.incUpdateCounter();
}
}
settings.incUpdateCounter();
});
}
}
@Override
Expand All @@ -743,12 +752,21 @@ private void handlePurchase(Purchase purchase) {
AcknowledgePurchaseParams.newBuilder()
.setPurchaseToken(purchase.getPurchaseToken())
.build();
Slog.d("IAP", "acknowledging: %s", purchase.getSku());
final String sku = purchase.getSku();
final List<String> products = purchase.getProducts();
for (String product : products) {
Slog.d("IAP", "acknowledging: %s", product);
}
billingClient.acknowledgePurchase(acknowledgePurchaseParams, billingResult -> {
Slog.d("IAP", "acknowledged: %s", sku);
settings.setPurchased(purchase.getSku());
for (String product : products) {
Slog.d("IAP", "acknowledged: %s", product);
settings.setPurchased(product);
}
});
} else {
for (String product : purchase.getProducts()) {
Slog.d("IAP", "already purchased: %s", product);
settings.setPurchased(product);
}
}
}
} catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.android.tools.build:gradle:3.6.2'


// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Mar 30 12:11:03 CET 2019
#Fri Nov 18 08:48:53 CET 2022
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip

0 comments on commit 86ec5c2

Please sign in to comment.