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.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(
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),
task));
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());
}
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;
apply(
chip.getContext(),
chip,
getIcon(tagData.getIcon(), R.drawable.ic_outline_label_24px),
tagData.getName(),
tagData.getColor());
}
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);
}
}

@ -2,12 +2,6 @@
<com.google.android.material.chip.Chip xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/ChipStyle"
android:textColor="?android:textColorSecondary"
app:chipBackgroundColor="?android:attr/colorBackground"
app:chipIconTint="@color/icon_tint"
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" />
android:textColor="@color/text_secondary"
app:chipIconTint="@color/text_secondary"
app:chipStrokeColor="@color/text_secondary" />

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

@ -14,10 +14,10 @@
android:layout_gravity="top"
android:gravity="start"
android:hint="@string/dont_sync"
android:textAlignment="viewStart"/>
android:textAlignment="viewStart" />
<com.google.android.material.chip.Chip
android:id="@+id/chip"
style="@style/ChipStyle.Closable"
android:visibility="gone"/>
android:visibility="gone" />
</LinearLayout>

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

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

@ -23,14 +23,8 @@
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:textColor="?android:textColorSecondary"
app:chipBackgroundColor="@color/window_background"
app:chipIconTint="@color/icon_tint"
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" />
app:chipStrokeColor="?android:textColorSecondary"/>
<TextView
android:id="@+id/title"

@ -153,12 +153,15 @@
<item name="chipMinHeight">@dimen/chip_min_height</item>
<item name="closeIconVisible">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 name="ChipStyle.Closable">
<item name="closeIconEndPadding">0dp</item>
<item name="closeIconVisible">true</item>
<item name="closeIconStartPadding">0dp</item>
</style>
<style name="OutlineButton" parent="Widget.MaterialComponents.Button.OutlinedButton">

Loading…
Cancel
Save