Added a button that users can click to manually restore transactions in the billing activity (in case something goes wrong)

pull/14/head
Sam Bosley 13 years ago
parent 3f32ccd887
commit 380d019593

@ -38,42 +38,58 @@
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="vertical"
android:gravity="center_vertical" android:gravity="center_vertical"
android:background="@android:color/white"> android:background="@android:color/white">
<LinearLayout
<Button android:layout_width="fill_parent"
android:id="@+id/premium_buy_month" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:orientation="horizontal"
android:layout_height="50dip" android:gravity="center_vertical"
android:layout_marginLeft="8dip" android:background="@android:color/white">
android:layout_marginRight="8dip"
android:layout_marginBottom="8dip" <Button
android:layout_marginTop="8dip" android:id="@+id/premium_buy_month"
android:layout_weight="1" android:layout_width="fill_parent"
android:background="#707070" android:layout_height="50dip"
android:textColor="@android:color/white" android:layout_marginLeft="8dip"
android:textStyle="bold" android:layout_marginRight="8dip"
android:textSize="24sp" android:layout_marginBottom="8dip"
android:text="@string/premium_buy_month" android:layout_marginTop="8dip"
android:gravity="center"/> android:layout_weight="1"
android:background="#707070"
<Button android:textColor="@android:color/white"
android:id="@+id/premium_buy_year" android:textStyle="bold"
android:layout_width="fill_parent" android:textSize="24sp"
android:layout_height="50dip" android:text="@string/premium_buy_month"
android:layout_marginLeft="8dip" android:gravity="center"/>
android:layout_marginRight="8dip"
android:layout_marginBottom="8dip" <Button
android:layout_marginTop="8dip" android:id="@+id/premium_buy_year"
android:layout_weight="1" android:layout_width="fill_parent"
android:background="?attr/asThemeTextColor" android:layout_height="50dip"
android:textColor="@android:color/white" android:layout_marginLeft="8dip"
android:textSize="24sp" android:layout_marginRight="8dip"
android:textStyle="bold" android:layout_marginBottom="8dip"
android:text="@string/premium_buy_year" android:layout_marginTop="8dip"
android:gravity="center" /> android:layout_weight="1"
android:background="?attr/asThemeTextColor"
android:textColor="@android:color/white"
android:textSize="24sp"
android:textStyle="bold"
android:text="@string/premium_buy_year"
android:gravity="center" />
</LinearLayout>
<TextView
android:id="@+id/check_for_purchases"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:textColor="#404040"
android:gravity="center"
android:text="@string/premium_check_for_purchases"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

@ -95,5 +95,7 @@
<string name="premium_success">Thanks for subscribing to Astrid Premium!</string> <string name="premium_success">Thanks for subscribing to Astrid Premium!</string>
<string name="premium_success_with_server_error">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.</string> <string name="premium_success_with_server_error">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.</string>
<string name="premium_verification_error">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</string> <string name="premium_verification_error">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</string>
<string name="premium_check_for_purchases">Already purchased premium? Click here to check Google Play for purchase history.</string>
<string name="premium_checking_for_purchases">Checking for purchases...</string>
</resources> </resources>

@ -26,6 +26,12 @@ public abstract class AstridPurchaseObserver extends PurchaseObserver {
@Autowired @Autowired
private ActFmPreferenceService actFmPreferenceService; 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 * A {@link PurchaseObserver} is used to get callbacks when Android Market sends
* messages to this application so that we can update the UI. * 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); DependencyInjectionService.getInstance().inject(this);
} }
public void setRestoreTransactionsListener(RestoreTransactionsListener listener) {
this.restoreTransactionsListener = listener;
}
@Override @Override
public void onBillingSupported(boolean supported, String type) { public void onBillingSupported(boolean supported, String type) {
if (BillingConstants.DEBUG) { if (BillingConstants.DEBUG) {
@ -172,6 +182,8 @@ public abstract class AstridPurchaseObserver extends PurchaseObserver {
Log.d(TAG, "RestoreTransactions error: " + responseCode); Log.d(TAG, "RestoreTransactions error: " + responseCode);
} }
} }
if (restoreTransactionsListener != null)
restoreTransactionsListener.restoreTransactionsResponse(responseCode);
} }
} }

@ -4,6 +4,7 @@ import java.util.Locale;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; 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.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.billing.BillingConstants.ResponseCode;
import com.todoroo.astrid.service.ThemeService; 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_CANNOT_CONNECT_ID = 1;
private static final int DIALOG_BILLING_NOT_SUPPORTED_ID = 2; private static final int DIALOG_BILLING_NOT_SUPPORTED_ID = 2;
@ -44,6 +46,9 @@ public class BillingActivity extends FragmentActivity {
private AstridPurchaseObserver purchaseObserver; private AstridPurchaseObserver purchaseObserver;
private Button buyMonth; private Button buyMonth;
private Button buyYear; private Button buyYear;
private TextView restorePurchases;
private ProgressDialog restoreTransactionsDialog;
@Autowired private ActFmPreferenceService actFmPreferenceService; @Autowired private ActFmPreferenceService actFmPreferenceService;
@ -67,9 +72,10 @@ public class BillingActivity extends FragmentActivity {
purchaseObserver = new AstridPurchaseObserver(this, handler) { purchaseObserver = new AstridPurchaseObserver(this, handler) {
@Override @Override
protected void billingSupportedCallback() { protected void billingSupportedCallback() {
restoreTransactions(); restoreTransactions(false);
buyMonth.setEnabled(true); buyMonth.setEnabled(true);
buyYear.setEnabled(true); buyYear.setEnabled(true);
restorePurchases.setEnabled(true);
} }
@Override @Override
@ -82,7 +88,7 @@ public class BillingActivity extends FragmentActivity {
showDialog(DIALOG_SUBSCRIPTIONS_NOT_SUPPORTED_ID); showDialog(DIALOG_SUBSCRIPTIONS_NOT_SUPPORTED_ID);
} }
}; };
purchaseObserver.setRestoreTransactionsListener(this);
} }
private void setupActionBar() { private void setupActionBar() {
@ -140,9 +146,11 @@ public class BillingActivity extends FragmentActivity {
private void setupButtons() { private void setupButtons() {
buyMonth = (Button) findViewById(R.id.premium_buy_month); buyMonth = (Button) findViewById(R.id.premium_buy_month);
buyYear = (Button) findViewById(R.id.premium_buy_year); buyYear = (Button) findViewById(R.id.premium_buy_year);
restorePurchases = (TextView) findViewById(R.id.check_for_purchases);
buyMonth.setEnabled(false); buyMonth.setEnabled(false);
buyYear.setEnabled(false); buyYear.setEnabled(false);
restorePurchases.setEnabled(false);
buyMonth.setOnClickListener(new OnClickListener() { buyMonth.setOnClickListener(new OnClickListener() {
@Override @Override
@ -163,11 +171,18 @@ public class BillingActivity extends FragmentActivity {
} }
} }
}); });
restorePurchases.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
restoreTransactions(true);
}
});
} }
@SuppressWarnings("nls") @SuppressWarnings("nls")
private void setupText() { 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 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(); return builder.create();
} }
private void restoreTransactions() { private void restoreTransactions(boolean force) {
boolean initialized = Preferences.getBoolean(BillingConstants.PREF_TRANSACTIONS_INITIALIZED, false); boolean initialized = Preferences.getBoolean(BillingConstants.PREF_TRANSACTIONS_INITIALIZED, false);
if (!initialized) { if (!initialized || force) {
billingService.restoreTransactions(); billingService.restoreTransactions();
} }
if (force) {
restoreTransactionsDialog = DialogUtilities.progressDialog(this, getString(R.string.premium_checking_for_purchases));
}
} }
@Override @Override
@ -291,4 +309,10 @@ public class BillingActivity extends FragmentActivity {
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@Override
public void restoreTransactionsResponse(ResponseCode responseCode) {
DialogUtilities.dismissDialog(this, restoreTransactionsDialog);
restoreTransactionsDialog = null;
}
} }

Loading…
Cancel
Save