mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-22 21:57:11 +00:00
display message when device doesn't support billing
This commit is contained in:
parent
964bf160c5
commit
e35318834c
5 changed files with 100 additions and 1 deletions
|
|
@ -24,7 +24,25 @@
|
|||
android:drawableTop="@drawable/ic_heart_large"
|
||||
android:textSize="14sp"
|
||||
android:lineSpacingExtra="4dp" />
|
||||
<TextView
|
||||
android:id="@+id/notAvailableTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/no_billing_gems"
|
||||
android:paddingTop="50dp"
|
||||
android:paddingBottom="10dp"
|
||||
android:visibility="gone" />
|
||||
<Button
|
||||
android:id="@+id/notAvailableButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/visit_habitica_website"
|
||||
android:layout_marginBottom="50dp"
|
||||
style="@style/Button.Purple"
|
||||
android:visibility="gone" />
|
||||
<LinearLayout
|
||||
android:id="@+id/gemPurchaseOptions"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
|
|
|||
|
|
@ -150,6 +150,25 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:id="@+id/loadingIndicator"/>
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/notAvailableTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/no_billing_subscriptions"
|
||||
android:paddingTop="50dp"
|
||||
android:paddingBottom="10dp"
|
||||
android:visibility="gone" />
|
||||
<Button
|
||||
android:id="@+id/notAvailableButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/visit_habitica_website"
|
||||
android:layout_marginBottom="50dp"
|
||||
style="@style/Button.Purple"
|
||||
android:visibility="gone" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/subscriptionOptions"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
|||
|
|
@ -569,4 +569,6 @@
|
|||
<string name="reload_content">Reload Content</string>
|
||||
<string name="dailyDueDefaultView">Set Dailies default to ‘due’ tab</string>
|
||||
<string name="dailyDueDefaultViewDescription">With this option set, the Dailies tasks will default to ‘due’ instead of ‘all’</string>
|
||||
<string name="no_billing_gems">Your device does not have any of the supported payment methods. Please use the habitica website if you want to purchase gems.</string>
|
||||
<string name="no_billing_subscriptions">Your device does not have any of the supported payment methods. Please use the habitica website if you want to purchase a subscription.</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments;
|
||||
|
||||
import com.habitrpg.android.habitica.BuildConfig;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.helpers.PurchaseTypes;
|
||||
|
|
@ -14,6 +15,9 @@ import org.solovyev.android.checkout.ProductTypes;
|
|||
import org.solovyev.android.checkout.RequestListener;
|
||||
import org.solovyev.android.checkout.Sku;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
|
@ -21,10 +25,13 @@ import android.util.Log;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
public class GemsPurchaseFragment extends BaseFragment implements GemPurchaseActivity.CheckoutFragment {
|
||||
|
||||
|
|
@ -36,12 +43,20 @@ public class GemsPurchaseFragment extends BaseFragment implements GemPurchaseAct
|
|||
GemPurchaseOptionsView gems42View;
|
||||
@BindView(R.id.gems_84_view)
|
||||
GemPurchaseOptionsView gems84View;
|
||||
@BindView(R.id.gemPurchaseOptions)
|
||||
ViewGroup gemPurchaseOptions;
|
||||
|
||||
@BindView(R.id.notAvailableTextView)
|
||||
TextView billingNotAvailableTextView;
|
||||
@BindView(R.id.notAvailableButton)
|
||||
Button billingNotAvailableButton;
|
||||
|
||||
@Inject
|
||||
CrashlyticsProxy crashlyticsProxy;
|
||||
|
||||
private GemPurchaseActivity listener;
|
||||
private BillingRequests billingRequests;
|
||||
private boolean billingNotSupported;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
|
|
@ -67,6 +82,10 @@ public class GemsPurchaseFragment extends BaseFragment implements GemPurchaseAct
|
|||
gems84View.setOnPurchaseClickListener(v -> purchaseGems(PurchaseTypes.Purchase84Gems));
|
||||
|
||||
gems84View.seedsImageButton.setOnClickListener(v -> ((GemPurchaseActivity) this.getActivity()).showSeedsPromo(getString(R.string.seeds_interstitial_gems), "store"));
|
||||
|
||||
if (billingNotSupported) {
|
||||
setBillingNotSupported();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -80,7 +99,7 @@ public class GemsPurchaseFragment extends BaseFragment implements GemPurchaseAct
|
|||
products -> {
|
||||
Inventory.Product gems = products.get(ProductTypes.IN_APP);
|
||||
if (!gems.supported) {
|
||||
// billing is not supported, user can't purchase anything
|
||||
setBillingNotSupported();
|
||||
return;
|
||||
}
|
||||
java.util.List<Sku> skus = gems.getSkus();
|
||||
|
|
@ -91,6 +110,15 @@ public class GemsPurchaseFragment extends BaseFragment implements GemPurchaseAct
|
|||
}
|
||||
}
|
||||
|
||||
private void setBillingNotSupported() {
|
||||
billingNotSupported = true;
|
||||
if (gemPurchaseOptions != null) {
|
||||
gemPurchaseOptions.setVisibility(View.GONE);
|
||||
billingNotAvailableButton.setVisibility(View.VISIBLE);
|
||||
billingNotAvailableTextView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setListener(GemPurchaseActivity listener) {
|
||||
this.listener = listener;
|
||||
|
|
@ -136,6 +164,11 @@ public class GemsPurchaseFragment extends BaseFragment implements GemPurchaseAct
|
|||
crashlyticsProxy.fabricLogE("Purchase", "Error", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@OnClick(R.id.notAvailableButton)
|
||||
public void openWebsite() {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(BuildConfig.BASE_URL + "/"));
|
||||
getContext().startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,6 +97,11 @@ public class SubscriptionFragment extends BaseFragment implements GemPurchaseAct
|
|||
@BindView(R.id.subscribeBenefitsTitle)
|
||||
TextView subscribeBenefitsTitle;
|
||||
|
||||
@BindView(R.id.notAvailableTextView)
|
||||
TextView billingNotAvailableTextView;
|
||||
@BindView(R.id.notAvailableButton)
|
||||
Button billingNotAvailableButton;
|
||||
|
||||
@Nullable
|
||||
Sku selectedSubscriptionSku;
|
||||
List<Sku> skus;
|
||||
|
|
@ -106,6 +111,7 @@ public class SubscriptionFragment extends BaseFragment implements GemPurchaseAct
|
|||
|
||||
private HabitRPGUser user;
|
||||
private boolean hasLoadedSubscriptionOptions;
|
||||
private boolean billingNotSupported;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
|
|
@ -145,6 +151,10 @@ public class SubscriptionFragment extends BaseFragment implements GemPurchaseAct
|
|||
this.subscribeListitem2Box.setOnClickListener(view1 -> toggleDescriptionView(this.subscribeListitem2Button, this.subscribeListItem2Description));
|
||||
this.subscribeListitem3Box.setOnClickListener(view1 -> toggleDescriptionView(this.subscribeListitem3Button, this.subscribeListItem3Description));
|
||||
this.subscribeListitem4Box.setOnClickListener(view1 -> toggleDescriptionView(this.subscribeListitem4Button, this.subscribeListItem4Description));
|
||||
|
||||
if (billingNotSupported) {
|
||||
setBillingNotSupported();
|
||||
}
|
||||
}
|
||||
|
||||
private void toggleDescriptionView(ImageView button, TextView descriptionView) {
|
||||
|
|
@ -173,6 +183,11 @@ public class SubscriptionFragment extends BaseFragment implements GemPurchaseAct
|
|||
products -> {
|
||||
Inventory.Product subscriptions = products.get(ProductTypes.SUBSCRIPTION);
|
||||
|
||||
if (!subscriptions.supported) {
|
||||
setBillingNotSupported();
|
||||
return;
|
||||
}
|
||||
|
||||
skus = subscriptions.getSkus();
|
||||
|
||||
for (Sku sku : skus) {
|
||||
|
|
@ -185,6 +200,16 @@ public class SubscriptionFragment extends BaseFragment implements GemPurchaseAct
|
|||
}
|
||||
}
|
||||
|
||||
private void setBillingNotSupported() {
|
||||
billingNotSupported = true;
|
||||
if (subscriptionOptions != null) {
|
||||
subscriptionOptions.setVisibility(View.GONE);
|
||||
loadingIndicator.setVisibility(View.GONE);
|
||||
billingNotAvailableButton.setVisibility(View.VISIBLE);
|
||||
billingNotAvailableTextView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateButtonLabel(Sku sku, String price, Inventory.Product subscriptions) {
|
||||
SubscriptionOptionView matchingView = buttonForSku(sku);
|
||||
if (matchingView != null) {
|
||||
|
|
@ -288,6 +313,8 @@ public class SubscriptionFragment extends BaseFragment implements GemPurchaseAct
|
|||
this.subscriptionDetailsView.setPlan(plan);
|
||||
this.subscribeBenefitsTitle.setText(R.string.subscribe_prompt_thanks);
|
||||
this.subscriptionOptions.setVisibility(View.GONE);
|
||||
billingNotAvailableButton.setVisibility(View.GONE);
|
||||
billingNotAvailableTextView.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (!hasLoadedSubscriptionOptions) {
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in a new issue