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