mirror of https://github.com/tasks/tasks
parent
b06aa552d4
commit
94d2189f85
@ -1,74 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
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.todoroo.astrid.activity.TaskListFragment;
|
||||
import com.todoroo.astrid.service.ThemeService;
|
||||
|
||||
import org.tasks.R;
|
||||
|
||||
public class ReengagementFragment extends TaskListFragment {
|
||||
|
||||
public static final String EXTRA_TEXT = "dialogText"; //$NON-NLS-1$
|
||||
|
||||
@Override
|
||||
protected void initializeData() {
|
||||
// hide quick add
|
||||
getView().findViewById(R.id.taskListFooter).setVisibility(View.GONE);
|
||||
|
||||
super.initializeData();
|
||||
|
||||
setupSpeechBubble();
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refresh() {
|
||||
super.refresh();
|
||||
setupSpeechBubble();
|
||||
}
|
||||
|
||||
private void setupSpeechBubble() {
|
||||
Resources r = getActivity().getResources();
|
||||
TextView snooze = (TextView) getView().findViewById(R.id.reminder_snooze);
|
||||
snooze.setBackgroundColor(r.getColor(ThemeService.getThemeColor()));
|
||||
TextView reminder = (TextView) getView().findViewById(R.id.reminder_message);
|
||||
if (taskAdapter.getCount() == 0) {
|
||||
snooze.setText(R.string.rmd_reengage_add_tasks);
|
||||
snooze.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
quickAddBar.performButtonClick();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
snooze.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getActivity().finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
reminder.setText(extras.getString(EXTRA_TEXT));
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,119 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
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 android.os.Bundle;
|
||||
|
||||
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.activity.TaskListActivity;
|
||||
import com.todoroo.astrid.activity.TaskListFragment;
|
||||
import com.todoroo.astrid.api.FilterWithCustomIntent;
|
||||
import com.todoroo.astrid.core.SortHelper;
|
||||
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import com.todoroo.astrid.service.TaskService;
|
||||
import com.todoroo.astrid.utility.Constants;
|
||||
import com.todoroo.astrid.utility.Flags;
|
||||
|
||||
import org.tasks.R;
|
||||
|
||||
public class ReengagementReceiver extends BroadcastReceiver {
|
||||
|
||||
@Autowired TaskService taskService;
|
||||
|
||||
private static final int TASK_LIMIT = 3;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (!Preferences.getBoolean(R.string.p_rmd_enabled, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
DependencyInjectionService.getInstance().inject(this);
|
||||
|
||||
int reengagementReminders = Preferences.getInt(ReengagementService.PREF_REENGAGEMENT_COUNT, 1);
|
||||
Preferences.setInt(ReengagementService.PREF_REENGAGEMENT_COUNT, reengagementReminders + 1);
|
||||
|
||||
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$
|
||||
|
||||
boolean hasTasks = false;
|
||||
TodorooCursor<Task> 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$
|
||||
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);
|
||||
|
||||
|
||||
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,
|
||||
title,
|
||||
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);
|
||||
Flags.set(Flags.REFRESH); // Forces a reload when app launches
|
||||
|
||||
ReengagementService.scheduleReengagementAlarm(context);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.reminders;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.todoroo.andlib.utility.DateUtilities;
|
||||
import com.todoroo.andlib.utility.Preferences;
|
||||
import com.todoroo.astrid.utility.AstridPreferences;
|
||||
import com.todoroo.astrid.utility.Constants;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public final class ReengagementService {
|
||||
|
||||
private static final int REQUEST_CODE = 10;
|
||||
|
||||
|
||||
public static final String PREF_REENGAGEMENT_COUNT = "pref_reengagement_count"; //$NON-NLS-1$
|
||||
|
||||
public static final String BROADCAST_SHOW_REENGAGEMENT = Constants.PACKAGE + ".SHOW_REENGAGEMENT"; //$NON-NLS-1$
|
||||
|
||||
public static void scheduleReengagementAlarm(Context context) {
|
||||
AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
|
||||
Intent intent = new Intent(BROADCAST_SHOW_REENGAGEMENT);
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, intent, 0);
|
||||
am.cancel(pendingIntent);
|
||||
|
||||
long time = getNextReminderTime();
|
||||
am.set(AlarmManager.RTC_WAKEUP, time, pendingIntent);
|
||||
}
|
||||
|
||||
private static long getNextReminderTime() {
|
||||
int reengagementReminders = Preferences.getInt(PREF_REENGAGEMENT_COUNT, 1);
|
||||
int days;
|
||||
if (DateUtilities.now() - Preferences.getLong(AstridPreferences.P_FIRST_LAUNCH, 0) > DateUtilities.ONE_DAY * 30) { // Installed longer than 30 days
|
||||
// Sequence: every 6, 8, 10 days
|
||||
days = Math.min(10, 4 + 2 * reengagementReminders);
|
||||
} else {
|
||||
// Sequence: every 2, 3, 4, 5 days
|
||||
days = Math.min(5, 1 + reengagementReminders);
|
||||
}
|
||||
|
||||
Date date = new Date(DateUtilities.now() + DateUtilities.ONE_DAY * days / 1000L * 1000L);
|
||||
date.setHours(18);
|
||||
date.setMinutes(0);
|
||||
date.setSeconds(0);
|
||||
|
||||
return date.getTime();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,76 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
** Copyright (c) 2012 Todoroo Inc
|
||||
**
|
||||
** See the file "LICENSE" for the full license governing this code.
|
||||
-->
|
||||
<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>
|
||||
Loading…
Reference in New Issue