mirror of https://github.com/tasks/tasks
Add ColorProvider
parent
e18a3bb8b4
commit
b8c98aa2f1
@ -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)
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue