mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-24 06:35:46 +00:00
show subscription details in account details
This commit is contained in:
parent
83bb7c3b6c
commit
7d4f4c47e8
11 changed files with 196 additions and 28 deletions
1
Habitica/assets/migrations/Habitica/31.sql
Normal file
1
Habitica/assets/migrations/Habitica/31.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE HabitRPGUser ADD COLUMN purchased_id varchar(255);
|
||||
|
|
@ -132,10 +132,11 @@
|
|||
android:text="@string/cancel_subscription"
|
||||
style="@style/subscriptionBoxText.Title.Red" />
|
||||
<TextView
|
||||
android:id="@+id/cancelSubscriptionDescription"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/subscriptionBoxText.Subtitle"
|
||||
android:text="@string/cancel_subscription.description"
|
||||
android:text="@string/cancel_subscription_notgoogle.description"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
<Button
|
||||
|
|
|
|||
|
|
@ -470,7 +470,8 @@ To start, which parts of your life do you want to improve?</string>
|
|||
<string name="subscription">Subscription</string>
|
||||
<string name="active">Active</string>
|
||||
<string name="cancel_subscription">Cancel Subscription</string>
|
||||
<string name="cancel_subscription.description">No longer want to subscribe? Due to your payment method, you can only unsubscribe through the website. Click the button below, to open the site in your browser!</string>
|
||||
<string name="cancel_subscription_google.description">No longer want to subscribe? You can find the option to unsubscribe in the "My Apps" section of the Google Play Store.</string>
|
||||
<string name="cancel_subscription_notgoogle.description">No longer want to subscribe? Due to your payment method, you can only unsubscribe through the website. Click the button below, to open the site in your browser!</string>
|
||||
<string name="visit_habitica_website">Visit Habitica Website</string>
|
||||
<string name="current_bonuses">Current Bonuses</string>
|
||||
<string name="months_subscribed">Months subscribed</string>
|
||||
|
|
@ -484,6 +485,7 @@ To start, which parts of your life do you want to improve?</string>
|
|||
<string name="six_months">6 months</string>
|
||||
<string name="twelve_months">12 months</string>
|
||||
<string name="subscribe_prompt_thanks">For Subscribing you are receiving these useful benefits:</string>
|
||||
<string name="subscription_status">Subscription Status</string>
|
||||
|
||||
<string name="byLeader" formatted="false">by %s</string>
|
||||
<string name="challenge_details">Challenge Details</string>
|
||||
|
|
|
|||
|
|
@ -47,13 +47,18 @@
|
|||
android:summary="@string/SP_APIToken_summary"/>
|
||||
|
||||
<Preference
|
||||
android:key="@string/SP_user_qr_code"
|
||||
android:key="SP_user_qr_code"
|
||||
android:title="@string/SP_user_qr_code"
|
||||
android:selectable="true"
|
||||
android:persistent="false"
|
||||
android:shouldDisableView="false"
|
||||
android:summary="@string/SP_user_qr_code"/>
|
||||
|
||||
<Preference
|
||||
android:key="subscription_status"
|
||||
android:title="@string/subscription_status"
|
||||
android:selectable="true"
|
||||
android:persistent="false"
|
||||
android:shouldDisableView="false"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
|
|
|||
|
|
@ -7,5 +7,5 @@ public class HabitDatabase {
|
|||
|
||||
public static final String NAME = "Habitica";
|
||||
|
||||
public static final int VERSION = 30;
|
||||
public static final int VERSION = 31;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,11 +7,13 @@ import com.magicmicky.habitrpgwrapper.lib.models.SubscriptionPlan;
|
|||
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
|
@ -41,16 +43,32 @@ public class SubscriptionDetailsView extends LinearLayout {
|
|||
@BindView(R.id.currentHourglassesTextView)
|
||||
TextView currentHourglassesTextView;
|
||||
|
||||
public SubscriptionDetailsView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
@BindView(R.id.cancelSubscriptionDescription)
|
||||
TextView cancelSubscripnDescription;
|
||||
|
||||
inflate(context, R.layout.subscription_details, this);
|
||||
@BindView(R.id.visitWebsiteButton)
|
||||
Button visitWebsiteButton;
|
||||
|
||||
private SubscriptionPlan plan;
|
||||
|
||||
public SubscriptionDetailsView(Context context, AttributeSet attributeSet) {
|
||||
super(context, attributeSet);
|
||||
setupView();
|
||||
}
|
||||
|
||||
public SubscriptionDetailsView(Context context) {
|
||||
super(context);
|
||||
setupView();
|
||||
}
|
||||
|
||||
private void setupView() {
|
||||
inflate(getContext(), R.layout.subscription_details, this);
|
||||
|
||||
ButterKnife.bind(this);
|
||||
|
||||
}
|
||||
|
||||
public void setPlan(SubscriptionPlan plan) {
|
||||
this.plan = plan;
|
||||
|
||||
if (plan.isActive()) {
|
||||
subscriptionStatusActive.setVisibility(View.VISIBLE);
|
||||
|
|
@ -85,11 +103,26 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick(R.id.visitWebsiteButton)
|
||||
public void openSubscriptionWebsite() {
|
||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(BuildConfig.BASE_URL+"/"));
|
||||
getContext().startActivity(browserIntent);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,26 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.preferences;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.events.commands.OpenGemPurchaseFragmentCommand;
|
||||
import com.habitrpg.android.habitica.helpers.QrCodeManager;
|
||||
import com.habitrpg.android.habitica.ui.SubscriptionDetailsView;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.SubscriptionPlan;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.BaseTransaction;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.TransactionListener;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.glxn.qrgen.android.QRCode;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -27,6 +29,38 @@ public class AccountDetailsFragment extends BasePreferencesFragment {
|
|||
|
||||
private QrCodeManager qrCodeManager;
|
||||
|
||||
private TransactionListener<HabitRPGUser> userTransactionListener = new TransactionListener<HabitRPGUser>() {
|
||||
@Override
|
||||
public void onResultReceived(HabitRPGUser habitRPGUser) {
|
||||
AccountDetailsFragment.this.setUser(habitRPGUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onReady(BaseTransaction<HabitRPGUser> baseTransaction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasResult(BaseTransaction<HabitRPGUser> baseTransaction, HabitRPGUser habitRPGUser) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
private HabitRPGUser user;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
String userID = getPreferenceManager().getSharedPreferences().getString(getContext().getString(R.string.SP_userID), null);
|
||||
if (userID != null) {
|
||||
new Select().from(HabitRPGUser.class).where(Condition.column("id").eq(userID)).async().querySingle(userTransactionListener);
|
||||
}
|
||||
}
|
||||
|
||||
public void setUser(HabitRPGUser user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupPreferences() {
|
||||
for (Map.Entry<String, ?> preference : getPreferenceScreen().getSharedPreferences().getAll().entrySet()) {
|
||||
|
|
@ -46,8 +80,17 @@ public class AccountDetailsFragment extends BasePreferencesFragment {
|
|||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(Preference preference) {
|
||||
if (preference.getKey().equals(getString(R.string.SP_user_qr_code))) {
|
||||
if (preference.getKey().equals("SP_user_qr_code")) {
|
||||
qrCodeManager.showDialogue();
|
||||
} else if (preference.getKey().equals("subscription_status")) {
|
||||
if (user != null && user.getPurchased() != null && user.getPurchased().getPlan() != null) {
|
||||
SubscriptionPlan plan = user.getPurchased().getPlan();
|
||||
if (plan.isActive()) {
|
||||
showSubscriptionStatusDialog();
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
}
|
||||
}
|
||||
EventBus.getDefault().post(new OpenGemPurchaseFragmentCommand());
|
||||
} else {
|
||||
ClipboardManager clipMan = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
clipMan.setPrimaryClip(ClipData.newPlainText(preference.getKey(), preference.getSummary()));
|
||||
|
|
@ -55,4 +98,16 @@ public class AccountDetailsFragment extends BasePreferencesFragment {
|
|||
}
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
}
|
||||
|
||||
private void showSubscriptionStatusDialog() {
|
||||
SubscriptionDetailsView view = new SubscriptionDetailsView(getContext());
|
||||
view.setPlan(user.getPurchased().getPlan());
|
||||
final AlertDialog dialog = new AlertDialog.Builder(getContext())
|
||||
.setView(view)
|
||||
.setTitle(R.string.subscription_status)
|
||||
.setPositiveButton(R.string.close, (dialogInterface, i) -> {
|
||||
dialogInterface.dismiss();
|
||||
}).create();
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,6 +104,10 @@ public class HabitRPGUser extends BaseModel {
|
|||
|
||||
private List<PushDevice> pushDevices;
|
||||
|
||||
@Column
|
||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "purchased_id",
|
||||
columnType = String.class,
|
||||
foreignColumnName = "user_id")})
|
||||
private Purchases purchased;
|
||||
|
||||
private TasksOrder tasksOrder;
|
||||
|
|
@ -352,9 +356,8 @@ public class HabitRPGUser extends BaseModel {
|
|||
items.user_id = id;
|
||||
authentication.user_id = id;
|
||||
flags.user_id = id;
|
||||
if (contributor != null) {
|
||||
contributor.user_id = id;
|
||||
}
|
||||
if (purchased != null) { purchased.user_id = id; }
|
||||
if (contributor != null) { contributor.user_id = id; }
|
||||
if (invitations != null) {
|
||||
invitations.user_id = id;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,34 @@
|
|||
package com.magicmicky.habitrpgwrapper.lib.models;
|
||||
|
||||
import com.habitrpg.android.habitica.HabitDatabase;
|
||||
import com.raizlabs.android.dbflow.annotation.Column;
|
||||
import com.raizlabs.android.dbflow.annotation.ForeignKey;
|
||||
import com.raizlabs.android.dbflow.annotation.ForeignKeyReference;
|
||||
import com.raizlabs.android.dbflow.annotation.NotNull;
|
||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||
import com.raizlabs.android.dbflow.annotation.Table;
|
||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by viirus on 14/01/16.
|
||||
*/
|
||||
public class Purchases {
|
||||
@Table(databaseName = HabitDatabase.NAME)
|
||||
public class Purchases extends BaseModel {
|
||||
|
||||
|
||||
@Column
|
||||
@PrimaryKey
|
||||
@NotNull
|
||||
String user_id;
|
||||
|
||||
public List<Customization> customizations;
|
||||
|
||||
@Column
|
||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "plan_user_id",
|
||||
columnType = String.class,
|
||||
foreignColumnName = "customerId")})
|
||||
private SubscriptionPlan plan;
|
||||
|
||||
public List<Customization> getCustomizations() {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,17 @@
|
|||
package com.magicmicky.habitrpgwrapper.lib.models;
|
||||
|
||||
import com.habitrpg.android.habitica.HabitDatabase;
|
||||
import com.raizlabs.android.dbflow.annotation.Column;
|
||||
import com.raizlabs.android.dbflow.annotation.ForeignKey;
|
||||
import com.raizlabs.android.dbflow.annotation.ForeignKeyReference;
|
||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||
import com.raizlabs.android.dbflow.annotation.Table;
|
||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class SubscriptionPlan {
|
||||
@Table(databaseName = HabitDatabase.NAME)
|
||||
public class SubscriptionPlan extends BaseModel {
|
||||
|
||||
public static String PLANID_BASIC = "basic";
|
||||
public static String PLANID_BASICEARNED = "basic_earned";
|
||||
|
|
@ -11,19 +20,43 @@ public class SubscriptionPlan {
|
|||
public static String PLANID_GOOGLE6MONTH = "google_6mo";
|
||||
public static String PLANID_BASIC12MONTH = "basic_12mo";
|
||||
|
||||
@Column
|
||||
@PrimaryKey
|
||||
public String customerId;
|
||||
@Column
|
||||
public Date dateCreated;
|
||||
@Column
|
||||
public Date dateUpdated;
|
||||
@Column
|
||||
public Date dateTerminated;
|
||||
@Column
|
||||
public String paymentMethod;
|
||||
@Column
|
||||
public String planId;
|
||||
@Column
|
||||
public Integer gemsBought;
|
||||
@Column
|
||||
public Integer extraMonths;
|
||||
@Column
|
||||
public Integer quantity;
|
||||
@Column
|
||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "consecutive_user_id",
|
||||
columnType = String.class,
|
||||
foreignColumnName = "customerId")})
|
||||
public SubscriptionPlanConsecutive consecutive;
|
||||
|
||||
public boolean isActive() {
|
||||
Date today = new Date();
|
||||
return (this.dateCreated != null && this.dateCreated.before(today)) && (this.dateTerminated == null || this.dateTerminated.after(today));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
|
||||
if (consecutive != null) {
|
||||
consecutive.customerId = customerId;
|
||||
}
|
||||
|
||||
super.save();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,24 @@
|
|||
package com.magicmicky.habitrpgwrapper.lib.models;
|
||||
|
||||
public class SubscriptionPlanConsecutive {
|
||||
import com.habitrpg.android.habitica.HabitDatabase;
|
||||
import com.raizlabs.android.dbflow.annotation.Column;
|
||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||
import com.raizlabs.android.dbflow.annotation.Table;
|
||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||
|
||||
@Table(databaseName = HabitDatabase.NAME)
|
||||
public class SubscriptionPlanConsecutive extends BaseModel {
|
||||
|
||||
@Column
|
||||
@PrimaryKey
|
||||
public String customerId;
|
||||
@Column
|
||||
private int trinkets;
|
||||
@Column
|
||||
private int gemCapExtra;
|
||||
@Column
|
||||
private int offset;
|
||||
@Column
|
||||
private int count;
|
||||
|
||||
public int getTrinkets() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue