From 99bff54292fc890b4aaa2efdf854cdcb090126a7 Mon Sep 17 00:00:00 2001 From: Negue Date: Mon, 15 Feb 2016 19:31:17 +0100 Subject: [PATCH] Get IAP Price & Add Support Text --- Habitica/res/layout/fragment_gem_purchase.xml | 6 +-- Habitica/res/values/strings.xml | 2 + .../ui/fragments/GemsPurchaseFragment.java | 39 +++++++++++++------ 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Habitica/res/layout/fragment_gem_purchase.xml b/Habitica/res/layout/fragment_gem_purchase.xml index e1670402f..5c719c1c4 100644 --- a/Habitica/res/layout/fragment_gem_purchase.xml +++ b/Habitica/res/layout/fragment_gem_purchase.xml @@ -6,9 +6,9 @@ + android:text="@string/gem.purchase.support" + android:layout_gravity="center_horizontal" + android:layout_margin="5dp"> diff --git a/Habitica/res/values/strings.xml b/Habitica/res/values/strings.xml index 9aad1f93d..50d76269e 100644 --- a/Habitica/res/values/strings.xml +++ b/Habitica/res/values/strings.xml @@ -211,4 +211,6 @@ To start, which parts of your life do you want to improve? Study a master of the craft Work on creative project Finish creative project + + Want to help us keep Habitica running? You can support the developers by buying gems!\n\nGems allow you to buy fun extras for your account, including: \n\n - Cool costumes for your avatar\n - Awesome backgrounds\n - Fun quests that reward you with pet eggs\n - The ability to change your class before level 100\n\nThank you so much for helping us make Habitica the best it can be. Your support means a lot to us! \ No newline at end of file diff --git a/Habitica/src/com/habitrpg/android/habitica/ui/fragments/GemsPurchaseFragment.java b/Habitica/src/com/habitrpg/android/habitica/ui/fragments/GemsPurchaseFragment.java index f43550960..2f0ae2295 100644 --- a/Habitica/src/com/habitrpg/android/habitica/ui/fragments/GemsPurchaseFragment.java +++ b/Habitica/src/com/habitrpg/android/habitica/ui/fragments/GemsPurchaseFragment.java @@ -14,13 +14,7 @@ import com.habitrpg.android.habitica.events.BoughtGemsEvent; import com.habitrpg.android.habitica.ui.helpers.ViewHelper; import de.greenrobot.event.EventBus; import io.fabric.sdk.android.Fabric; -import org.solovyev.android.checkout.ActivityCheckout; -import org.solovyev.android.checkout.BillingRequests; -import org.solovyev.android.checkout.Checkout; -import org.solovyev.android.checkout.ProductTypes; -import org.solovyev.android.checkout.Purchase; -import org.solovyev.android.checkout.Purchases; -import org.solovyev.android.checkout.RequestListener; +import org.solovyev.android.checkout.*; import butterknife.Bind; @@ -65,7 +59,7 @@ public class GemsPurchaseFragment extends BaseMainFragment { checkout.createPurchaseFlow(new RequestListener() { @Override public void onSuccess(Purchase purchase) { - if(purchase.sku.equals(HabiticaApplication.Purchase20Gems)){ + if (purchase.sku.equals(HabiticaApplication.Purchase20Gems)) { billingRequests.consume(purchase.token, new RequestListener() { @Override public void onSuccess(Object o) { @@ -95,6 +89,7 @@ public class GemsPurchaseFragment extends BaseMainFragment { // if the user leaves the fragment before the checkout callback is done if(btnPurchaseGems != null) { btnPurchaseGems.setEnabled(true); + } checkIfPendingPurchases(); } @@ -102,12 +97,36 @@ public class GemsPurchaseFragment extends BaseMainFragment { @Override public void onReady(BillingRequests billingRequests, String s, boolean b) { + checkout.loadInventory().whenLoaded(new Inventory.Listener() { + @Override + public void onLoaded(Inventory.Products products) { + + Inventory.Product gems = products.get(ProductTypes.IN_APP); + + java.util.List skus = gems.getSkus(); + + for (Sku sku : skus){ + updateBuyButtonText(sku.price); + } + } + }); + } }); return v; } + private void updateBuyButtonText(String price){ + if(price == null || price.isEmpty()){ + btnPurchaseGems.setText("+"+ GEMS_TO_ADD); + } + else + { + btnPurchaseGems.setText(price + " = " +"+"+GEMS_TO_ADD ); + } + } + private void checkIfPendingPurchases(){ billingRequests.getAllPurchases(ProductTypes.IN_APP, new RequestListener() { @Override @@ -164,12 +183,8 @@ public class GemsPurchaseFragment extends BaseMainFragment { public void onDestroyView() { super.onDestroyView(); ButterKnife.unbind(this); - } - - - public interface Listener { ActivityCheckout getActivityCheckout(); }