Finish button and listener logic for sync upgrade prompts

pull/14/head
Sam Bosley 11 years ago
parent bab8092c97
commit 1ea5d2cbf6

@ -2,6 +2,7 @@ package com.todoroo.astrid.actfm.sync;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.util.TypedValue;
import android.view.View;
import android.view.View.OnClickListener;
@ -11,40 +12,68 @@ import android.widget.TextView;
import com.timsu.astrid.R;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.ActFmLoginActivity;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.gtasks.sync.GtasksSyncV2Provider;
public class SyncUpgradePrompt {
private static final String P_SYNC_UPGRADE_PROMPT = "p_sync_upgr_prompt"; //$NON-NLS-1$
private static long lastPromptDate = -1;
public static void showSyncUpgradePrompt(Activity activity) {
public static void showSyncUpgradePrompt(final Activity activity) {
if (lastPromptDate == -1)
lastPromptDate = Preferences.getLong(P_SYNC_UPGRADE_PROMPT, 0L);
Dialog d = null;
Dialog d;
if (DateUtilities.now() - lastPromptDate > DateUtilities.ONE_WEEK * 3) {
if (!PluginServices.getActFmPreferenceService().isLoggedIn()) {
if (PluginServices.getGtasksPreferenceService().isLoggedIn()) {
// Logged into google but not astrid
// TODO: Buttons and listeners
d = getDialog(activity, R.string.sync_upgr_gtasks_only_title, R.string.sync_upgr_gtasks_only_body);
d = getDialog(activity, R.string.sync_upgr_gtasks_only_title, R.string.sync_upgr_gtasks_only_body,
R.string.sync_upgr_gtasks_only_btn1, new Runnable() {
@Override
public void run() {
GtasksSyncV2Provider.getInstance().signOut();
activity.startActivity(new Intent(activity, ActFmLoginActivity.class));
}
},
R.string.sync_upgr_gtasks_only_btn2,
null);
} else {
// Logged into neither
// TODO: Buttons and listeners
d = getDialog(activity, R.string.sync_upgr_neither_title, R.string.sync_upgr_neither_body);
// TODO: Buttons and listeners
d = getDialog(activity, R.string.sync_upgr_neither_title, R.string.sync_upgr_neither_body,
R.string.sync_upgr_neither_btn1, new Runnable() {
@Override
public void run() {
activity.startActivity(new Intent(activity, ActFmLoginActivity.class));
}
});
}
setLastPromptDate(DateUtilities.now());
} else if (PluginServices.getGtasksPreferenceService().isLoggedIn()) {
// Logged into both
// TODO: Buttons and listeners
d = getDialog(activity, R.string.sync_upgr_both_title, R.string.sync_upgr_both_body);
d = getDialog(activity, R.string.sync_upgr_both_title, R.string.sync_upgr_both_body,
R.string.sync_upgr_both_btn1,
null,
R.string.sync_upgr_both_btn2, new Runnable() {
@Override
public void run() {
new ActFmSyncV2Provider().signOut();
}
});
setLastPromptDate(Long.MAX_VALUE);
} else {
// Logged into just astrid--don't need to show prompts anymore
d = null;
setLastPromptDate(Long.MAX_VALUE);
}
} else {
d = null;
}
if (d != null)
d.show();
}
@ -55,7 +84,7 @@ public class SyncUpgradePrompt {
}
private static Dialog getDialog(Activity activity, int title, int body, Object... buttonsAndListeners) {
Dialog d = new Dialog(activity, R.style.ReminderDialog);
final Dialog d = new Dialog(activity, R.style.ReminderDialog);
d.setContentView(R.layout.astrid_reminder_view);
((TextView) d.findViewById(R.id.reminder_title)).setText(title);
((TextView) d.findViewById(R.id.reminder_message)).setText(body);
@ -65,20 +94,34 @@ public class SyncUpgradePrompt {
activity.getTheme().resolveAttribute(R.attr.asThemeTextColor, tv, false);
int button1 = (Integer) buttonsAndListeners[0];
OnClickListener listener1 = (OnClickListener) buttonsAndListeners[1];
final Runnable listener1 = (Runnable) buttonsAndListeners[1];
Button b1 = (Button) d.findViewById(R.id.reminder_edit);
b1.setText(button1);
b1.setOnClickListener(listener1);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
d.dismiss();
if (listener1 != null)
listener1.run();
}
});
b1.setTextColor(activity.getResources().getColor(tv.data));
if (buttonsAndListeners.length < 3) {
d.findViewById(R.id.reminder_snooze).setVisibility(View.GONE);
} else {
int button2 = (Integer) buttonsAndListeners[2];
OnClickListener listener2 = (OnClickListener) buttonsAndListeners[3];
final Runnable listener2 = (Runnable) buttonsAndListeners[3];
Button b2 = (Button) d.findViewById(R.id.reminder_snooze);
b2.setText(button2);
b2.setOnClickListener(listener2);
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
d.dismiss();
if (listener2 != null)
listener2.run();
}
});
b2.setTextColor(activity.getResources().getColor(tv.data));
}

@ -343,11 +343,18 @@
<!-- Sync upgrade messages -->
<string name="sync_upgr_both_title">Using Astrid.com + Google without Duplicates</string>
<string name="sync_upgr_both_body">Let\'s be honest. Google Tasks is convenient but not as cool as Astrid. To avoid duplicates you can no longer sync with Astrid.com and background sync with Google Tasks at the same time. You can still import your Google Tasks by visiting Settings → Backup &amp; Sync</string>
<string name="sync_upgr_both_body">Let\'s be honest. Google Tasks is convenient but not as cool as Astrid. To avoid duplicates you can no longer sync with Astrid.com and background sync with Google Tasks at the same time. You can still import your Google Tasks by visiting Settings → Backup &amp; Sync, or downgrade to Google Tasks only sync</string>
<string name="sync_upgr_both_btn1">Stick with Astrid</string>
<string name="sync_upgr_both_btn2">Downgrade to Google Tasks</string>
<string name="sync_upgr_gtasks_only_title">Upgrade to Astrid Sync for Free!</string>
<string name="sync_upgr_gtasks_only_body">Access your tasks from all your devices and from Gmail with Astrid.com sync. Upgrade to Astrid.com Sync (you can always go back to Google Tasks - but you won\'t want to)!</string>
<string name="sync_upgr_gtasks_only_btn1">Upgrade to Astrid Sync</string>
<string name="sync_upgr_gtasks_only_btn2">Stick with Google Tasks</string>
<string name="sync_upgr_neither_title">Free backup &amp; Sync!</string>
<string name="sync_upgr_neither_body">Don\'t put your to-dos at risk! New and improved Astrid sync to keep and access your tasks from anywhere.</string>
<string name="sync_upgr_neither_btn1">Sign up now</string>
</resources>

Loading…
Cancel
Save