Don't restore transactions on app launch, only in billing activity after login. Gives server more control over premium status

pull/14/head
Sam Bosley 12 years ago
parent 382451937b
commit b3f41f830c

@ -440,12 +440,12 @@ public class EditPreferences extends TodorooPreferenceActivity {
if (r.getString(R.string.p_account).equals(preference.getKey())) { if (r.getString(R.string.p_account).equals(preference.getKey())) {
int title; int title;
int summary; int summary;
if (ActFmPreferenceService.isPremiumUser() || actFmPreferenceService.isLoggedIn()) { if (!actFmPreferenceService.isLoggedIn()) {
title = R.string.actfm_account_info;
summary = R.string.actfm_account_info_summary;
} else {
title = R.string.account_type_title_not_logged_in; title = R.string.account_type_title_not_logged_in;
summary = R.string.account_type_summary_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.setTitle(title);
preference.setSummary(summary); preference.setSummary(summary);

@ -1,13 +1,14 @@
package com.todoroo.astrid.billing; package com.todoroo.astrid.billing;
import android.app.Activity; import android.app.Activity;
import android.content.DialogInterface;
import android.os.Handler; import android.os.Handler;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.actfm.sync.ActFmSyncService; import com.todoroo.astrid.actfm.sync.ActFmSyncService;
@ -56,6 +57,7 @@ public abstract class AstridPurchaseObserver extends PurchaseObserver {
protected abstract void subscriptionsNotSupportedCallback(); protected abstract void subscriptionsNotSupportedCallback();
@Override @Override
public void onPurchaseStateChange(PurchaseState purchaseState, final String itemId, public void onPurchaseStateChange(PurchaseState purchaseState, final String itemId,
int quantity, long purchaseTime, String developerPayload, final String purchaseToken) { int quantity, long purchaseTime, String developerPayload, final String purchaseToken) {
@ -79,7 +81,13 @@ public abstract class AstridPurchaseObserver extends PurchaseObserver {
mActivity.runOnUiThread(new Runnable() { mActivity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { 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() { mActivity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { 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(); }.start();

@ -62,7 +62,7 @@ public class BillingConstants {
public static final char PUB_KEY_REPLACE_CHAR = 'B'; public static final char PUB_KEY_REPLACE_CHAR = 'B';
public static final String PUB_KEY_OBFUSCATED = "pubkey"; 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. // The response codes for a request, defined by Android Market.
public enum ResponseCode { public enum ResponseCode {

@ -23,7 +23,6 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteException;
import android.media.AudioManager; import android.media.AudioManager;
import android.os.Handler;
import android.util.Log; import android.util.Log;
import android.widget.Toast; 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.BackupConstants;
import com.todoroo.astrid.backup.BackupService; import com.todoroo.astrid.backup.BackupService;
import com.todoroo.astrid.backup.TasksXmlImporter; 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.dao.Database;
import com.todoroo.astrid.gtasks.GtasksPreferenceService; import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.gtasks.sync.GtasksSyncService; import com.todoroo.astrid.gtasks.sync.GtasksSyncService;
@ -198,30 +192,9 @@ public class StartupService {
abTestInvoker.reportAcquisition(); abTestInvoker.reportAcquisition();
final Handler purchaseHandler = new Handler();
// perform startup activities in a background thread // perform startup activities in a background thread
new Thread(new Runnable() { new Thread(new Runnable() {
public void run() { 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 // start widget updating alarm
AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, WidgetUpdateService.class); Intent intent = new Intent(context, WidgetUpdateService.class);

Loading…
Cancel
Save