diff --git a/astrid/res/layout/billing_activity.xml b/astrid/res/layout/billing_activity.xml
index b613a0bda..a7837a29e 100644
--- a/astrid/res/layout/billing_activity.xml
+++ b/astrid/res/layout/billing_activity.xml
@@ -38,42 +38,58 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
+
diff --git a/astrid/res/values/strings-premium.xml b/astrid/res/values/strings-premium.xml
index 4f031b070..67446016d 100644
--- a/astrid/res/values/strings-premium.xml
+++ b/astrid/res/values/strings-premium.xml
@@ -95,5 +95,7 @@
Thanks for subscribing to Astrid Premium!
Thanks for subscribing to Astrid Premium! The new features will be unlocked for you on astrid.com soon, and should be available on your phone right away.
The premium subscription for this Google Play account is connected to a different user. To link additional emails to your account, visit astrid.com/users/profile
+ Already purchased premium? Click here to check Google Play for purchase history.
+ Checking for purchases...
diff --git a/astrid/src/com/todoroo/astrid/billing/AstridPurchaseObserver.java b/astrid/src/com/todoroo/astrid/billing/AstridPurchaseObserver.java
index 731719fe7..aa605914a 100644
--- a/astrid/src/com/todoroo/astrid/billing/AstridPurchaseObserver.java
+++ b/astrid/src/com/todoroo/astrid/billing/AstridPurchaseObserver.java
@@ -26,6 +26,12 @@ public abstract class AstridPurchaseObserver extends PurchaseObserver {
@Autowired
private ActFmPreferenceService actFmPreferenceService;
+ public interface RestoreTransactionsListener {
+ public void restoreTransactionsResponse(ResponseCode responseCode);
+ }
+
+ private RestoreTransactionsListener restoreTransactionsListener;
+
/**
* A {@link PurchaseObserver} is used to get callbacks when Android Market sends
* messages to this application so that we can update the UI.
@@ -35,6 +41,10 @@ public abstract class AstridPurchaseObserver extends PurchaseObserver {
DependencyInjectionService.getInstance().inject(this);
}
+ public void setRestoreTransactionsListener(RestoreTransactionsListener listener) {
+ this.restoreTransactionsListener = listener;
+ }
+
@Override
public void onBillingSupported(boolean supported, String type) {
if (BillingConstants.DEBUG) {
@@ -172,6 +182,8 @@ public abstract class AstridPurchaseObserver extends PurchaseObserver {
Log.d(TAG, "RestoreTransactions error: " + responseCode);
}
}
+ if (restoreTransactionsListener != null)
+ restoreTransactionsListener.restoreTransactionsResponse(responseCode);
}
}
diff --git a/astrid/src/com/todoroo/astrid/billing/BillingActivity.java b/astrid/src/com/todoroo/astrid/billing/BillingActivity.java
index bbd7b5545..a9ca63782 100644
--- a/astrid/src/com/todoroo/astrid/billing/BillingActivity.java
+++ b/astrid/src/com/todoroo/astrid/billing/BillingActivity.java
@@ -4,6 +4,7 @@ import java.util.Locale;
import android.app.AlertDialog;
import android.app.Dialog;
+import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
@@ -31,9 +32,10 @@ import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
+import com.todoroo.astrid.billing.BillingConstants.ResponseCode;
import com.todoroo.astrid.service.ThemeService;
-public class BillingActivity extends FragmentActivity {
+public class BillingActivity extends FragmentActivity implements AstridPurchaseObserver.RestoreTransactionsListener {
private static final int DIALOG_CANNOT_CONNECT_ID = 1;
private static final int DIALOG_BILLING_NOT_SUPPORTED_ID = 2;
@@ -44,6 +46,9 @@ public class BillingActivity extends FragmentActivity {
private AstridPurchaseObserver purchaseObserver;
private Button buyMonth;
private Button buyYear;
+ private TextView restorePurchases;
+
+ private ProgressDialog restoreTransactionsDialog;
@Autowired private ActFmPreferenceService actFmPreferenceService;
@@ -67,9 +72,10 @@ public class BillingActivity extends FragmentActivity {
purchaseObserver = new AstridPurchaseObserver(this, handler) {
@Override
protected void billingSupportedCallback() {
- restoreTransactions();
+ restoreTransactions(false);
buyMonth.setEnabled(true);
buyYear.setEnabled(true);
+ restorePurchases.setEnabled(true);
}
@Override
@@ -82,7 +88,7 @@ public class BillingActivity extends FragmentActivity {
showDialog(DIALOG_SUBSCRIPTIONS_NOT_SUPPORTED_ID);
}
};
-
+ purchaseObserver.setRestoreTransactionsListener(this);
}
private void setupActionBar() {
@@ -140,9 +146,11 @@ public class BillingActivity extends FragmentActivity {
private void setupButtons() {
buyMonth = (Button) findViewById(R.id.premium_buy_month);
buyYear = (Button) findViewById(R.id.premium_buy_year);
+ restorePurchases = (TextView) findViewById(R.id.check_for_purchases);
buyMonth.setEnabled(false);
buyYear.setEnabled(false);
+ restorePurchases.setEnabled(false);
buyMonth.setOnClickListener(new OnClickListener() {
@Override
@@ -163,11 +171,18 @@ public class BillingActivity extends FragmentActivity {
}
}
});
+
+ restorePurchases.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ restoreTransactions(true);
+ }
+ });
}
@SuppressWarnings("nls")
private void setupText() {
- int[] bullets = new int[] { R.string.premium_description_1, R.string.premium_description_2, R.string.premium_description_3,
+ int[] bullets = new int[] { R.string.premium_description_1, /* R.string.premium_description_2,*/ R.string.premium_description_3,
R.string.premium_description_4, R.string.premium_description_5, R.string.premium_description_6
};
@@ -276,11 +291,14 @@ public class BillingActivity extends FragmentActivity {
return builder.create();
}
- private void restoreTransactions() {
+ private void restoreTransactions(boolean force) {
boolean initialized = Preferences.getBoolean(BillingConstants.PREF_TRANSACTIONS_INITIALIZED, false);
- if (!initialized) {
+ if (!initialized || force) {
billingService.restoreTransactions();
}
+ if (force) {
+ restoreTransactionsDialog = DialogUtilities.progressDialog(this, getString(R.string.premium_checking_for_purchases));
+ }
}
@Override
@@ -291,4 +309,10 @@ public class BillingActivity extends FragmentActivity {
}
return super.onOptionsItemSelected(item);
}
+
+ @Override
+ public void restoreTransactionsResponse(ResponseCode responseCode) {
+ DialogUtilities.dismissDialog(this, restoreTransactionsDialog);
+ restoreTransactionsDialog = null;
+ }
}