|
|
@ -11,7 +11,8 @@ import static org.tasks.themes.ThemeColor.newThemeColor;
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.res.ColorStateList;
|
|
|
|
import android.content.res.ColorStateList;
|
|
|
|
import androidx.annotation.LayoutRes;
|
|
|
|
import androidx.annotation.ColorInt;
|
|
|
|
|
|
|
|
import androidx.annotation.DrawableRes;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
@ -42,6 +43,7 @@ import org.tasks.data.TagDataDao;
|
|
|
|
import org.tasks.data.TaskContainer;
|
|
|
|
import org.tasks.data.TaskContainer;
|
|
|
|
import org.tasks.injection.ApplicationScope;
|
|
|
|
import org.tasks.injection.ApplicationScope;
|
|
|
|
import org.tasks.injection.ForApplication;
|
|
|
|
import org.tasks.injection.ForApplication;
|
|
|
|
|
|
|
|
import org.tasks.themes.CustomIcons;
|
|
|
|
import org.tasks.themes.ThemeColor;
|
|
|
|
import org.tasks.themes.ThemeColor;
|
|
|
|
|
|
|
|
|
|
|
|
@ApplicationScope
|
|
|
|
@ApplicationScope
|
|
|
@ -50,7 +52,6 @@ public class ChipProvider {
|
|
|
|
private final Map<String, GtasksFilter> googleTaskLists = new HashMap<>();
|
|
|
|
private final Map<String, GtasksFilter> googleTaskLists = new HashMap<>();
|
|
|
|
private final Map<String, CaldavFilter> caldavCalendars = new HashMap<>();
|
|
|
|
private final Map<String, CaldavFilter> caldavCalendars = new HashMap<>();
|
|
|
|
private final Map<String, TagFilter> tagDatas = new HashMap<>();
|
|
|
|
private final Map<String, TagFilter> tagDatas = new HashMap<>();
|
|
|
|
private final Context context;
|
|
|
|
|
|
|
|
private final Inventory inventory;
|
|
|
|
private final Inventory inventory;
|
|
|
|
private final int iconAlpha;
|
|
|
|
private final int iconAlpha;
|
|
|
|
private final LocalBroadcastManager localBroadcastManager;
|
|
|
|
private final LocalBroadcastManager localBroadcastManager;
|
|
|
@ -61,7 +62,6 @@ public class ChipProvider {
|
|
|
|
return left.listingTitle.compareTo(right.listingTitle);
|
|
|
|
return left.listingTitle.compareTo(right.listingTitle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
private final ThemeColor untagged;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
@Inject
|
|
|
|
public ChipProvider(
|
|
|
|
public ChipProvider(
|
|
|
@ -71,10 +71,8 @@ public class ChipProvider {
|
|
|
|
CaldavDao caldavDao,
|
|
|
|
CaldavDao caldavDao,
|
|
|
|
TagDataDao tagDataDao,
|
|
|
|
TagDataDao tagDataDao,
|
|
|
|
LocalBroadcastManager localBroadcastManager) {
|
|
|
|
LocalBroadcastManager localBroadcastManager) {
|
|
|
|
this.context = context;
|
|
|
|
|
|
|
|
this.inventory = inventory;
|
|
|
|
this.inventory = inventory;
|
|
|
|
this.localBroadcastManager = localBroadcastManager;
|
|
|
|
this.localBroadcastManager = localBroadcastManager;
|
|
|
|
untagged = getUntaggedThemeColor(context);
|
|
|
|
|
|
|
|
iconAlpha =
|
|
|
|
iconAlpha =
|
|
|
|
(int) (255 * ResourcesCompat.getFloat(context.getResources(), R.dimen.alpha_secondary));
|
|
|
|
(int) (255 * ResourcesCompat.getFloat(context.getResources(), R.dimen.alpha_secondary));
|
|
|
|
|
|
|
|
|
|
|
@ -117,30 +115,36 @@ public class ChipProvider {
|
|
|
|
|
|
|
|
|
|
|
|
List<Chip> chips = new ArrayList<>();
|
|
|
|
List<Chip> chips = new ArrayList<>();
|
|
|
|
if (!hideSubtaskChip && task.hasChildren()) {
|
|
|
|
if (!hideSubtaskChip && task.hasChildren()) {
|
|
|
|
chips.add(
|
|
|
|
Chip chip = newChip(activity, task);
|
|
|
|
newIconChip(
|
|
|
|
apply(
|
|
|
|
activity,
|
|
|
|
activity,
|
|
|
|
|
|
|
|
chip,
|
|
|
|
task.isCollapsed()
|
|
|
|
task.isCollapsed()
|
|
|
|
? R.drawable.ic_keyboard_arrow_up_black_24dp
|
|
|
|
? R.drawable.ic_keyboard_arrow_up_black_24dp
|
|
|
|
: R.drawable.ic_keyboard_arrow_down_black_24dp,
|
|
|
|
: R.drawable.ic_keyboard_arrow_down_black_24dp,
|
|
|
|
activity
|
|
|
|
activity
|
|
|
|
.getResources()
|
|
|
|
.getResources()
|
|
|
|
.getQuantityString(R.plurals.subtask_count, task.children, task.children),
|
|
|
|
.getQuantityString(R.plurals.subtask_count, task.children, task.children),
|
|
|
|
task));
|
|
|
|
0);
|
|
|
|
|
|
|
|
chips.add(chip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (task.hasLocation()) {
|
|
|
|
if (task.hasLocation()) {
|
|
|
|
chips.add(
|
|
|
|
Chip chip = newChip(activity, task.getLocation());
|
|
|
|
newIconChip(
|
|
|
|
apply(
|
|
|
|
activity,
|
|
|
|
activity, chip, R.drawable.ic_outline_place_24px, task.getLocation().getDisplayName(), 0);
|
|
|
|
R.drawable.ic_outline_place_24px,
|
|
|
|
chips.add(chip);
|
|
|
|
task.getLocation().getDisplayName(),
|
|
|
|
|
|
|
|
task.getLocation()));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isSubtask) {
|
|
|
|
if (!isSubtask) {
|
|
|
|
if (!Strings.isNullOrEmpty(task.getGoogleTaskList()) && !(filter instanceof GtasksFilter)) {
|
|
|
|
if (!Strings.isNullOrEmpty(task.getGoogleTaskList()) && !(filter instanceof GtasksFilter)) {
|
|
|
|
chips.add(newTagChip(activity, googleTaskLists.get(task.getGoogleTaskList())));
|
|
|
|
chips.add(
|
|
|
|
|
|
|
|
newTagChip(
|
|
|
|
|
|
|
|
activity,
|
|
|
|
|
|
|
|
googleTaskLists.get(task.getGoogleTaskList()),
|
|
|
|
|
|
|
|
R.drawable.ic_outline_cloud_24px));
|
|
|
|
} else if (!Strings.isNullOrEmpty(task.getCaldav()) && !(filter instanceof CaldavFilter)) {
|
|
|
|
} else if (!Strings.isNullOrEmpty(task.getCaldav()) && !(filter instanceof CaldavFilter)) {
|
|
|
|
chips.add(newTagChip(activity, caldavCalendars.get(task.getCaldav())));
|
|
|
|
chips.add(
|
|
|
|
|
|
|
|
newTagChip(
|
|
|
|
|
|
|
|
activity, caldavCalendars.get(task.getCaldav()), R.drawable.ic_outline_cloud_24px));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String tagString = task.getTagsString();
|
|
|
|
String tagString = task.getTagsString();
|
|
|
@ -152,7 +156,7 @@ public class ChipProvider {
|
|
|
|
chips.addAll(
|
|
|
|
chips.addAll(
|
|
|
|
transform(
|
|
|
|
transform(
|
|
|
|
orderByName.sortedCopy(filter(transform(tags, tagDatas::get), Predicates.notNull())),
|
|
|
|
orderByName.sortedCopy(filter(transform(tags, tagDatas::get), Predicates.notNull())),
|
|
|
|
tag -> newTagChip(activity, tag)));
|
|
|
|
tag -> newTagChip(activity, tag, R.drawable.ic_outline_label_24px)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
removeIf(chips, Predicates.isNull());
|
|
|
|
removeIf(chips, Predicates.isNull());
|
|
|
@ -160,68 +164,71 @@ public class ChipProvider {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void apply(Chip chip, Filter filter) {
|
|
|
|
public void apply(Chip chip, Filter filter) {
|
|
|
|
apply(chip, filter.listingTitle, filter.tint);
|
|
|
|
apply(
|
|
|
|
|
|
|
|
chip.getContext(),
|
|
|
|
|
|
|
|
chip,
|
|
|
|
|
|
|
|
getIcon(filter.icon, R.drawable.ic_outline_cloud_24px),
|
|
|
|
|
|
|
|
filter.listingTitle,
|
|
|
|
|
|
|
|
filter.tint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void apply(Chip chip, @NonNull TagData tagData) {
|
|
|
|
public void apply(Chip chip, @NonNull TagData tagData) {
|
|
|
|
apply(chip, tagData.getName(), tagData.getColor());
|
|
|
|
apply(
|
|
|
|
}
|
|
|
|
chip.getContext(),
|
|
|
|
|
|
|
|
chip,
|
|
|
|
private Chip newIconChip(Activity activity, int icon, String text, Object tag) {
|
|
|
|
getIcon(tagData.getIcon(), R.drawable.ic_outline_label_24px),
|
|
|
|
Chip chip = newChip(activity, R.layout.chip_button, tag);
|
|
|
|
tagData.getName(),
|
|
|
|
chip.setChipIconResource(icon);
|
|
|
|
tagData.getColor());
|
|
|
|
chip.setText(text);
|
|
|
|
|
|
|
|
return chip;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private @Nullable Chip newTagChip(Activity activity, Filter filter) {
|
|
|
|
private @Nullable Chip newTagChip(Activity activity, Filter filter, int defIcon) {
|
|
|
|
if (filter == null) {
|
|
|
|
if (filter == null) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Chip chip = newChip(activity, R.layout.chip_tag, filter);
|
|
|
|
Chip chip = newChip(activity, filter);
|
|
|
|
apply(chip, filter.listingTitle, filter.tint);
|
|
|
|
apply(activity, chip, getIcon(filter.icon, defIcon), filter.listingTitle, filter.tint);
|
|
|
|
return chip;
|
|
|
|
return chip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Chip newClosableChip(Activity activity, Object tag) {
|
|
|
|
public Chip newClosableChip(Activity activity, Object tag) {
|
|
|
|
Chip chip = (Chip) activity.getLayoutInflater().inflate(R.layout.chip_closable, null);
|
|
|
|
Chip chip = (Chip) activity.getLayoutInflater().inflate(R.layout.chip_closable, null);
|
|
|
|
|
|
|
|
chip.setCloseIconVisible(true);
|
|
|
|
chip.setTag(tag);
|
|
|
|
chip.setTag(tag);
|
|
|
|
return chip;
|
|
|
|
return chip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Chip newChip(Activity activity, @LayoutRes int layout, Object tag) {
|
|
|
|
private Chip newChip(Activity activity, Object tag) {
|
|
|
|
Chip chip = (Chip) activity.getLayoutInflater().inflate(layout, null);
|
|
|
|
Chip chip = (Chip) activity.getLayoutInflater().inflate(R.layout.chip_button, null);
|
|
|
|
chip.setTag(tag);
|
|
|
|
chip.setTag(tag);
|
|
|
|
return chip;
|
|
|
|
return chip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void apply(Chip chip, String name, int theme) {
|
|
|
|
private void apply(Context context, Chip chip, @Nullable @DrawableRes Integer icon, String name, int theme) {
|
|
|
|
ThemeColor color = getColor(theme);
|
|
|
|
@ColorInt int color = getColor(context, theme);
|
|
|
|
chip.setText(name);
|
|
|
|
chip.setText(name);
|
|
|
|
chip.setCloseIconTint(
|
|
|
|
ColorStateList colorStateList = new ColorStateList(new int[][]{new int[]{}}, new int[]{color});
|
|
|
|
new ColorStateList(new int[][] {new int[] {}}, new int[] {color.getColorOnPrimary()}));
|
|
|
|
chip.setCloseIconTint(colorStateList);
|
|
|
|
chip.setTextColor(color.getColorOnPrimary());
|
|
|
|
chip.setTextColor(color);
|
|
|
|
|
|
|
|
if (icon != null) {
|
|
|
|
|
|
|
|
chip.setChipIconResource(icon);
|
|
|
|
|
|
|
|
chip.setChipIconTint(colorStateList);
|
|
|
|
|
|
|
|
}
|
|
|
|
chip.getChipDrawable().setAlpha(iconAlpha);
|
|
|
|
chip.getChipDrawable().setAlpha(iconAlpha);
|
|
|
|
chip.setChipBackgroundColor(
|
|
|
|
chip.setChipStrokeColor(colorStateList);
|
|
|
|
new ColorStateList(
|
|
|
|
|
|
|
|
new int[][] {
|
|
|
|
|
|
|
|
new int[] {-android.R.attr.state_checked}, new int[] {android.R.attr.state_checked}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
new int[] {color.getPrimaryColor(), color.getPrimaryColor()}));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ThemeColor getColor(int theme) {
|
|
|
|
private @DrawableRes Integer getIcon(int index, int def) {
|
|
|
|
|
|
|
|
Integer icon = CustomIcons.getIconResId(index);
|
|
|
|
|
|
|
|
return icon != null ? icon : def;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private @ColorInt int getColor(Context context, int theme) {
|
|
|
|
if (theme != 0) {
|
|
|
|
if (theme != 0) {
|
|
|
|
ThemeColor color = newThemeColor(context, theme);
|
|
|
|
ThemeColor color = newThemeColor(context, theme);
|
|
|
|
if (color.isFree() || inventory.purchasedThemes()) {
|
|
|
|
if (color.isFree() || inventory.purchasedThemes()) {
|
|
|
|
return color;
|
|
|
|
return color.getPrimaryColor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return untagged;
|
|
|
|
return ContextCompat.getColor(context, R.color.text_secondary);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static ThemeColor getUntaggedThemeColor(Context context) {
|
|
|
|
|
|
|
|
return new ThemeColor(
|
|
|
|
|
|
|
|
context, ContextCompat.getColor(context, R.color.tag_color_none_background), false);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|