Get IAP Price & Add Support Text

This commit is contained in:
Negue 2016-02-15 19:31:17 +01:00
parent 231629ce6d
commit 99bff54292
3 changed files with 32 additions and 15 deletions

View file

@ -6,9 +6,9 @@
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="5dp"
android:text="Help support Habitica"
android:layout_gravity="center_horizontal">
android:text="@string/gem.purchase.support"
android:layout_gravity="center_horizontal"
android:layout_margin="5dp">
</TextView>

View file

@ -211,4 +211,6 @@ To start, which parts of your life do you want to improve?</string>
<string name="setup_task_creativity_1">Study a master of the craft</string>
<string name="setup_task_creativity_2">Work on creative project</string>
<string name="setup_task_creativity_3">Finish creative project</string>
<string name="gem.purchase.support">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!</string>
</resources>

View file

@ -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<Purchase>() {
@Override
public void onSuccess(Purchase purchase) {
if(purchase.sku.equals(HabiticaApplication.Purchase20Gems)){
if (purchase.sku.equals(HabiticaApplication.Purchase20Gems)) {
billingRequests.consume(purchase.token, new RequestListener<Object>() {
@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<Sku> 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<Purchases>() {
@Override
@ -164,12 +183,8 @@ public class GemsPurchaseFragment extends BaseMainFragment {
public void onDestroyView() {
super.onDestroyView();
ButterKnife.unbind(this);
}
public interface Listener {
ActivityCheckout getActivityCheckout();
}