From b66377901ac97c628b3e9bcd2e41dbcc02e614b7 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Mon, 4 Jun 2012 12:55:33 -0700 Subject: [PATCH] Copy updates, more reengagement strings --- .../reminders/ReengagementFragment.java | 6 ++- .../reminders/ReengagementReceiver.java | 47 ++++++++++++++++++- astrid/res/values/strings-reminders.xml | 28 +++++++++-- 3 files changed, 72 insertions(+), 9 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/ReengagementFragment.java b/astrid/plugin-src/com/todoroo/astrid/reminders/ReengagementFragment.java index 7a139c192..7eaa44082 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/ReengagementFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/ReengagementFragment.java @@ -12,6 +12,8 @@ import com.todoroo.astrid.service.ThemeService; public class ReengagementFragment extends DisposableTaskListFragment { + public static final String EXTRA_TEXT = "dialogText"; //$NON-NLS-1$ + @Override protected void initializeData() { // hide quick add @@ -25,7 +27,6 @@ public class ReengagementFragment extends DisposableTaskListFragment { snooze.setBackgroundColor(r.getColor(ThemeService.getThemeColor())); TextView reminder = (TextView) getView().findViewById(R.id.reminder_message); if (taskAdapter.getCount() == 0) { - reminder.setText(Notifications.getRandomReminder(r.getStringArray(R.array.rmd_reengage_dialog_empty_options))); snooze.setText(R.string.rmd_reengage_add_tasks); snooze.setOnClickListener(new OnClickListener() { @Override @@ -34,7 +35,6 @@ public class ReengagementFragment extends DisposableTaskListFragment { } }); } else { - reminder.setText(Notifications.getRandomReminder(r.getStringArray(R.array.rmd_reengage_dialog_options))); snooze.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { @@ -42,6 +42,8 @@ public class ReengagementFragment extends DisposableTaskListFragment { } }); } + + reminder.setText(extras.getString(EXTRA_TEXT)); } @Override diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/ReengagementReceiver.java b/astrid/plugin-src/com/todoroo/astrid/reminders/ReengagementReceiver.java index 399ba1195..68a09b261 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/ReengagementReceiver.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/ReengagementReceiver.java @@ -1,5 +1,7 @@ package com.todoroo.astrid.reminders; +import org.json.JSONObject; + import android.app.Notification; import android.app.PendingIntent; import android.content.BroadcastReceiver; @@ -7,27 +9,41 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.graphics.Color; +import android.os.Bundle; +import android.text.TextUtils; import com.timsu.astrid.R; +import com.todoroo.andlib.data.TodorooCursor; +import com.todoroo.andlib.service.Autowired; +import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.NotificationManager; import com.todoroo.andlib.service.NotificationManager.AndroidNotificationManager; +import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.QueryTemplate; import com.todoroo.andlib.utility.Preferences; +import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; import com.todoroo.astrid.activity.TaskListActivity; import com.todoroo.astrid.activity.TaskListFragment; import com.todoroo.astrid.api.FilterWithCustomIntent; import com.todoroo.astrid.core.SortHelper; +import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.TaskApiDao.TaskCriteria; +import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.service.abtesting.ABChooser; import com.todoroo.astrid.service.abtesting.ABTests; import com.todoroo.astrid.utility.Constants; public class ReengagementReceiver extends BroadcastReceiver { + @Autowired ActFmPreferenceService actFmPreferenceService; + + @Autowired TaskService taskService; + private static final int TASK_LIMIT = 3; @Override public void onReceive(Context context, Intent intent) { + DependencyInjectionService.getInstance().inject(this); if (ABChooser.readChoiceForTest(ABTests.AB_TEST_REENGAGEMENT_ENABLED) == 0) return; @@ -39,18 +55,45 @@ public class ReengagementReceiver extends BroadcastReceiver { QueryTemplate template = new QueryTemplate().where(TaskCriteria.activeVisibleMine()); String sql = SortHelper.adjustQueryForFlagsAndSort(template.toString(), 0, SortHelper.SORT_AUTO) + " LIMIT " + TASK_LIMIT; //$NON-NLS-1$ + boolean hasTasks = false; + TodorooCursor tasks = taskService.query(Query.select(Task.ID).where(TaskCriteria.activeVisibleMine()).limit(TASK_LIMIT)); + try { + hasTasks = tasks.getCount() > 0; + } finally { + tasks.close(); + } + + String title = Notifications.getRandomReminder(context.getResources().getStringArray(R.array.rmd_reengage_notif_titles)); + if (title.contains("%s")) { //$NON-NLS-1$ + String name = ""; //$NON-NLS-1$ + if (actFmPreferenceService.isLoggedIn()) { + JSONObject thisUser = ActFmPreferenceService.thisUser(); + name = thisUser.optString("first_name"); //$NON-NLS-1$ + if (TextUtils.isEmpty(name)) + name = thisUser.optString("name"); //$NON-NLS-1$ + if (TextUtils.isEmpty(name)) + name = context.getString(R.string.rmd_reengage_name_default); + } + title = String.format(title, name); + } + + String text = Notifications.getRandomReminder(context.getResources().getStringArray(hasTasks ? R.array.rmd_reengage_dialog_options : R.array.rmd_reengage_dialog_empty_options)); + FilterWithCustomIntent filter = new FilterWithCustomIntent(context.getString(R.string.rmd_NoA_filter), context.getString(R.string.rmd_NoA_filter), sql, null); filter.customTaskList = new ComponentName(context, ReengagementFragment.class); + filter.customExtras = new Bundle(); + filter.customExtras.putString(ReengagementFragment.EXTRA_TEXT, text); notifIntent.setAction("NOTIFY_reengagement"); //$NON-NLS-1$ notifIntent.putExtra(TaskListFragment.TOKEN_FILTER, filter); + notifIntent.putExtra(ReengagementFragment.EXTRA_TEXT, text); notifIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); notifIntent.putExtra(TaskListActivity.TOKEN_SOURCE, Constants.SOURCE_REENGAGEMENT); - String text = context.getString(R.string.rmd_reengage_notif); + NotificationManager manager = new AndroidNotificationManager(context); Notification notification = new Notification(R.drawable.notif_astrid, text, System.currentTimeMillis()); @@ -59,7 +102,7 @@ public class ReengagementReceiver extends BroadcastReceiver { 0, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, - "", //$NON-NLS-1$ + title, text, pendingIntent); diff --git a/astrid/res/values/strings-reminders.xml b/astrid/res/values/strings-reminders.xml index dfae27646..6d154f591 100644 --- a/astrid/res/values/strings-reminders.xml +++ b/astrid/res/values/strings-reminders.xml @@ -61,19 +61,37 @@ Reminder: - - Here are some tasks you might have missed! - + + + A note from Astrid + Memo for %s. + Your Astrid digest + Reminders from Astrid + + + you + Snooze all Add a task - Time to shorten your to-do list! + Time to shorten your to-do list! + Dear sir or madam, some tasks await your inspection! + Hi there, could you take a look at these? + I\'ve got some tasks with your name on them! + A fresh batch of tasks for you today! + You look fabulous! Ready to get started? + A lovely day for getting some work done, I think! - Don\'t you want to get organized? + Don\'t you want to get organized? + I\'m Astrid! I\'m here to help you do more! + You look busy! Let me take some of those tasks off of your plate. + I can help you keep track of all of the details in your life. + You\'re serious about getting more done? So am I! + Pleasure to make your acquaintance!