From b3f41f830cd434e9abfecb46b9f155cfb4164b76 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Fri, 24 Aug 2012 14:17:03 -0700 Subject: [PATCH] Don't restore transactions on app launch, only in billing activity after login. Gives server more control over premium status --- .../astrid/activity/EditPreferences.java | 8 +++--- .../billing/AstridPurchaseObserver.java | 22 ++++++++++++--- .../astrid/billing/BillingConstants.java | 2 +- .../astrid/service/StartupService.java | 27 ------------------- 4 files changed, 24 insertions(+), 35 deletions(-) diff --git a/astrid/src/com/todoroo/astrid/activity/EditPreferences.java b/astrid/src/com/todoroo/astrid/activity/EditPreferences.java index d3e127503..970337a79 100644 --- a/astrid/src/com/todoroo/astrid/activity/EditPreferences.java +++ b/astrid/src/com/todoroo/astrid/activity/EditPreferences.java @@ -440,12 +440,12 @@ public class EditPreferences extends TodorooPreferenceActivity { if (r.getString(R.string.p_account).equals(preference.getKey())) { int title; int summary; - if (ActFmPreferenceService.isPremiumUser() || actFmPreferenceService.isLoggedIn()) { - title = R.string.actfm_account_info; - summary = R.string.actfm_account_info_summary; - } else { + if (!actFmPreferenceService.isLoggedIn()) { title = R.string.account_type_title_not_logged_in; summary = R.string.account_type_summary_not_logged_in; + } else { + title = R.string.actfm_account_info; + summary = R.string.actfm_account_info_summary; } preference.setTitle(title); preference.setSummary(summary); diff --git a/astrid/src/com/todoroo/astrid/billing/AstridPurchaseObserver.java b/astrid/src/com/todoroo/astrid/billing/AstridPurchaseObserver.java index 8f438d3a7..e22c87f34 100644 --- a/astrid/src/com/todoroo/astrid/billing/AstridPurchaseObserver.java +++ b/astrid/src/com/todoroo/astrid/billing/AstridPurchaseObserver.java @@ -1,13 +1,14 @@ package com.todoroo.astrid.billing; import android.app.Activity; +import android.content.DialogInterface; import android.os.Handler; import android.util.Log; -import android.widget.Toast; import com.timsu.astrid.R; import com.todoroo.andlib.service.Autowired; 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.actfm.sync.ActFmSyncService; @@ -56,6 +57,7 @@ public abstract class AstridPurchaseObserver extends PurchaseObserver { protected abstract void subscriptionsNotSupportedCallback(); + @Override public void onPurchaseStateChange(PurchaseState purchaseState, final String itemId, int quantity, long purchaseTime, String developerPayload, final String purchaseToken) { @@ -79,7 +81,13 @@ public abstract class AstridPurchaseObserver extends PurchaseObserver { mActivity.runOnUiThread(new Runnable() { @Override public void run() { - Toast.makeText(mActivity, R.string.premium_success, Toast.LENGTH_LONG).show(); + DialogUtilities.okDialog(mActivity, mActivity.getString(R.string.DLG_information_title), + 0, mActivity.getString(R.string.premium_success), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + mActivity.finish(); + } + }); } }); } @@ -89,11 +97,19 @@ public abstract class AstridPurchaseObserver extends PurchaseObserver { mActivity.runOnUiThread(new Runnable() { @Override public void run() { - Toast.makeText(mActivity, R.string.premium_success_with_server_error, Toast.LENGTH_LONG).show(); + DialogUtilities.okDialog(mActivity, mActivity.getString(R.string.DLG_information_title), + 0, mActivity.getString(R.string.premium_success_with_server_error), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + mActivity.finish(); + } + }); } }); } }); + } else { + Preferences.setBoolean(BillingConstants.PREF_NEEDS_SERVER_UPDATE, true); } } }.start(); diff --git a/astrid/src/com/todoroo/astrid/billing/BillingConstants.java b/astrid/src/com/todoroo/astrid/billing/BillingConstants.java index b382e5aff..a29415dbd 100644 --- a/astrid/src/com/todoroo/astrid/billing/BillingConstants.java +++ b/astrid/src/com/todoroo/astrid/billing/BillingConstants.java @@ -62,7 +62,7 @@ public class BillingConstants { public static final char PUB_KEY_REPLACE_CHAR = 'B'; public static final String PUB_KEY_OBFUSCATED = "pubkey"; - public static final boolean DEBUG = false || Constants.DEBUG; + public static final boolean DEBUG = true || Constants.DEBUG; // The response codes for a request, defined by Android Market. public enum ResponseCode { diff --git a/astrid/src/com/todoroo/astrid/service/StartupService.java b/astrid/src/com/todoroo/astrid/service/StartupService.java index b9643417a..66b0b8095 100644 --- a/astrid/src/com/todoroo/astrid/service/StartupService.java +++ b/astrid/src/com/todoroo/astrid/service/StartupService.java @@ -23,7 +23,6 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.database.sqlite.SQLiteException; import android.media.AudioManager; -import android.os.Handler; import android.util.Log; import android.widget.Toast; @@ -42,11 +41,6 @@ import com.todoroo.astrid.activity.BeastModePreferences; import com.todoroo.astrid.backup.BackupConstants; import com.todoroo.astrid.backup.BackupService; import com.todoroo.astrid.backup.TasksXmlImporter; -import com.todoroo.astrid.billing.AstridPurchaseObserver; -import com.todoroo.astrid.billing.BillingConstants; -import com.todoroo.astrid.billing.BillingService; -import com.todoroo.astrid.billing.PurchaseObserver; -import com.todoroo.astrid.billing.ResponseHandler; import com.todoroo.astrid.dao.Database; import com.todoroo.astrid.gtasks.GtasksPreferenceService; import com.todoroo.astrid.gtasks.sync.GtasksSyncService; @@ -198,30 +192,9 @@ public class StartupService { abTestInvoker.reportAcquisition(); - final Handler purchaseHandler = new Handler(); - // perform startup activities in a background thread new Thread(new Runnable() { public void run() { - final BillingService billingService = new BillingService(); - billingService.setContext(context); - PurchaseObserver purchaseObserver = new AstridPurchaseObserver(context, purchaseHandler) { - - @Override - protected void billingSupportedCallback() { - billingService.restoreTransactions(); - } - - @Override - protected void subscriptionsNotSupportedCallback() {/**/} - - @Override - protected void billingNotSupportedCallback() {/**/} - }; - - ResponseHandler.register(purchaseObserver); - billingService.checkBillingSupported(BillingConstants.ITEM_TYPE_SUBSCRIPTION); - // start widget updating alarm AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, WidgetUpdateService.class);