Reengagement notifications are working in full

pull/14/head
Sam Bosley 13 years ago
parent cfcbc468c8
commit 27c3d3cd4a

@ -210,7 +210,7 @@
</intent-filter>
</receiver>
<receiver android:name="com.todoroo.astrid.reminder.ReengagementReceiver">
<receiver android:name="com.todoroo.astrid.reminders.ReengagementReceiver">
<intent-filter>
<action android:name="com.timsu.astrid.SHOW_REENGAGEMENT"/>
</intent-filter>

@ -43,7 +43,6 @@ import com.todoroo.astrid.activity.DisposableTaskListFragment;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.repeats.RepeatControlSet;
import com.todoroo.astrid.service.StartupService;
import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.ui.NumberPicker;
@ -66,13 +65,6 @@ public class NotificationFragment extends DisposableTaskListFragment implements
private long taskId;
@Override
public void onCreate(Bundle savedInstanceState) {
StartupService.bypassInitialization();
super.onCreate(savedInstanceState);
}
/* (non-Javadoc)
* @see com.todoroo.astrid.activity.TaskListActivity#onActivityCreated(android.os.Bundle)
*/

@ -1,63 +0,0 @@
package com.todoroo.astrid.reminders;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.service.StartupService;
import com.todoroo.astrid.service.ThemeService;
public class ReengagementActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
new StartupService().onStartupApplication(this);
super.onCreate(savedInstanceState);
DependencyInjectionService.getInstance().inject(this);
setContentView(R.layout.reengagement_activity);
setUpUi();
}
private void setUpUi() {
View dismiss1 = findViewById(R.id.dismiss);
View dismiss2 = findViewById(R.id.dismiss_button);
OnClickListener dismissListener = new OnClickListener() {
@Override
public void onClick(View v) {
finish();
AndroidUtilities.callOverridePendingTransition(ReengagementActivity.this, 0, android.R.anim.fade_out);
}
};
dismiss1.setOnClickListener(dismissListener);
dismiss2.setOnClickListener(dismissListener);
TextView seeTasksButton = (TextView) findViewById(R.id.see_tasks_button);
seeTasksButton.setBackgroundColor(getResources().getColor(ThemeService.getThemeColor()));
seeTasksButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//
}
});
((TextView) findViewById(R.id.reminder_title)).setText("TITLE");
if (!Preferences.getBoolean(R.string.p_rmd_nagging, true)) {
findViewById(R.id.missed_calls_speech_bubble).setVisibility(View.GONE);
} else {
TextView dialogView = (TextView) findViewById(R.id.reminder_message);
dialogView.setText(Notifications.getRandomReminder(getResources().getStringArray(R.array.rmd_reengage_dialog_options)));
}
}
}

@ -0,0 +1,49 @@
package com.todoroo.astrid.reminders;
import android.content.res.Resources;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;
import com.timsu.astrid.R;
import com.todoroo.astrid.activity.DisposableTaskListFragment;
import com.todoroo.astrid.service.ThemeService;
public class ReengagementFragment extends DisposableTaskListFragment {
@Override
protected void initializeData() {
// hide quick add
getView().findViewById(R.id.taskListFooter).setVisibility(View.GONE);
Resources r = getActivity().getResources();
int color = r.getColor(ThemeService.getThemeColor());
View snooze = getView().findViewById(R.id.reminder_snooze);
snooze.setBackgroundColor(color);
snooze.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
getActivity().finish();
}
});
TextView reminder = (TextView) getView().findViewById(R.id.reminder_message);
reminder.setText(Notifications.getRandomReminder(r.getStringArray(R.array.rmd_reengage_dialog_options)));
super.initializeData();
}
@Override
protected View getListBody(ViewGroup root) {
ViewGroup parent = (ViewGroup) getActivity().getLayoutInflater().inflate(R.layout.task_list_body_reengagement, root, false);
View taskListView = super.getListBody(parent);
parent.addView(taskListView, 0);
return parent;
}
}

@ -1,14 +1,28 @@
package com.todoroo.astrid.reminders;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.NotificationManager;
import com.todoroo.andlib.service.NotificationManager.AndroidNotificationManager;
import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.andlib.utility.Preferences;
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.TaskApiDao.TaskCriteria;
import com.todoroo.astrid.utility.Constants;
public class ReengagementReceiver extends BroadcastReceiver {
private static final int TASK_LIMIT = 3;
@Override
public void onReceive(Context context, Intent intent) {
@ -16,9 +30,47 @@ public class ReengagementReceiver extends BroadcastReceiver {
int reengagementReminders = Preferences.getInt(ReengagementService.PREF_REENGAGEMENT_COUNT, 1);
Preferences.setInt(ReengagementService.PREF_REENGAGEMENT_COUNT, reengagementReminders + 1);
Intent reengagement = new Intent(context, ReengagementActivity.class);
reengagement.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
context.startActivity(reengagement);
Intent notifIntent = new Intent(context, TaskListActivity.class);
QueryTemplate template = new QueryTemplate().where(TaskCriteria.activeVisibleMine());
String sql = SortHelper.adjustQueryForFlagsAndSort(template.toString(), 0, SortHelper.SORT_AUTO) + " LIMIT " + TASK_LIMIT; //$NON-NLS-1$
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);
notifIntent.setAction("NOTIFY_reengagement"); //$NON-NLS-1$
notifIntent.putExtra(TaskListFragment.TOKEN_FILTER, filter);
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());
PendingIntent pendingIntent = PendingIntent.getActivity(context,
0, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context,
"", //$NON-NLS-1$
text,
pendingIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
if(Preferences.getBoolean(R.string.p_rmd_persistent, true)) {
notification.flags |= Notification.FLAG_NO_CLEAR |
Notification.FLAG_SHOW_LIGHTS;
notification.ledOffMS = 5000;
notification.ledOnMS = 700;
notification.ledARGB = Color.YELLOW;
} else {
notification.defaults = Notification.DEFAULT_LIGHTS;
}
manager.notify(0, notification);
ReengagementService.scheduleReengagementAlarm(context);
}

@ -31,9 +31,9 @@ public final class ReengagementService {
int reengagementReminders = Preferences.getInt(PREF_REENGAGEMENT_COUNT, 1);
int days;
if (reengagementReminders >= 4)
days = 12;
days = 8;
else
days = 3 * reengagementReminders;
days = 2 * reengagementReminders;
return DateUtilities.now() + DateUtilities.ONE_DAY * days;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 760 B

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 760 B

After

Width:  |  Height:  |  Size: 2.3 KiB

@ -1,71 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/reminder_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:orientation="vertical"
android:background="@drawable/reminder_dialog_background">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dip"
android:layout_marginRight="5dip"
android:layout_marginBottom="15dip"
android:layout_marginLeft="10dip">
<TextView
android:id="@+id/reminder_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dip"
android:textSize="24sp"
android:textColor="@android:color/white"
android:layout_weight="1"
android:text="@string/MCA_title"/>
<ImageView
android:id="@+id/dismiss"
android:layout_width="25dip"
android:layout_height="25dip"
android:scaleType="fitCenter"
android:src="@drawable/close_clear_cancel"/>
</LinearLayout>
<TextView
android:id="@+id/see_tasks_button"
android:layout_width="fill_parent"
android:layout_height="35dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginBottom="10dip"
android:textColor="@android:color/white"
android:textSize="24sp"
android:gravity="center"
android:text="@string/rmd_reengage_see_tasks"/>
<TextView
android:id="@+id/dismiss_button"
android:layout_width="fill_parent"
android:layout_height="35dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginBottom="10dip"
android:textColor="@android:color/white"
android:textSize="24sp"
android:gravity="center"
android:text="@string/DLG_dismiss"
android:background="#707070"/>
<FrameLayout
android:id="@+id/missed_calls_speech_bubble"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<include layout="@layout/astrid_speech_bubble" />
</FrameLayout>
</LinearLayout>

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<include layout="@layout/astrid_reengagement_view"/>
</LinearLayout>

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="100">
<!-- List body goes here -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/speech_bubble_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="2dip"
android:layout_marginRight="5dip"
android:layout_marginBottom="10dip"
android:gravity="bottom">
<ImageView
android:id="@+id/astridIcon"
android:layout_width="75dip"
android:layout_height="75dip"
android:layout_marginBottom="5dip"
android:src="@drawable/icon"
android:scaleType="fitCenter"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"/>
<LinearLayout
android:id="@+id/speech_bubble_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:layout_marginBottom="5dip"
android:minHeight="60dip"
android:layout_alignParentBottom="true"
android:gravity="center_vertical"
android:background="@drawable/speech_bubble_reminder"
android:layout_toRightOf="@id/astridIcon">
<TextView
android:id="@+id/reminder_message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@style/TextAppearance.TLA_Reminder"
android:gravity="center_vertical"/>
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/reminder_snooze"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginBottom="10dip"
android:textColor="@android:color/white"
android:textSize="24sp"
android:text="@string/rmd_NoA_snooze"
android:background="#707070"/>
</LinearLayout>
</LinearLayout>

@ -62,10 +62,12 @@
<!-- ==================================================== user reengagement == -->
<string name="rmd_reengage_see_tasks">See my tasks</string>
<string name="rmd_reengage_notif">Here are some tasks you might have missed!</string>
<string name="rmd_reengage_snooze">Snooze all</string>
<string-array name="rmd_reengage_dialog_options">
<item>Some stuff!</item>
<item>Time to shorten your to-do list!</item>
</string-array>
<!-- ============================================= reminder preferences == -->

@ -668,6 +668,8 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
case Constants.SOURCE_C2DM:
StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_C2DM);
break;
case Constants.SOURCE_REENGAGEMENT:
StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_REENGAGEMENT);
}
getIntent().putExtra(TOKEN_SOURCE, Constants.SOURCE_DEFAULT); // Only report source once
}

@ -40,6 +40,7 @@ import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.gtasks.sync.GtasksSyncService;
import com.todoroo.astrid.opencrx.OpencrxCoreUtils;
import com.todoroo.astrid.producteev.ProducteevUtilities;
import com.todoroo.astrid.reminders.ReengagementService;
import com.todoroo.astrid.reminders.ReminderStartupReceiver;
import com.todoroo.astrid.service.abtesting.ABChooser;
import com.todoroo.astrid.service.abtesting.ABTestInvoker;
@ -105,6 +106,7 @@ public class StartupService {
if(hasStartedUp || context == null)
return;
// sets up context manager
ContextManager.setContext(context);
@ -193,6 +195,7 @@ public class StartupService {
am.setInexactRepeating(AlarmManager.RTC, 0,
Constants.WIDGET_UPDATE_INTERVAL, pendingIntent);
ReengagementService.scheduleReengagementAlarm(context);
taskService.cleanup();
// if sync ongoing flag was set, clear it

@ -24,6 +24,7 @@ public class StatisticsConstants {
public static final String LAUNCH_FROM_PPW = "launch-from-ppw";
public static final String LAUNCH_FROM_WIDGET = "launch-from-widget";
public static final String LAUNCH_FROM_C2DM = "launch-from-c2dm";
public static final String LAUNCH_FROM_REENGAGEMENT = "launch-from-reengagement";
public static final String LOCALE_EDIT_ALERTS_NO_PLUGIN = "locale-edit-alerts-no-plugin";
public static final String LOCALE_EDIT_ALERTS = "locale-edit-alerts";
public static final String WIDGET_CONFIG = "widget-config";

@ -51,6 +51,7 @@ public final class Constants {
public static final int SOURCE_WIDGET = 2;
public static final int SOURCE_PPWIDGET = 3;
public static final int SOURCE_C2DM = 4;
public static final int SOURCE_REENGAGEMENT = 5;
// --- notification id's

Loading…
Cancel
Save