Use InboxStyle notification for tasker

pull/574/head
Alex Baker 7 years ago
parent 1a98cc36c2
commit efb20b7548

@ -1,6 +1,5 @@
package org.tasks;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@ -30,6 +29,7 @@ import org.tasks.reminders.NotificationActivity;
import org.tasks.reminders.SnoozeActivity;
import org.tasks.reminders.SnoozeDialog;
import org.tasks.reminders.SnoozeOption;
import org.tasks.ui.CheckBoxes;
import java.util.Collections;
import java.util.LinkedHashMap;
@ -57,12 +57,13 @@ public class Notifier {
private final VoiceOutputAssistant voiceOutputAssistant;
private final Preferences preferences;
private final NotificationDao notificationDao;
private final CheckBoxes checkBoxes;
@Inject
public Notifier(@ForApplication Context context, TaskDao taskDao,
NotificationManager notificationManager, TelephonyManager telephonyManager,
AudioManager audioManager, VoiceOutputAssistant voiceOutputAssistant,
Preferences preferences, NotificationDao notificationDao) {
Preferences preferences, NotificationDao notificationDao, CheckBoxes checkBoxes) {
this.context = context;
this.taskDao = taskDao;
this.notificationManager = notificationManager;
@ -71,37 +72,48 @@ public class Notifier {
this.voiceOutputAssistant = voiceOutputAssistant;
this.preferences = preferences;
this.notificationDao = notificationDao;
this.checkBoxes = checkBoxes;
}
public void triggerFilterNotification(final Filter filter) {
String title = filter.listingTitle;
String query = filter.getSqlQuery();
int count = taskDao.count(filter);
List<Task> tasks = taskDao.query(filter);
int count = tasks.size();
if (count == 0) {
return;
}
String subtitle = context.getString(R.string.task_count, count);
Intent intent = new Intent(context, TaskListActivity.class);
intent.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_MULTIPLE_TASK);
intent.putExtra(TaskListActivity.OPEN_FILTER, filter);
PendingIntent pendingIntent = PendingIntent.getActivity(context, (title + query).hashCode(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pendingIntent = PendingIntent.getActivity(context, filter.listingTitle.hashCode(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
String summaryTitle = context.getString(R.string.task_count, count);
NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle()
.setBigContentTitle(summaryTitle);
int maxPriority = 3;
for (Task task : tasks) {
style.addLine(task.getTitle());
maxPriority = Math.min(maxPriority, task.getImportance());
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NotificationManager.NOTIFICATION_CHANNEL_TASKER)
.setSmallIcon(R.drawable.ic_check_white_24dp)
.setSmallIcon(R.drawable.ic_done_all_white_24dp)
.setCategory(NotificationCompat.CATEGORY_REMINDER)
.setTicker(title)
.setContentTitle(title)
.setContentText(subtitle)
.setTicker(summaryTitle)
.setContentTitle(summaryTitle)
.setContentText(filter.listingTitle)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setWhen(currentTimeMillis())
.setShowWhen(true);
.setShowWhen(true)
.setColor(checkBoxes.getPriorityColor(maxPriority))
.setGroupSummary(true)
.setGroup(filter.listingTitle)
.setStyle(style);
notificationManager.notify(
(title + query).hashCode(),
filter.listingTitle.hashCode(),
builder,
true,
false,

@ -8,8 +8,6 @@ import org.tasks.analytics.Tracker;
import org.tasks.db.AppDatabase;
import org.tasks.locale.Locale;
import org.tasks.notifications.NotificationDao;
import org.tasks.ui.CheckBoxes;
import org.tasks.ui.WidgetCheckBoxes;
import java.util.concurrent.Executor;
@ -18,9 +16,6 @@ import javax.inject.Named;
import dagger.Module;
import dagger.Provides;
import static org.tasks.ui.CheckBoxes.newCheckBoxes;
import static org.tasks.ui.WidgetCheckBoxes.newWidgetCheckBoxes;
@Module
public class ApplicationModule {
private final Context context;
@ -47,18 +42,6 @@ public class ApplicationModule {
return new ErrorReportingSingleThreadExecutor("iab-executor", tracker);
}
@Provides
@ApplicationScope
public CheckBoxes getCheckBoxes() {
return newCheckBoxes(context);
}
@Provides
@ApplicationScope
public WidgetCheckBoxes getWidgetCheckBoxes(CheckBoxes checkBoxes) {
return newWidgetCheckBoxes(checkBoxes);
}
@Provides
@ApplicationScope
public AppDatabase getAppDatabase() {

@ -107,7 +107,7 @@ public class NotificationManager {
long taskId = entry.getKey().taskId;
Task task = taskDao.fetch(taskId);
NotificationCompat.Builder builder = entry.getValue();
builder.setColor(getPriorityColor(task.getImportance()));
builder.setColor(checkBoxes.getPriorityColor(task.getImportance()));
if (i < last) {
notify(taskId, builder, false, false, false);
} else {
@ -182,7 +182,7 @@ public class NotificationManager {
.setWhen(when)
.setSmallIcon(R.drawable.ic_done_all_white_24dp)
.setStyle(style)
.setColor(getPriorityColor(maxPriority))
.setColor(checkBoxes.getPriorityColor(maxPriority))
.setNumber(taskCount)
.setContentIntent(PendingIntent.getActivity(context, 0, TaskIntents.getTaskListIntent(context, filter), PendingIntent.FLAG_UPDATE_CURRENT));
if (notify) {
@ -201,8 +201,4 @@ public class NotificationManager {
}
}
private int getPriorityColor(int priority) {
priority = Math.max(0, Math.min(3, priority));
return checkBoxes.getPriorityColors().get(priority);
}
}

@ -9,17 +9,18 @@ import com.google.common.collect.ImmutableList;
import com.google.common.primitives.Ints;
import org.tasks.R;
import org.tasks.injection.ApplicationScope;
import org.tasks.injection.ForApplication;
import java.util.List;
import javax.inject.Inject;
import static android.support.v4.content.ContextCompat.getColor;
@ApplicationScope
public class CheckBoxes {
public static CheckBoxes newCheckBoxes(Context context) {
return new CheckBoxes(context);
}
private static final int MAX_IMPORTANCE_INDEX = 3;
private final List<Drawable> checkboxes;
@ -28,7 +29,8 @@ public class CheckBoxes {
private final List<Integer> priorityColors;
private final int[] priorityColorsArray;
private CheckBoxes(Context context) {
@Inject
public CheckBoxes(@ForApplication Context context) {
checkboxes = wrapDrawable(context, R.drawable.ic_check_box_outline_blank_24dp);
repeatingCheckboxes = wrapDrawable(context, R.drawable.ic_repeat_24dp);
completedCheckboxes = wrapDrawable(context, R.drawable.ic_check_box_24dp);
@ -40,6 +42,10 @@ public class CheckBoxes {
priorityColorsArray = Ints.toArray(priorityColors);
}
public int getPriorityColor(int priority) {
return priorityColors.get(Math.max(0, Math.min(3, priority)));
}
public List<Integer> getPriorityColors() {
return priorityColors;
}

@ -5,24 +5,26 @@ import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import org.tasks.injection.ApplicationScope;
import java.util.List;
import javax.inject.Inject;
import timber.log.Timber;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.transform;
@ApplicationScope
public class WidgetCheckBoxes {
public static WidgetCheckBoxes newWidgetCheckBoxes(CheckBoxes checkBoxes) {
return new WidgetCheckBoxes(checkBoxes);
}
private final List<Bitmap> checkboxes;
private final List<Bitmap> repeatingCheckboxes;
private final List<Bitmap> completedCheckboxes;
private WidgetCheckBoxes(CheckBoxes checkBoxes) {
@Inject
public WidgetCheckBoxes(CheckBoxes checkBoxes) {
Timber.d("Initializing widget checkboxes");
checkboxes = convertToBitmap(checkBoxes.getCheckBoxes());
repeatingCheckboxes = convertToBitmap(checkBoxes.getRepeatingCheckBoxes());

Loading…
Cancel
Save