Outline chip style

pull/935/head
Alex Baker 5 years ago
parent bfe384d3fb
commit fc73f2e835

@ -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);
} }
} }

@ -2,12 +2,6 @@
<com.google.android.material.chip.Chip xmlns:android="http://schemas.android.com/apk/res/android" <com.google.android.material.chip.Chip xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/ChipStyle" style="@style/ChipStyle"
android:textColor="?android:textColorSecondary" android:textColor="@color/text_secondary"
app:chipBackgroundColor="?android:attr/colorBackground" app:chipIconTint="@color/text_secondary"
app:chipIconTint="@color/icon_tint" app:chipStrokeColor="@color/text_secondary" />
app:chipStrokeColor="?android:textColorSecondary"
app:chipStrokeWidth="@dimen/chip_stroke"
app:iconEndPadding="0dp"
app:iconStartPadding="@dimen/chip_text_padding"
app:textEndPadding="@dimen/chip_text_padding"
app:textStartPadding="@dimen/chip_text_padding" />

@ -1,3 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.chip.Chip
style="@style/ChipStyle"/>

@ -15,9 +15,10 @@
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:layout_toLeftOf="@id/clear" android:layout_toLeftOf="@id/clear"
android:layout_toStartOf="@id/clear" android:layout_toStartOf="@id/clear"
android:drawablePadding="@dimen/keyline_second"
android:contentDescription="@string/color" android:contentDescription="@string/color"
android:drawablePadding="@dimen/keyline_second"
android:text="@string/color" android:text="@string/color"
android:textColor="@color/text_primary"
android:textSize="18sp" /> android:textSize="18sp" />
</RelativeLayout> </RelativeLayout>

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/icon_row" android:id="@+id/icon_row"
style="@style/TagSettingsRow" style="@style/TagSettingsRow"
android:background="?attr/selectableItemBackground"> android:background="?attr/selectableItemBackground">
@ -11,9 +10,10 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:drawablePadding="@dimen/keyline_second"
android:contentDescription="@string/icon" android:contentDescription="@string/icon"
android:drawablePadding="@dimen/keyline_second"
android:text="@string/icon" android:text="@string/icon"
android:textColor="@color/text_primary"
android:textSize="18sp" /> android:textSize="18sp" />
</RelativeLayout> </RelativeLayout>

@ -23,14 +23,8 @@
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:textColor="?android:textColorSecondary" android:textColor="?android:textColorSecondary"
app:chipBackgroundColor="@color/window_background"
app:chipIconTint="@color/icon_tint" app:chipIconTint="@color/icon_tint"
app:chipStrokeColor="?android:textColorSecondary" app:chipStrokeColor="?android:textColorSecondary"/>
app:chipStrokeWidth="@dimen/chip_stroke"
app:iconEndPadding="0dp"
app:iconStartPadding="@dimen/chip_text_padding"
app:textEndPadding="@dimen/chip_text_padding"
app:textStartPadding="@dimen/chip_text_padding" />
<TextView <TextView
android:id="@+id/title" android:id="@+id/title"

@ -153,12 +153,15 @@
<item name="chipMinHeight">@dimen/chip_min_height</item> <item name="chipMinHeight">@dimen/chip_min_height</item>
<item name="closeIconVisible">false</item> <item name="closeIconVisible">false</item>
<item name="ensureMinTouchTargetSize">false</item> <item name="ensureMinTouchTargetSize">false</item>
<item name="chipStrokeWidth">@dimen/chip_stroke</item>
<item name="chipSurfaceColor">@android:color/transparent</item>
<item name="chipBackgroundColor">@android:color/transparent</item>
<item name="iconStartPadding">@dimen/chip_text_padding</item>
<item name="iconEndPadding">0dp</item>
</style> </style>
<style name="ChipStyle.Closable"> <style name="ChipStyle.Closable">
<item name="closeIconEndPadding">0dp</item>
<item name="closeIconVisible">true</item> <item name="closeIconVisible">true</item>
<item name="closeIconStartPadding">0dp</item>
</style> </style>
<style name="OutlineButton" parent="Widget.MaterialComponents.Button.OutlinedButton"> <style name="OutlineButton" parent="Widget.MaterialComponents.Button.OutlinedButton">

Loading…
Cancel
Save