fix another crash in subscription view

This commit is contained in:
Phillip Thelen 2017-03-06 12:12:31 +01:00
parent 4c2f678322
commit 0ba7272cea
3 changed files with 22 additions and 18 deletions

View file

@ -104,25 +104,29 @@ public class SubscriptionDetailsView extends LinearLayout {
gemCapTextView.setText(String.valueOf(plan.consecutive.getGemCapExtra() + 25));
currentHourglassesTextView.setText(String.valueOf(plan.consecutive.getTrinkets()));
if (plan.paymentMethod.equals("Google")) {
cancelSubscripnDescription.setText(R.string.cancel_subscription_google_description);
visitWebsiteButton.setText(R.string.open_in_store);
} else {
cancelSubscripnDescription.setText(R.string.cancel_subscription_notgoogle_description);
visitWebsiteButton.setText(R.string.visit_habitica_website);
if (plan.paymentMethod != null) {
if (plan.paymentMethod.equals("Google")) {
cancelSubscripnDescription.setText(R.string.cancel_subscription_google_description);
visitWebsiteButton.setText(R.string.open_in_store);
} else {
cancelSubscripnDescription.setText(R.string.cancel_subscription_notgoogle_description);
visitWebsiteButton.setText(R.string.visit_habitica_website);
}
}
}
@OnClick(R.id.visitWebsiteButton)
public void openSubscriptionWebsite() {
Intent intent;
if (plan.paymentMethod.equals("Google")) {
intent = new Intent("android.intent.action.VIEW");
intent.setComponent(new ComponentName("com.android.vending", "com.android.vending.MyDownloadsActivity"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} else {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(BuildConfig.BASE_URL + "/"));
if (plan.paymentMethod != null) {
Intent intent;
if (plan.paymentMethod.equals("Google")) {
intent = new Intent("android.intent.action.VIEW");
intent.setComponent(new ComponentName("com.android.vending", "com.android.vending.MyDownloadsActivity"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} else {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(BuildConfig.BASE_URL + "/"));
}
getContext().startActivity(intent);
}
getContext().startActivity(intent);
}
}

View file

@ -27,7 +27,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
@ -107,7 +106,6 @@ public class SubscriptionFragment extends BaseFragment implements GemPurchaseAct
private HabitRPGUser user;
private boolean hasLoadedSubscriptionOptions;
private boolean isSubscribed;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
@ -279,7 +277,7 @@ public class SubscriptionFragment extends BaseFragment implements GemPurchaseAct
private void updateSubscriptionInfo() {
if (user != null) {
SubscriptionPlan plan = user.getPurchased().getPlan();
isSubscribed = false;
boolean isSubscribed = false;
if (plan != null) {
if (plan.isActive()) {
isSubscribed = true;

View file

@ -31,8 +31,10 @@ public class SubscriptionPlan extends BaseModel {
@Column
public Date dateUpdated;
@Column
@Nullable
public Date dateTerminated;
@Column
@Nullable
public String paymentMethod;
@Column
@Nullable
@ -53,7 +55,7 @@ public class SubscriptionPlan extends BaseModel {
public boolean isActive() {
Date today = new Date();
if (this.dateTerminated == null) {
if (planId != null && this.dateTerminated == null) {
return true;
}
return planId != null || this.dateTerminated.after(today);