Add ColorProvider

pull/935/head
Alex Baker 5 years ago
parent e18a3bb8b4
commit b8c98aa2f1

@ -13,7 +13,6 @@ import static com.todoroo.andlib.utility.AndroidUtilities.atLeastNougat;
import static com.todoroo.astrid.activity.TaskEditFragment.newTaskEditFragment;
import static com.todoroo.astrid.activity.TaskListFragment.newTaskListFragment;
import static org.tasks.tasklist.ActionUtils.applySupportActionModeColor;
import static org.tasks.themes.ThemeColor.newThemeColor;
import static org.tasks.ui.NavigationDrawerFragment.REQUEST_NEW_LIST;
import android.annotation.SuppressLint;
@ -54,6 +53,7 @@ import org.tasks.intents.TaskIntents;
import org.tasks.preferences.DefaultFilterProvider;
import org.tasks.preferences.Preferences;
import org.tasks.receivers.RepeatConfirmationReceiver;
import org.tasks.themes.ColorProvider;
import org.tasks.themes.Theme;
import org.tasks.themes.ThemeColor;
import org.tasks.ui.DeadlineControlSet;
@ -92,6 +92,7 @@ public class MainActivity extends InjectingAppCompatActivity
@Inject TaskCreator taskCreator;
@Inject PlayServices playServices;
@Inject Inventory inventory;
@Inject ColorProvider colorProvider;
private CompositeDisposable disposables;
private NavigationDrawerFragment navigationDrawer;
@ -302,7 +303,7 @@ public class MainActivity extends InjectingAppCompatActivity
private ThemeColor getFilterColor() {
return filter != null && filter.tint != 0
? newThemeColor(this, filter.tint)
? colorProvider.getThemeColor(filter.tint, true)
: theme.getThemeColor();
}

@ -12,7 +12,6 @@ import static com.google.common.collect.Lists.newArrayList;
import static com.todoroo.andlib.utility.AndroidUtilities.assertMainThread;
import static org.tasks.activities.RemoteListPicker.newRemoteListSupportPicker;
import static org.tasks.caldav.CaldavCalendarSettingsActivity.EXTRA_CALDAV_CALENDAR;
import static org.tasks.themes.ThemeColor.newThemeColor;
import static org.tasks.ui.CheckBoxes.getPriorityColor;
import android.app.Activity;
@ -103,6 +102,7 @@ import org.tasks.tasklist.DragAndDropRecyclerAdapter;
import org.tasks.tasklist.PagedListRecyclerAdapter;
import org.tasks.tasklist.TaskListRecyclerAdapter;
import org.tasks.tasklist.ViewHolderFactory;
import org.tasks.themes.ColorProvider;
import org.tasks.themes.ThemeColor;
import org.tasks.ui.TaskListViewModel;
import org.tasks.ui.Toaster;
@ -153,6 +153,7 @@ public final class TaskListFragment extends InjectingFragment
@Inject TagDataDao tagDataDao;
@Inject CaldavDao caldavDao;
@Inject ThemeColor defaultThemeColor;
@Inject ColorProvider colorProvider;
@BindView(R.id.swipe_layout)
SwipeRefreshLayout swipeRefreshLayout;
@ -263,7 +264,7 @@ public final class TaskListFragment extends InjectingFragment
filter = getFilter();
themeColor = filter.tint != 0 ? newThemeColor(context, filter.tint) : defaultThemeColor;
themeColor = filter.tint != 0 ? colorProvider.getThemeColor(filter.tint, true) : defaultThemeColor;
filter.setFilterQueryOverride(null);

@ -25,6 +25,7 @@ import javax.inject.Inject;
import org.tasks.billing.Inventory;
import org.tasks.filters.NavigationDrawerSubheader;
import org.tasks.locale.Locale;
import org.tasks.themes.ColorProvider;
import org.tasks.themes.Theme;
import org.tasks.themes.ThemeAccent;
@ -37,16 +38,23 @@ public class FilterAdapter extends BaseAdapter {
private final ThemeAccent accent;
private final Locale locale;
private final Inventory inventory;
private final ColorProvider colorProvider;
private final LayoutInflater inflater;
private Filter selected = null;
private List<FilterListItem> items = new ArrayList<>();
@Inject
public FilterAdapter(Activity activity, Theme theme, Locale locale, Inventory inventory) {
public FilterAdapter(
Activity activity,
Theme theme,
Locale locale,
Inventory inventory,
ColorProvider colorProvider) {
this.activity = activity;
this.accent = theme.getThemeAccent();
this.locale = locale;
this.inventory = inventory;
this.colorProvider = colorProvider;
this.inflater = theme.getLayoutInflater(activity);
}
@ -101,7 +109,8 @@ public class FilterAdapter extends BaseAdapter {
switch (viewType) {
case ITEM:
viewHolder =
new FilterViewHolder(convertView, accent, false, locale, activity, inventory, null);
new FilterViewHolder(
convertView, accent, false, locale, activity, inventory, colorProvider, null);
break;
case SEPARATOR:
viewHolder = new FilterViewHolder(convertView);

@ -1,7 +1,6 @@
package com.todoroo.astrid.adapter;
import static com.todoroo.andlib.utility.AndroidUtilities.preLollipop;
import static org.tasks.themes.ThemeColor.newThemeColor;
import android.app.Activity;
import android.content.Intent;
@ -29,6 +28,7 @@ import org.tasks.billing.Inventory;
import org.tasks.filters.NavigationDrawerSubheader;
import org.tasks.locale.Locale;
import org.tasks.preferences.SyncPreferences;
import org.tasks.themes.ColorProvider;
import org.tasks.themes.CustomIcons;
import org.tasks.themes.DrawableUtil;
import org.tasks.themes.ThemeAccent;
@ -56,6 +56,7 @@ public class FilterViewHolder extends RecyclerView.ViewHolder {
private Activity activity;
private View itemView;
private Inventory inventory;
private ColorProvider colorProvider;
FilterViewHolder(
@NonNull View itemView,
@ -64,9 +65,11 @@ public class FilterViewHolder extends RecyclerView.ViewHolder {
Locale locale,
Activity activity,
Inventory inventory,
ColorProvider colorProvider,
OnClick onClick) {
super(itemView);
this.inventory = inventory;
this.colorProvider = colorProvider;
ButterKnife.bind(this, itemView);
@ -135,7 +138,7 @@ public class FilterViewHolder extends RecyclerView.ViewHolder {
private int getColor(FilterListItem filter) {
if (filter.tint != 0) {
ThemeColor color = newThemeColor(activity, filter.tint);
ThemeColor color = colorProvider.getThemeColor(filter.tint, true);
if (color.isFree() || inventory.purchasedThemes()) {
return color.getPrimaryColor();
}

@ -30,6 +30,7 @@ import javax.inject.Inject;
import org.tasks.billing.Inventory;
import org.tasks.filters.NavigationDrawerSubheader;
import org.tasks.locale.Locale;
import org.tasks.themes.ColorProvider;
import org.tasks.themes.Theme;
import org.tasks.themes.ThemeAccent;
@ -40,6 +41,7 @@ public class NavigationDrawerAdapter extends ListAdapter<FilterListItem, FilterV
private final ThemeAccent accent;
private final Locale locale;
private final Inventory inventory;
private final ColorProvider colorProvider;
private final LayoutInflater inflater;
private OnClick onClick;
private Filter selected = null;
@ -47,12 +49,17 @@ public class NavigationDrawerAdapter extends ListAdapter<FilterListItem, FilterV
@Inject
public NavigationDrawerAdapter(
Activity activity, Theme theme, Locale locale, Inventory inventory) {
Activity activity,
Theme theme,
Locale locale,
Inventory inventory,
ColorProvider colorProvider) {
super(new DiffCallback());
this.activity = activity;
this.accent = theme.getThemeAccent();
this.locale = locale;
this.inventory = inventory;
this.colorProvider = colorProvider;
this.inflater = theme.getLayoutInflater(activity);
}
@ -95,7 +102,7 @@ public class NavigationDrawerAdapter extends ListAdapter<FilterListItem, FilterV
View view = inflater.inflate(type.layout, parent, false);
if (type == ITEM) {
return new FilterViewHolder(
view, accent, true, locale, activity, inventory, this::onClickFilter);
view, accent, true, locale, activity, inventory, colorProvider, this::onClickFilter);
} else if (type == SUBHEADER) {
return new FilterViewHolder(view, activity);
} else {

@ -26,7 +26,6 @@ import org.tasks.scheduling.CalendarNotificationIntentService;
import org.tasks.scheduling.NotificationSchedulerIntentService;
import org.tasks.scheduling.RefreshScheduler;
import org.tasks.themes.ThemeBase;
import org.tasks.themes.ThemeColor;
import timber.log.Timber;
public class Tasks extends InjectingApplication {
@ -59,7 +58,6 @@ public class Tasks extends InjectingApplication {
preferences.setSyncOngoing(false);
ThemeBase.getThemeBase(preferences, inventory, null).setDefaultNightMode();
ThemeColor.enableSaturation(preferences.getBoolean(R.string.p_desaturate_colors, true));
localBroadcastManager.registerRefreshReceiver(new RefreshBroadcastReceiver());

@ -2,7 +2,6 @@ package org.tasks.activities;
import static org.tasks.dialogs.IconPickerDialog.newIconPicker;
import static org.tasks.themes.DrawableUtil.getLeftDrawable;
import static org.tasks.themes.ThemeColor.newThemeColor;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
@ -26,6 +25,7 @@ import org.tasks.dialogs.ColorWheelPicker;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.dialogs.IconPickerDialog.IconPickerCallback;
import org.tasks.injection.ThemedInjectingAppCompatActivity;
import org.tasks.themes.ColorProvider;
import org.tasks.themes.CustomIcons;
import org.tasks.themes.DrawableUtil;
import org.tasks.themes.ThemeColor;
@ -57,6 +57,7 @@ public abstract class BaseListSettingsActivity extends ThemedInjectingAppCompatA
@Inject ThemeColor themeColor;
@Inject DialogBuilder dialogBuilder;
@Inject ColorProvider colorProvider;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -172,7 +173,7 @@ public abstract class BaseListSettingsActivity extends ThemedInjectingAppCompatA
getLeftDrawable(color), ContextCompat.getColor(this, R.color.icon_tint_with_alpha));
clear.setVisibility(View.GONE);
} else {
themeColor = newThemeColor(this, selectedColor);
themeColor = colorProvider.getThemeColor(selectedColor, true);
DrawableUtil.setLeftDrawable(this, color, R.drawable.color_picker);
Drawable leftDrawable = getLeftDrawable(color);
DrawableCompat.setTint(

@ -21,6 +21,7 @@ import org.tasks.dialogs.ColorPickerAdapter.Palette
import org.tasks.dialogs.ColorWheelPicker.Companion.newColorWheel
import org.tasks.injection.DialogFragmentComponent
import org.tasks.injection.InjectingDialogFragment
import org.tasks.themes.ColorProvider
import org.tasks.themes.ThemeAccent
import org.tasks.themes.ThemeColor
import javax.inject.Inject
@ -67,6 +68,7 @@ class ColorPalettePicker : InjectingDialogFragment() {
@Inject lateinit var dialogBuilder: DialogBuilder
@Inject lateinit var inventory: Inventory
@Inject lateinit var colorProvider: ColorProvider
@BindView(R.id.icons) lateinit var recyclerView: RecyclerView
@ -80,18 +82,14 @@ class ColorPalettePicker : InjectingDialogFragment() {
ButterKnife.bind(this, view)
palette = arguments!!.getSerializable(EXTRA_PALETTE) as Palette
colors = when (palette) {
Palette.COLORS -> ThemeColor.COLORS.map { color ->
ThemeColor(context, ContextCompat.getColor(context!!, color), true)
}
Palette.COLORS -> colorProvider.getThemeColors()
Palette.ACCENTS -> ThemeAccent.ACCENTS.mapIndexed { index, _ ->
ThemeAccent(context, index)
}
Palette.LAUNCHERS -> ThemeColor.LAUNCHER_COLORS.map { color ->
ThemeColor(context, ContextCompat.getColor(context!!, color), false)
}
Palette.WIDGET -> ThemeColor.COLORS.map { color ->
ThemeColor(context, ContextCompat.getColor(context!!, color), false)
ThemeColor(context, ContextCompat.getColor(context!!, color))
}
Palette.WIDGET -> colorProvider.getWidgetColors()
}
val iconPickerAdapter = ColorPickerAdapter(

@ -9,6 +9,7 @@ import org.tasks.billing.Inventory;
import org.tasks.location.Geocoder;
import org.tasks.location.MapboxGeocoder;
import org.tasks.preferences.Preferences;
import org.tasks.themes.ColorProvider;
import org.tasks.themes.ThemeAccent;
import org.tasks.themes.ThemeBase;
import org.tasks.themes.ThemeColor;
@ -41,8 +42,8 @@ public class ActivityModule {
@Provides
@ActivityScope
public ThemeColor getThemeColor(Preferences preferences) {
return ThemeColor.newThemeColor(activity, preferences.getInt(R.string.p_theme_color, 0));
public ThemeColor getThemeColor(ColorProvider colorProvider, Preferences preferences) {
return colorProvider.getThemeColor(preferences.getInt(R.string.p_theme_color, 0), true);
}
@Provides

@ -109,7 +109,6 @@ class LookAndFeel : InjectingPreferenceFragment(), Preference.OnPreferenceChange
}
findPreference(R.string.p_desaturate_colors).setOnPreferenceChangeListener { _, newValue ->
ThemeColor.enableSaturation(newValue as Boolean)
if (context?.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES) {
activity?.recreate()
}

@ -19,6 +19,7 @@ import org.tasks.data.TagData;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.ThemedInjectingAppCompatActivity;
import org.tasks.tags.CheckBoxTriStates.State;
import org.tasks.themes.ColorProvider;
import org.tasks.themes.Theme;
import org.tasks.themes.ThemeColor;
@ -39,6 +40,7 @@ public class TagPickerActivity extends ThemedInjectingAppCompatActivity {
@Inject Theme theme;
@Inject Inventory inventory;
@Inject ColorProvider colorProvider;
private TagPickerViewModel viewModel;
private ArrayList<Long> taskIds;
@ -68,7 +70,7 @@ public class TagPickerActivity extends ThemedInjectingAppCompatActivity {
themeColor.apply(toolbar);
TagRecyclerAdapter recyclerAdapter =
new TagRecyclerAdapter(this, viewModel, inventory, this::onToggle);
new TagRecyclerAdapter(this, viewModel, inventory, colorProvider, this::onToggle);
recyclerView.setAdapter(recyclerAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));

@ -1,7 +1,5 @@
package org.tasks.tags;
import static org.tasks.themes.ThemeColor.newThemeColor;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
@ -17,7 +15,9 @@ import org.tasks.R;
import org.tasks.billing.Inventory;
import org.tasks.data.TagData;
import org.tasks.tags.CheckBoxTriStates.State;
import org.tasks.themes.ColorProvider;
import org.tasks.themes.CustomIcons;
import org.tasks.themes.ThemeColor;
public class TagRecyclerAdapter extends RecyclerView.Adapter<TagPickerViewHolder> {
@ -25,16 +25,19 @@ public class TagRecyclerAdapter extends RecyclerView.Adapter<TagPickerViewHolder
private final Context context;
private final TagPickerViewModel viewModel;
private final Inventory inventory;
private final ColorProvider colorProvider;
private final Function2<TagData, Boolean, State> callback;
TagRecyclerAdapter(
Context context,
TagPickerViewModel viewModel,
Inventory inventory,
ColorProvider colorProvider,
Function2<TagData, Boolean, State> callback) {
this.context = context;
this.viewModel = viewModel;
this.inventory = inventory;
this.colorProvider = colorProvider;
this.callback = callback;
differ = new AsyncListDiffer<>(this, new TagDiffCallback());
}
@ -58,9 +61,13 @@ public class TagRecyclerAdapter extends RecyclerView.Adapter<TagPickerViewHolder
}
private int getColor(TagData tagData) {
return tagData.getColor() == 0
? ContextCompat.getColor(context, R.color.icon_tint_with_alpha)
: newThemeColor(context, tagData.getColor()).getPrimaryColor();
if (tagData.getColor() != 0) {
ThemeColor themeColor = colorProvider.getThemeColor(tagData.getColor(), true);
if (inventory.purchasedThemes() || themeColor.isFree()) {
return themeColor.getPrimaryColor();
}
}
return ContextCompat.getColor(context, R.color.icon_tint_with_alpha);
}
private @Nullable Integer getIcon(TagData tagData) {

@ -0,0 +1,88 @@
package org.tasks.themes
import android.content.Context
import androidx.annotation.ColorInt
import androidx.core.content.ContextCompat
import org.tasks.R
import org.tasks.injection.ForActivity
import org.tasks.preferences.Preferences
import javax.inject.Inject
class ColorProvider @Inject constructor(@ForActivity private val context: Context, preferences: Preferences) {
companion object {
private const val RED = -769226
private const val AMBER = -16121
private const val BLUE = -14575885
private const val GREY = -6381922
private const val WHITE = -1
private const val BLACK = -16777216
private val saturated: Map<Int, Int> = hashMapOf(
// 2014 material design palette
-10453621 to -5194043, // blue_grey
-12434878 to -14606047, // grey
RED to -1074534, // red
-1499549 to -749647, // pink
-6543440 to -3238952, // purple
-10011977 to -5005861, // deep purple
// -12627531 to -6313766, // indigo
BLUE to -7288071, // blue
-16537100 to -8268550, // light blue
-16728876 to -8331542, // cyan
// -16738680 to -8336444, // teal
-11751600 to -5908825, // green
-7617718 to -3808859, // light green
-3285959 to -1642852, // lime
-5317 to -2659, // yellow
AMBER to -8062, // amber
-26624 to -13184, // orange
-43230 to -21615, // deep orange
// -8825528 to -4412764, // brown
GREY to -1118482, // grey
WHITE to BLACK,
// 2019 google calendar
-2818048 to -3397335, // tomato
-765666 to -2136512, // tangerine
-1086464 to -2459092, // pumpkin
-1010944 to -2254804, // mango
-606426 to -2050234, // banana
-1784767 to -2769834, // citron
-4142541 to -4274613, // avocado
-8604862 to -7817131, // pistachio
-16023485 to -14116514, // basil
-16738680 to -14571622, // eucalyptus
-13388167 to -11879802, // sage
-16540699 to -13787178, // peacock
-12417548 to -10974241, // cobalt
-12627531 to -11312199, // blueberry
-8812853 to -8615738, // lavender
-5005861 to -5597744, // wisteria
-6395473 to -5934410, // amethyst
-7461718 to -6668365, // grape
-5434281 to -4967572, // radicchio
-2614432 to -3261327, // cherry blossom
-1672077 to -2654344, // flamingo
-8825528 to -6984611, // cocoa
-10395295 to -7895161, // graphite
-5792882 to -5135210 // birch
)
}
private val isDark = context.resources.getBoolean(R.bool.is_dark)
private val desaturate = preferences.getBoolean(R.string.p_desaturate_colors, true)
fun getThemeColor(@ColorInt color: Int, adjust: Boolean = true) =
ThemeColor(context, color, if (adjust && isDark && desaturate) {
saturated[color] ?: color
} else {
color
})
fun getThemeColors(adjust: Boolean = true) = ThemeColor.COLORS.map { c ->
getThemeColor(ContextCompat.getColor(context, c), adjust)
}
fun getWidgetColors() = getThemeColors(true)
}

@ -1,6 +1,5 @@
package org.tasks.themes;
import static com.google.common.collect.Maps.newHashMap;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastLollipop;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastMarshmallow;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastOreo;
@ -26,11 +25,8 @@ import androidx.core.graphics.ColorUtils;
import androidx.core.os.ParcelCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import java.util.Collections;
import java.util.Map;
import org.tasks.R;
import org.tasks.dialogs.ColorPalettePicker.Pickable;
import timber.log.Timber;
public class ThemeColor implements Pickable {
@ -165,66 +161,8 @@ public class ThemeColor implements Pickable {
}
};
private static final int BLUE = -14575885;
private static final int WHITE = -1;
private static final int BLACK = -16777216;
private static final Map<Integer, Integer> saturated = newHashMap();
public static Map<Integer, Integer> colorMap = saturated;
public static void enableSaturation(boolean enabled) {
colorMap = enabled ? saturated : Collections.emptyMap();
}
static {
// 2014 material design palette
saturated.put(-10453621, -5194043); // blue_grey
saturated.put(-12434878, -14606047); // grey
saturated.put(-769226, -1074534); // red
saturated.put(-1499549, -749647); // pink
saturated.put(-6543440, -3238952); // purple
saturated.put(-10011977, -5005861); // deep purple
saturated.put(-12627531, -6313766); // indigo
saturated.put(-14575885, -7288071); // blue
saturated.put(-16537100, -8268550); // light blue
saturated.put(-16728876, -8331542); // cyan
saturated.put(-16738680, -8336444); // teal
saturated.put(-11751600, -5908825); // green
saturated.put(-7617718, -3808859); // light green
saturated.put(-3285959, -1642852); // lime
saturated.put(-5317, -2659); // yellow
saturated.put(-16121, -8062); // amber
saturated.put(-26624, -13184); // orange
saturated.put(-43230, -21615); // deep orange
saturated.put(-8825528, -4412764); // brown
saturated.put(-6381922, -1118482); // grey
saturated.put(WHITE, BLACK);
// 2019 google calendar
saturated.put(-2818048, -3397335); // tomato
saturated.put(-765666, -2136512); // tangerine
saturated.put(-1086464, -2459092); // pumpkin
saturated.put(-1010944, -2254804); // mango
saturated.put(-606426, -2050234); // banana
saturated.put(-1784767, -2769834); // citron
saturated.put(-4142541, -4274613); // avocado
saturated.put(-8604862, -7817131); // pistachio
saturated.put(-16023485, -14116514); // basil
// saturated.put(-16738680, -14571622); // eucalyptus
saturated.put(-13388167, -11879802); // sage
saturated.put(-16540699, -13787178); // peacock
saturated.put(-12417548, -10974241); // cobalt
// saturated.put(-12627531, -11312199); // blueberry
saturated.put(-8812853, -8615738); // lavender
saturated.put(-5005861, -5597744); // wisteria
saturated.put(-6395473, -5934410); // amethyst
saturated.put(-7461718, -6668365); // grape
saturated.put(-5434281, -4967572); // radicchio
saturated.put(-2614432, -3261327); // cherry blossom
saturated.put(-1672077, -2654344); // flamingo
// saturated.put(-8825528, -6984611); // cocoa
saturated.put(-10395295, -7895161); // graphite
saturated.put(-5792882, -5135210); // birch
}
private final int original;
private final int colorOnPrimary;
@ -233,17 +171,17 @@ public class ThemeColor implements Pickable {
private final boolean isDark;
public ThemeColor(Context context, int color) {
this(context, color == 0 ? ContextCompat.getColor(context, R.color.blue_500) : color, true);
this(context, color, color);
}
public ThemeColor(Context context, int color, boolean adjustColor) {
color |= 0xFF000000; // remove alpha
original = color;
if (adjustColor && context.getResources().getBoolean(R.bool.is_dark)) {
colorPrimary = desaturate(color);
public ThemeColor(Context context, int original, int color) {
this.original = original;
if (color == 0) {
color = BLUE;
} else {
colorPrimary = color;
color |= 0xFF000000; // remove alpha
}
colorPrimary = color;
colorPrimaryVariant = ColorUtil.darken(colorPrimary, 6);
double contrast = ColorUtils.calculateContrast(WHITE, colorPrimary);
@ -260,16 +198,7 @@ public class ThemeColor implements Pickable {
}
public static ThemeColor getLauncherColor(Context context, int index) {
return new ThemeColor(context, ContextCompat.getColor(context, LAUNCHER_COLORS[index]), false);
}
public static ThemeColor newThemeColor(Context context, int color) {
try {
return new ThemeColor(context, color);
} catch (Exception e) {
Timber.e(e);
return new ThemeColor(context, 0);
}
return new ThemeColor(context, ContextCompat.getColor(context, LAUNCHER_COLORS[index]));
}
private static void colorMenu(Menu menu, int color) {
@ -297,15 +226,6 @@ public class ThemeColor implements Pickable {
return drawable;
}
private int desaturate(int color) {
if (colorMap.containsKey(color)) {
//noinspection ConstantConditions
return colorMap.get(color);
} else {
return color;
}
}
public void applyToSystemBars(Activity activity) {
setStatusBarColor(activity);

@ -0,0 +1,76 @@
package org.tasks.ui;
import com.todoroo.astrid.api.CaldavFilter;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.GtasksFilter;
import com.todoroo.astrid.api.TagFilter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.tasks.LocalBroadcastManager;
import org.tasks.data.CaldavCalendar;
import org.tasks.data.CaldavDao;
import org.tasks.data.GoogleTaskList;
import org.tasks.data.GoogleTaskListDao;
import org.tasks.data.TagData;
import org.tasks.data.TagDataDao;
import org.tasks.injection.ApplicationScope;
@ApplicationScope
public class ChipListCache {
private final Map<String, GtasksFilter> googleTaskLists = new HashMap<>();
private final Map<String, CaldavFilter> caldavCalendars = new HashMap<>();
private final Map<String, TagFilter> tagDatas = new HashMap<>();
private final LocalBroadcastManager localBroadcastManager;
@Inject
public ChipListCache(
GoogleTaskListDao googleTaskListDao,
CaldavDao caldavDao,
TagDataDao tagDataDao,
LocalBroadcastManager localBroadcastManager) {
this.localBroadcastManager = localBroadcastManager;
googleTaskListDao.subscribeToLists().observeForever(this::updateGoogleTaskLists);
caldavDao.subscribeToCalendars().observeForever(this::updateCaldavCalendars);
tagDataDao.subscribeToTags().observeForever(this::updateTags);
}
private void updateGoogleTaskLists(List<GoogleTaskList> updated) {
googleTaskLists.clear();
for (GoogleTaskList update : updated) {
googleTaskLists.put(update.getRemoteId(), new GtasksFilter(update));
}
localBroadcastManager.broadcastRefresh();
}
private void updateCaldavCalendars(List<CaldavCalendar> updated) {
caldavCalendars.clear();
for (CaldavCalendar update : updated) {
caldavCalendars.put(update.getUuid(), new CaldavFilter(update));
}
localBroadcastManager.broadcastRefresh();
}
private void updateTags(List<TagData> updated) {
tagDatas.clear();
for (TagData update : updated) {
tagDatas.put(update.getRemoteId(), new TagFilter(update));
}
localBroadcastManager.broadcastRefresh();
}
Filter getGoogleTaskList(String googleTaskList) {
return googleTaskLists.get(googleTaskList);
}
Filter getCaldavList(String caldav) {
return caldavCalendars.get(caldav);
}
TagFilter getTag(String tag) {
return tagDatas.get(tag);
}
}

@ -1,12 +1,10 @@
package org.tasks.ui;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Collections2.filter;
import static com.google.common.collect.Collections2.transform;
import static com.google.common.collect.Iterables.removeIf;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Lists.transform;
import static com.google.common.collect.Sets.newHashSet;
import static com.todoroo.andlib.utility.AndroidUtilities.assertMainThread;
import static org.tasks.themes.ThemeColor.newThemeColor;
import android.app.Activity;
import android.content.Context;
@ -24,36 +22,25 @@ import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.GtasksFilter;
import com.todoroo.astrid.api.TagFilter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import org.tasks.LocalBroadcastManager;
import org.tasks.R;
import org.tasks.billing.Inventory;
import org.tasks.data.CaldavCalendar;
import org.tasks.data.CaldavDao;
import org.tasks.data.GoogleTaskList;
import org.tasks.data.GoogleTaskListDao;
import org.tasks.data.TagData;
import org.tasks.data.TagDataDao;
import org.tasks.data.TaskContainer;
import org.tasks.injection.ApplicationScope;
import org.tasks.injection.ForApplication;
import org.tasks.injection.ForActivity;
import org.tasks.preferences.Preferences;
import org.tasks.themes.ColorProvider;
import org.tasks.themes.CustomIcons;
import org.tasks.themes.ThemeColor;
@ApplicationScope
public class ChipProvider {
private final Map<String, GtasksFilter> googleTaskLists = new HashMap<>();
private final Map<String, CaldavFilter> caldavCalendars = new HashMap<>();
private final Map<String, TagFilter> tagDatas = new HashMap<>();
private final Inventory inventory;
private final int iconAlpha;
private final LocalBroadcastManager localBroadcastManager;
private final ChipListCache lists;
private final ColorProvider colorProvider;
private final Ordering<TagFilter> orderByName =
new Ordering<TagFilter>() {
@Override
@ -67,21 +54,17 @@ public class ChipProvider {
@Inject
public ChipProvider(
@ForApplication Context context,
@ForActivity Context context,
Inventory inventory,
GoogleTaskListDao googleTaskListDao,
CaldavDao caldavDao,
TagDataDao tagDataDao,
LocalBroadcastManager localBroadcastManager,
Preferences preferences) {
ChipListCache lists,
Preferences preferences,
ColorProvider colorProvider) {
this.inventory = inventory;
this.localBroadcastManager = localBroadcastManager;
iconAlpha =
(int) (255 * ResourcesCompat.getFloat(context.getResources(), R.dimen.alpha_secondary));
this.lists = lists;
this.colorProvider = colorProvider;
googleTaskListDao.subscribeToLists().observeForever(this::updateGoogleTaskLists);
caldavDao.subscribeToCalendars().observeForever(this::updateCaldavCalendars);
tagDataDao.subscribeToTags().observeForever(this::updateTags);
setStyle(preferences.getIntegerFromString(R.string.p_chip_style, 0));
setAppearance(preferences.getIntegerFromString(R.string.p_chip_appearance, 0));
}
@ -95,30 +78,6 @@ public class ChipProvider {
showIcon = appearance != 1;
}
private void updateGoogleTaskLists(List<GoogleTaskList> updated) {
googleTaskLists.clear();
for (GoogleTaskList update : updated) {
googleTaskLists.put(update.getRemoteId(), new GtasksFilter(update));
}
localBroadcastManager.broadcastRefresh();
}
private void updateCaldavCalendars(List<CaldavCalendar> updated) {
caldavCalendars.clear();
for (CaldavCalendar update : updated) {
caldavCalendars.put(update.getUuid(), new CaldavFilter(update));
}
localBroadcastManager.broadcastRefresh();
}
private void updateTags(List<TagData> updated) {
tagDatas.clear();
for (TagData update : updated) {
tagDatas.put(update.getRemoteId(), new TagFilter(update));
}
localBroadcastManager.broadcastRefresh();
}
public List<Chip> getChips(
Activity activity,
Filter filter,
@ -131,7 +90,6 @@ public class ChipProvider {
if (!hideSubtaskChip && task.hasChildren()) {
Chip chip = newChip(activity, task);
apply(
activity,
chip,
task.isCollapsed()
? R.drawable.ic_keyboard_arrow_up_black_24dp
@ -146,8 +104,7 @@ public class ChipProvider {
}
if (task.hasLocation()) {
Chip chip = newChip(activity, task.getLocation());
apply(
activity, chip, R.drawable.ic_outline_place_24px, task.getLocation().getDisplayName(), 0, showText, showIcon);
apply(chip, R.drawable.ic_outline_place_24px, task.getLocation().getDisplayName(), 0, showText, showIcon);
chips.add(chip);
}
if (!isSubtask) {
@ -155,12 +112,12 @@ public class ChipProvider {
chips.add(
newChip(
activity,
googleTaskLists.get(task.getGoogleTaskList()),
lists.getGoogleTaskList(task.getGoogleTaskList()),
R.drawable.ic_outline_cloud_24px));
} else if (!Strings.isNullOrEmpty(task.getCaldav()) && !(filter instanceof CaldavFilter)) {
chips.add(
newChip(
activity, caldavCalendars.get(task.getCaldav()), R.drawable.ic_outline_cloud_24px));
activity, lists.getCaldavList(task.getCaldav()), R.drawable.ic_outline_cloud_24px));
}
}
String tagString = task.getTagsString();
@ -171,7 +128,7 @@ public class ChipProvider {
}
chips.addAll(
transform(
orderByName.sortedCopy(filter(transform(tags, tagDatas::get), Predicates.notNull())),
orderByName.sortedCopy(filter(transform(tags, lists::getTag), Predicates.notNull())),
tag -> newChip(activity, tag, R.drawable.ic_outline_label_24px)));
}
@ -181,7 +138,6 @@ public class ChipProvider {
public void apply(Chip chip, Filter filter) {
apply(
chip.getContext(),
chip,
getIcon(filter.icon, R.drawable.ic_outline_cloud_24px),
filter.listingTitle,
@ -192,7 +148,6 @@ public class ChipProvider {
public void apply(Chip chip, @NonNull TagData tagData) {
apply(
chip.getContext(),
chip,
getIcon(tagData.getIcon(), R.drawable.ic_outline_label_24px),
tagData.getName(),
@ -210,7 +165,7 @@ public class ChipProvider {
return null;
}
Chip chip = newChip(activity, filter);
apply(activity, chip, getIcon(filter.icon, defIcon), filter.listingTitle, filter.tint, showText, showIcon);
apply(chip, getIcon(filter.icon, defIcon), filter.listingTitle, filter.tint, showText, showIcon);
return chip;
}
@ -235,7 +190,6 @@ public class ChipProvider {
}
private void apply(
Context context,
Chip chip,
@Nullable @DrawableRes Integer icon,
String name,
@ -251,7 +205,7 @@ public class ChipProvider {
chip.setTextStartPadding(0f);
chip.setChipEndPadding(0f);
}
ThemeColor themeColor = getColor(context, theme);
ThemeColor themeColor = getColor(theme);
if (themeColor != null) {
int primaryColor = themeColor.getPrimaryColor();
ColorStateList primaryColorSL =
@ -282,9 +236,9 @@ public class ChipProvider {
return icon != null ? icon : def;
}
private @Nullable ThemeColor getColor(Context context, int theme) {
private @Nullable ThemeColor getColor(int theme) {
if (theme != 0) {
ThemeColor color = newThemeColor(context, theme);
ThemeColor color = colorProvider.getThemeColor(theme, true);
if (color.isFree() || inventory.purchasedThemes()) {
return color;
}

@ -8,13 +8,14 @@ import com.todoroo.astrid.api.Filter
import org.tasks.databinding.FragmentTaskEditEmptyBinding
import org.tasks.injection.FragmentComponent
import org.tasks.injection.InjectingFragment
import org.tasks.themes.ColorProvider
import org.tasks.themes.ThemeColor
import org.tasks.themes.ThemeColor.newThemeColor
import javax.inject.Inject
class EmptyTaskEditFragment : InjectingFragment() {
@Inject lateinit var themeColor: ThemeColor
@Inject lateinit var colorProvider: ColorProvider
companion object {
const val EXTRA_FILTER = "extra_filter"
@ -35,10 +36,11 @@ class EmptyTaskEditFragment : InjectingFragment() {
val tint = arguments?.getParcelable<Filter>(EXTRA_FILTER)?.tint
val color = newThemeColor(
context!!,
if (tint == null || tint == 0) themeColor.primaryColor else tint
)
val color = colorProvider.getThemeColor(if (tint == null || tint == 0) {
themeColor.primaryColor
} else {
tint
})
color.apply(binding.toolbar.toolbar)

@ -73,7 +73,7 @@ public class TasksWidget extends InjectingAppWidgetProvider {
Intent rvIntent = new Intent(context, ScrollableWidgetUpdateService.class);
rvIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
rvIntent.setData(Uri.parse(rvIntent.toUri(Intent.URI_INTENT_SCHEME)));
ThemeColor color = new ThemeColor(context, widgetPreferences.getColor(), false);
ThemeColor color = new ThemeColor(context, widgetPreferences.getColor());
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.scrollable_widget);
if (atLeastJellybeanMR1()) {
remoteViews.setInt(R.id.widget, "setLayoutDirection", locale.getDirectionality());

Loading…
Cancel
Save