Remove checkbox caching

pull/820/head
Alex Baker 5 years ago
parent fb59324a50
commit 21f1275ca4

@ -10,6 +10,7 @@ import static android.app.Activity.RESULT_OK;
import static androidx.core.content.ContextCompat.getColor;
import static com.todoroo.andlib.utility.AndroidUtilities.assertMainThread;
import static org.tasks.caldav.CaldavCalendarSettingsActivity.EXTRA_CALDAV_CALENDAR;
import static org.tasks.ui.CheckBoxes.getPriorityColor;
import android.app.Activity;
import android.content.BroadcastReceiver;
@ -90,7 +91,6 @@ import org.tasks.tasklist.ManualSortRecyclerAdapter;
import org.tasks.tasklist.PagedListRecyclerAdapter;
import org.tasks.tasklist.TaskListRecyclerAdapter;
import org.tasks.tasklist.ViewHolderFactory;
import org.tasks.ui.CheckBoxes;
import org.tasks.ui.MenuColorizer;
import org.tasks.ui.TaskListViewModel;
import org.tasks.ui.Toaster;
@ -126,7 +126,6 @@ public final class TaskListFragment extends InjectingFragment
@Inject @ForActivity Context context;
@Inject Preferences preferences;
@Inject DialogBuilder dialogBuilder;
@Inject CheckBoxes checkBoxes;
@Inject TaskCreator taskCreator;
@Inject TimerPlugin timerPlugin;
@Inject ViewHolderFactory viewHolderFactory;
@ -454,7 +453,11 @@ public final class TaskListFragment extends InjectingFragment
private void setupRefresh(SwipeRefreshLayout layout) {
layout.setOnRefreshListener(this);
layout.setColorSchemeColors(checkBoxes.getPriorityColors());
layout.setColorSchemeColors(
getPriorityColor(context, 0),
getPriorityColor(context, 1),
getPriorityColor(context, 2),
getPriorityColor(context, 3));
}
@Override

@ -81,7 +81,6 @@ public class Astrid2TaskProvider extends InjectingContentProvider {
}
@Inject Lazy<TagService> tagService;
@Inject Lazy<CheckBoxes> checkBoxes;
@Inject Lazy<TaskDao> taskDao;
@Inject Lazy<TagDao> tagDao;
@ -177,7 +176,7 @@ public class Astrid2TaskProvider extends InjectingContentProvider {
Object[] values = new Object[7];
values[0] = task.getTitle();
values[1] = checkBoxes.get().getPriorityColor(task.getPriority());
values[1] = CheckBoxes.getPriorityColor(getContext(), task.getPriority());
values[2] = task.getDueDate();
values[3] = task.getDueDate();
values[4] = task.getPriority();

@ -26,6 +26,7 @@ import com.todoroo.astrid.data.Task;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.dialogs.Linkify;
import org.tasks.injection.ForApplication;
import org.tasks.injection.FragmentComponent;
import org.tasks.ui.CheckBoxes;
import org.tasks.ui.TaskEditControlFragment;
@ -44,8 +45,8 @@ public class EditTitleControlSet extends TaskEditControlFragment {
private static final String EXTRA_REPEATING = "extra_repeating";
private static final String EXTRA_PRIORITY = "extra_priority";
@Inject @ForApplication Context context;
@Inject TaskDao taskDao;
@Inject CheckBoxes checkBoxes;
@Inject Linkify linkify;
@BindView(R.id.title)
@ -140,13 +141,8 @@ public class EditTitleControlSet extends TaskEditControlFragment {
private void updateCompleteBox() {
isComplete = completeBox.isChecked();
if (isComplete) {
completeBox.setImageDrawable(checkBoxes.getCompletedCheckbox(importanceValue));
} else if (isRepeating) {
completeBox.setImageDrawable(checkBoxes.getRepeatingCheckBox(importanceValue));
} else {
completeBox.setImageDrawable(checkBoxes.getCheckBox(importanceValue));
}
completeBox.setImageDrawable(
CheckBoxes.getCheckBox(context, isComplete, isRepeating, importanceValue));
if (isComplete) {
editText.setPaintFlags(editText.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

@ -39,7 +39,6 @@ public class Notifier {
private final AudioManager audioManager;
private final VoiceOutputAssistant voiceOutputAssistant;
private final Preferences preferences;
private final CheckBoxes checkBoxes;
@Inject
public Notifier(
@ -49,8 +48,7 @@ public class Notifier {
TelephonyManager telephonyManager,
AudioManager audioManager,
VoiceOutputAssistant voiceOutputAssistant,
Preferences preferences,
CheckBoxes checkBoxes) {
Preferences preferences) {
this.context = context;
this.taskDao = taskDao;
this.notificationManager = notificationManager;
@ -58,7 +56,6 @@ public class Notifier {
this.audioManager = audioManager;
this.voiceOutputAssistant = voiceOutputAssistant;
this.preferences = preferences;
this.checkBoxes = checkBoxes;
}
public void triggerFilterNotification(final Filter filter) {
@ -96,7 +93,7 @@ public class Notifier {
.setAutoCancel(true)
.setWhen(currentTimeMillis())
.setShowWhen(true)
.setColor(checkBoxes.getPriorityColor(maxPriority))
.setColor(CheckBoxes.getPriorityColor(context, maxPriority))
.setGroupSummary(true)
.setGroup(filter.listingTitle)
.setStyle(style);

@ -71,7 +71,6 @@ public class NotificationManager {
private final TaskDao taskDao;
private final Context context;
private final Preferences preferences;
private final CheckBoxes checkBoxes;
private final Throttle throttle = new Throttle(NOTIFICATIONS_PER_SECOND);
private final NotificationLimiter queue = new NotificationLimiter(MAX_NOTIFICATIONS);
@ -81,13 +80,11 @@ public class NotificationManager {
Preferences preferences,
NotificationDao notificationDao,
TaskDao taskDao,
CheckBoxes checkBoxes,
LocationDao locationDao) {
this.context = context;
this.preferences = preferences;
this.notificationDao = notificationDao;
this.taskDao = taskDao;
this.checkBoxes = checkBoxes;
this.locationDao = locationDao;
notificationManagerCompat = NotificationManagerCompat.from(context);
}
@ -273,7 +270,7 @@ public class NotificationManager {
.setWhen(when)
.setSmallIcon(R.drawable.ic_done_all_white_24dp)
.setStyle(style)
.setColor(checkBoxes.getPriorityColor(maxPriority))
.setColor(CheckBoxes.getPriorityColor(context, maxPriority))
.setOnlyAlertOnce(false)
.setContentIntent(
PendingIntent.getActivity(
@ -352,7 +349,7 @@ public class NotificationManager {
new NotificationCompat.Builder(context, NotificationManager.NOTIFICATION_CHANNEL_DEFAULT)
.setCategory(NotificationCompat.CATEGORY_REMINDER)
.setContentTitle(taskTitle)
.setColor(checkBoxes.getPriorityColor(task.getPriority()))
.setColor(CheckBoxes.getPriorityColor(context, task.getPriority()))
.setSmallIcon(R.drawable.ic_check_white_24dp)
.setWhen(when)
.setOnlyAlertOnce(false)

@ -9,7 +9,6 @@ import static com.todoroo.andlib.utility.DateUtilities.getAbbreviatedRelativeDat
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Paint;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
@ -40,7 +39,6 @@ public class ViewHolder extends RecyclerView.ViewHolder {
private final Activity context;
private final Preferences preferences;
private final CheckBoxes checkBoxes;
private final int textColorSecondary;
private final int textColorPrimary;
private final TaskDao taskDao;
@ -92,7 +90,6 @@ public class ViewHolder extends RecyclerView.ViewHolder {
ViewGroup view,
Preferences preferences,
int fontSize,
CheckBoxes checkBoxes,
ChipProvider chipProvider,
int textColorOverdue,
int textColorSecondary,
@ -107,7 +104,6 @@ public class ViewHolder extends RecyclerView.ViewHolder {
super(view);
this.context = context;
this.preferences = preferences;
this.checkBoxes = checkBoxes;
this.chipProvider = chipProvider;
this.textColorOverdue = textColorOverdue;
this.textColorSecondary = textColorSecondary;
@ -247,16 +243,8 @@ public class ViewHolder extends RecyclerView.ViewHolder {
private void setupCompleteBox() {
// complete box
final CheckableImageView checkBoxView = completeBox;
boolean completed = task.isCompleted();
checkBoxView.setChecked(completed);
if (completed) {
checkBoxView.setImageDrawable(checkBoxes.getCompletedCheckbox(task.getPriority()));
} else if (TextUtils.isEmpty(task.getRecurrence())) {
checkBoxView.setImageDrawable(checkBoxes.getCheckBox(task.getPriority()));
} else {
checkBoxView.setImageDrawable(checkBoxes.getRepeatingCheckBox(task.getPriority()));
}
checkBoxView.setChecked(task.isCompleted());
checkBoxView.setImageDrawable(CheckBoxes.getCheckBox(context, task.getTask()));
checkBoxView.invalidate();
}

@ -17,7 +17,6 @@ import org.tasks.dialogs.Linkify;
import org.tasks.injection.ForActivity;
import org.tasks.locale.Locale;
import org.tasks.preferences.Preferences;
import org.tasks.ui.CheckBoxes;
import org.tasks.ui.ChipProvider;
public class ViewHolderFactory {
@ -27,7 +26,6 @@ public class ViewHolderFactory {
private final int textColorOverdue;
private final Context context;
private final Locale locale;
private final CheckBoxes checkBoxes;
private final ChipProvider chipProvider;
private final int fontSize;
private final TaskDao taskDao;
@ -43,13 +41,11 @@ public class ViewHolderFactory {
@ForActivity Context context,
Locale locale,
Preferences preferences,
CheckBoxes checkBoxes,
ChipProvider chipProvider,
TaskDao taskDao,
Linkify linkify) {
this.context = context;
this.locale = locale;
this.checkBoxes = checkBoxes;
this.chipProvider = chipProvider;
this.taskDao = taskDao;
this.preferences = preferences;
@ -72,7 +68,6 @@ public class ViewHolderFactory {
LayoutInflater.from(context).inflate(R.layout.task_adapter_row_simple, parent, false),
preferences,
fontSize,
checkBoxes,
chipProvider,
textColorOverdue,
textColorSecondary,

@ -3,38 +3,18 @@ package org.tasks.ui;
import static androidx.core.content.ContextCompat.getColor;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import androidx.annotation.DrawableRes;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import javax.inject.Inject;
import com.todoroo.astrid.data.Task;
import org.tasks.R;
import org.tasks.injection.ApplicationScope;
import org.tasks.injection.ForApplication;
@ApplicationScope
public class CheckBoxes {
private static final int MIN_PRIORITY = 0;
private static final int MAX_PRIORITY = 3;
private final Drawable[] checkboxes = new Drawable[4];
private final Drawable[] repeatingCheckboxes = new Drawable[4];
private final Drawable[] completedCheckboxes = new Drawable[4];
private final Context context;
private final int[] priorityColors;
@Inject
public CheckBoxes(@ForApplication Context context) {
this.context = context;
priorityColors =
new int[] {
getColor(context, R.color.priority_1),
getColor(context, R.color.priority_2),
getColor(context, R.color.priority_3),
getColor(context, R.color.priority_4)
};
}
private CheckBoxes() {}
private static Drawable getDrawable(Context context, @DrawableRes int resId, int priority) {
Drawable original = ContextCompat.getDrawable(context, resId);
@ -44,50 +24,46 @@ public class CheckBoxes {
}
private static int getPriorityResId(int priority) {
switch (priority) {
case 0:
return R.color.priority_1;
case 1:
return R.color.priority_2;
case 2:
return R.color.priority_3;
default:
return R.color.priority_4;
if (priority <= 0) {
return R.color.priority_1;
} else if (priority == 1) {
return R.color.priority_2;
} else if (priority == 2) {
return R.color.priority_3;
} else {
return R.color.priority_4;
}
}
public int getPriorityColor(int priority) {
return priorityColors[Math.max(MIN_PRIORITY, Math.min(MAX_PRIORITY, priority))];
private static Bitmap convertToBitmap(Drawable d) {
Bitmap bitmap =
Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
d.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
d.draw(canvas);
return bitmap;
}
public int[] getPriorityColors() {
return priorityColors;
public static Bitmap getCheckBoxBitmap(Context context, Task task) {
return convertToBitmap(getCheckBox(context, task));
}
public Drawable getCompletedCheckbox(int priority) {
priority = Math.min(priority, MAX_PRIORITY);
if (completedCheckboxes[priority] == null) {
completedCheckboxes[priority] =
getDrawable(context, R.drawable.ic_outline_check_box_24px, priority);
}
return completedCheckboxes[priority];
public static Drawable getCheckBox(Context context, Task task) {
return getCheckBox(context, task.isCompleted(), task.isRecurring(), task.getPriority());
}
public Drawable getRepeatingCheckBox(int priority) {
priority = Math.min(priority, MAX_PRIORITY);
if (repeatingCheckboxes[priority] == null) {
repeatingCheckboxes[priority] =
getDrawable(context, R.drawable.ic_outline_repeat_24px, priority);
public static Drawable getCheckBox(
Context context, boolean complete, boolean repeating, int priority) {
if (complete) {
return getDrawable(context, R.drawable.ic_outline_check_box_24px, priority);
} else if (repeating) {
return getDrawable(context, R.drawable.ic_outline_repeat_24px, priority);
} else {
return getDrawable(context, R.drawable.ic_outline_check_box_outline_blank_24px, priority);
}
return repeatingCheckboxes[priority];
}
public Drawable getCheckBox(int priority) {
priority = Math.min(priority, MAX_PRIORITY);
if (checkboxes[priority] == null) {
checkboxes[priority] =
getDrawable(context, R.drawable.ic_outline_check_box_outline_blank_24px, priority);
}
return checkboxes[priority];
public static int getPriorityColor(Context context, int priority) {
return getColor(context, getPriorityResId(priority));
}
}

@ -3,6 +3,7 @@ package org.tasks.ui;
import static com.todoroo.andlib.utility.AndroidUtilities.preLollipop;
import android.app.Activity;
import android.content.Context;
import android.content.res.ColorStateList;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -18,13 +19,15 @@ import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Task.Priority;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.injection.ForApplication;
import org.tasks.injection.FragmentComponent;
public class PriorityControlSet extends TaskEditControlFragment {
public static final int TAG = R.string.TEA_ctrl_importance_pref;
private static final String EXTRA_PRIORITY = "extra_priority";
@Inject CheckBoxes checkBoxes;
@Inject @ForApplication Context context;
@BindView(R.id.priority_high)
AppCompatRadioButton priorityHigh;
@ -120,7 +123,7 @@ public class PriorityControlSet extends TaskEditControlFragment {
}
private void tintRadioButton(AppCompatRadioButton radioButton, int priority) {
int color = checkBoxes.getPriorityColor(priority);
int color = CheckBoxes.getPriorityColor(context, priority);
CompoundButtonCompat.setButtonTintList(
radioButton,
new ColorStateList(

@ -1,51 +0,0 @@
package org.tasks.ui;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import javax.inject.Inject;
import org.tasks.injection.ApplicationScope;
@ApplicationScope
public class WidgetCheckBoxes {
private final CheckBoxes checkBoxes;
private final Bitmap[] incomplete = new Bitmap[4];
private final Bitmap[] repeating = new Bitmap[4];
private final Bitmap[] completed = new Bitmap[4];
@Inject
public WidgetCheckBoxes(CheckBoxes checkBoxes) {
this.checkBoxes = checkBoxes;
}
private static Bitmap convertToBitmap(Drawable d) {
Bitmap bitmap =
Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
d.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
d.draw(canvas);
return bitmap;
}
public Bitmap getCompletedCheckbox(int importance) {
if (completed[importance] == null) {
completed[importance] = convertToBitmap(checkBoxes.getCompletedCheckbox(importance));
}
return completed[importance];
}
public Bitmap getRepeatingCheckBox(int importance) {
if (repeating[importance] == null) {
repeating[importance] = convertToBitmap(checkBoxes.getRepeatingCheckBox(importance));
}
return repeating[importance];
}
public Bitmap getCheckBox(int importance) {
if (incomplete[importance] == null) {
incomplete[importance] = convertToBitmap(checkBoxes.getCheckBox(importance));
}
return incomplete[importance];
}
}

@ -9,7 +9,6 @@ import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.text.TextUtils;
import android.view.View;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;
@ -30,12 +29,11 @@ import org.tasks.preferences.DefaultFilterProvider;
import org.tasks.preferences.Preferences;
import org.tasks.themes.ThemeCache;
import org.tasks.themes.WidgetTheme;
import org.tasks.ui.WidgetCheckBoxes;
import org.tasks.ui.CheckBoxes;
import timber.log.Timber;
class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFactory {
private final WidgetCheckBoxes checkBoxes;
private final ThemeCache themeCache;
private final int widgetId;
private final TaskDao taskDao;
@ -62,7 +60,6 @@ class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFactory {
int widgetId,
TaskDao taskDao,
DefaultFilterProvider defaultFilterProvider,
WidgetCheckBoxes checkBoxes,
ThemeCache themeCache) {
this.subtasksHelper = subtasksHelper;
this.preferences = preferences;
@ -70,7 +67,6 @@ class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFactory {
this.widgetId = widgetId;
this.taskDao = taskDao;
this.defaultFilterProvider = defaultFilterProvider;
this.checkBoxes = checkBoxes;
this.themeCache = themeCache;
widgetPreferences = new WidgetPreferences(context, preferences, widgetId);
@ -79,9 +75,7 @@ class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFactory {
}
@Override
public void onCreate() {
}
public void onCreate() {}
@Override
public void onDataSetChanged() {
@ -130,13 +124,7 @@ class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFactory {
}
private Bitmap getCheckbox(Task task) {
if (task.isCompleted()) {
return checkBoxes.getCompletedCheckbox(task.getPriority());
} else if (TextUtils.isEmpty(task.getRecurrence())) {
return checkBoxes.getCheckBox(task.getPriority());
} else {
return checkBoxes.getRepeatingCheckBox(task.getPriority());
}
return CheckBoxes.getCheckBoxBitmap(context, task);
}
private RemoteViews buildUpdate(int position) {

@ -12,7 +12,6 @@ import org.tasks.locale.Locale;
import org.tasks.preferences.DefaultFilterProvider;
import org.tasks.preferences.Preferences;
import org.tasks.themes.ThemeCache;
import org.tasks.ui.WidgetCheckBoxes;
public class ScrollableWidgetUpdateService extends RemoteViewsService {
@ -20,7 +19,6 @@ public class ScrollableWidgetUpdateService extends RemoteViewsService {
@Inject Preferences preferences;
@Inject SubtasksHelper subtasksHelper;
@Inject DefaultFilterProvider defaultFilterProvider;
@Inject WidgetCheckBoxes widgetCheckBoxes;
@Inject ThemeCache themeCache;
@Inject Locale locale;
@ -57,7 +55,6 @@ public class ScrollableWidgetUpdateService extends RemoteViewsService {
widgetId,
taskDao,
defaultFilterProvider,
widgetCheckBoxes,
themeCache);
}
}

Loading…
Cancel
Save