Use local knowledge of in-app purchases combined with reporting to server to determine premium status

pull/14/head
Sam Bosley 12 years ago
parent d37e594045
commit fac3ba1080

@ -524,7 +524,7 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
Preferences.setString(ActFmPreferenceService.PREF_PICTURE,
result.optString("picture"));
actFmPreferenceService.reloadThisUser();
ActFmPreferenceService.reloadThisUser();
setResult(RESULT_OK);
finish();

@ -12,6 +12,7 @@ import android.text.TextUtils;
import com.timsu.astrid.R;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.billing.BillingConstants;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.service.StatisticsConstants;
@ -77,6 +78,9 @@ public class ActFmPreferenceService extends SyncProviderUtilities {
/** Act.fm current user premium status */
public static final String PREF_PREMIUM = IDENTIFIER + "_premium"; //$NON-NLS-1$
/** Local knowledge of current premium status */
public static final String PREF_LOCAL_PREMIUM = IDENTIFIER + "_local_premium"; //$NON-NLS-1$
/** Act.fm current user picture */
public static final String PREF_PICTURE = IDENTIFIER + "_picture"; //$NON-NLS-1$
@ -144,7 +148,7 @@ public class ActFmPreferenceService extends SyncProviderUtilities {
user.put("name", Preferences.getStringValue(PREF_NAME));
user.put("first_name", Preferences.getStringValue(PREF_FIRST_NAME));
user.put("last_name", Preferences.getStringValue(PREF_LAST_NAME));
user.put("premium", Preferences.getBoolean(PREF_PREMIUM, false));
user.put("premium", isPremiumUser());
user.put("email", Preferences.getStringValue(PREF_EMAIL));
user.put("picture", Preferences.getStringValue(PREF_PICTURE));
user.put("id", Preferences.getLong(PREF_USER_ID, 0));
@ -154,6 +158,9 @@ public class ActFmPreferenceService extends SyncProviderUtilities {
}
public static boolean isPremiumUser() {
if (Preferences.getBoolean(BillingConstants.PREF_NEEDS_SERVER_UPDATE, false)) {
return Preferences.getBoolean(PREF_LOCAL_PREMIUM, false);
}
return Preferences.getBoolean(PREF_PREMIUM, false);
}

@ -938,12 +938,14 @@ public final class ActFmSyncService {
pushAllQueuedUpdates();
}
public void updateUserSubscriptionStatus(Runnable onError) {
public void updateUserSubscriptionStatus(Runnable onSuccess, Runnable onError) {
String purchaseToken = Preferences.getStringValue(BillingConstants.PREF_PURCHASE_TOKEN);
String productId = Preferences.getStringValue(BillingConstants.PREF_PRODUCT_ID);
try {
actFmInvoker.invoke("premium_update_android", "purchaseToken", purchaseToken, "productId", productId);
Preferences.setBoolean(BillingConstants.PREF_NEEDS_SERVER_UPDATE, false);
if (onSuccess != null)
onSuccess.run();
} catch (Exception e) {
Preferences.setBoolean(BillingConstants.PREF_NEEDS_SERVER_UPDATE, true);
if (onError != null)

@ -169,9 +169,9 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
/** fetch user status hash*/
@SuppressWarnings("nls")
private void updateUserStatus() {
public void updateUserStatus() {
if (Preferences.getBoolean(BillingConstants.PREF_NEEDS_SERVER_UPDATE, false)) {
actFmSyncService.updateUserSubscriptionStatus(null);
actFmSyncService.updateUserSubscriptionStatus(null, null);
}
try {

@ -227,8 +227,13 @@ public class BillingActivity extends Activity {
new Thread() {
@Override
public void run() {
Preferences.setBoolean(ActFmPreferenceService.PREF_PREMIUM, true);
Preferences.setBoolean(ActFmPreferenceService.PREF_LOCAL_PREMIUM, true);
actFmSyncService.updateUserSubscriptionStatus(new Runnable() {
@Override
public void run() {
Preferences.setBoolean(ActFmPreferenceService.PREF_PREMIUM, true);
}
}, new Runnable() {
@Override
public void run() {
Toast.makeText(BillingActivity.this, R.string.premium_success_with_server_error, Toast.LENGTH_LONG).show();
@ -240,8 +245,8 @@ public class BillingActivity extends Activity {
new Thread() {
@Override
public void run() {
Preferences.setBoolean(ActFmPreferenceService.PREF_PREMIUM, false);
actFmSyncService.updateUserSubscriptionStatus(null);
Preferences.setBoolean(ActFmPreferenceService.PREF_LOCAL_PREMIUM, false);
actFmSyncService.updateUserSubscriptionStatus(null, null);
}
}.start();
}

Loading…
Cancel
Save