IAPing.
This commit is contained in:
@@ -1,22 +1,22 @@
|
||||
(ns advent.android
|
||||
(:import [com.android.billingclient.api PurchasesUpdatedListener PurchaseHistoryResponseListener Purchase$PurchasesResult])
|
||||
(:require [clojure.core.async :as a]))
|
||||
|
||||
(def purchase-chan (a/chan))
|
||||
(:import [com.android.billingclient.api PurchasesUpdatedListener PurchaseHistoryResponseListener Purchase$PurchasesResult]
|
||||
[com.badlogic.gdx Gdx Application])
|
||||
(:require [clojure.core.async :as a]
|
||||
[advent.iap :as iap]))
|
||||
|
||||
(def listener
|
||||
(reify PurchasesUpdatedListener
|
||||
(onPurchasesUpdated [this response-code purchases]
|
||||
(println response-code purchases)
|
||||
(let [result (and purchases (> (.size purchases) 0))]
|
||||
(reset! @(resolve 'advent.core/has-purchased?) (if result true false))
|
||||
(a/go (a/>! purchase-chan (if result true false)))))) )
|
||||
(println "purchase response" result)
|
||||
(iap/set-purchase-pref (if result true false))))) )
|
||||
|
||||
(def history-listener
|
||||
(reify PurchaseHistoryResponseListener
|
||||
(onPurchaseHistoryResponse [this purchases-result]
|
||||
(println "got history")
|
||||
(reset! iap/can-purchase? true)
|
||||
(let [result (and purchases-result (.getPurchasesList purchases-result) (> (.size (.getPurchasesList purchases-result)) 0))]
|
||||
(reset! @(resolve 'advent.core/has-purchased?) (if result true false))
|
||||
(a/go (a/>! purchase-chan (if result true false)))))) )
|
||||
(println "purchase history" result)
|
||||
(iap/set-purchase-pref (if result true false))))) )
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.android.billingclient.api.BillingClient.SkuType;
|
||||
import com.android.billingclient.api.SkuDetails.SkuDetailsResult;
|
||||
import com.android.billingclient.api.BillingFlowParams;
|
||||
import com.android.billingclient.api.BillingFlowParams.Builder;
|
||||
import android.content.pm.*;
|
||||
|
||||
public class MainActivity extends AndroidApplication {
|
||||
public boolean triggerPurchase() {
|
||||
@@ -26,10 +27,19 @@ public class MainActivity extends AndroidApplication {
|
||||
|
||||
public void onCreate (android.os.Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
try {
|
||||
RT.var("clojure.core", "require").invoke(Symbol.intern("clojure.core.async"));
|
||||
RT.var("clojure.core", "require").invoke(Symbol.intern("advent.core"));
|
||||
RT.var("clojure.core", "require").invoke(Symbol.intern("advent.android"));
|
||||
|
||||
try {
|
||||
PackageInfo pInfo = this.getPackageManager().getPackageInfo(this.getPackageName(), 0);
|
||||
String version = pInfo.versionName;
|
||||
RT.var("advent.version", "version-override").bindRoot(version);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Importing failed");
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user