Reduce chip size

pull/848/head
Alex Baker 5 years ago
parent 2ab23e39b3
commit 76bb10c40d

@ -355,7 +355,7 @@ public final class TagsControlSet extends TaskEditControlFragment {
chipGroup.setVisibility(View.VISIBLE);
chipGroup.removeAllViews();
for (TagData tagData : orderByName.sortedCopy(selectedTags)) {
Chip chip = new Chip(getActivity());
Chip chip = chipProvider.newChip(getActivity(), tagData);
chipProvider.apply(chip, tagData);
chip.setCloseIconVisible(true);
chip.setOnClickListener(view -> onClickRow());

@ -49,7 +49,6 @@ public class ViewHolder extends RecyclerView.ViewHolder {
private final Linkify linkify;
private final int textColorOverdue;
private final ChipProvider chipProvider;
private final int fontSizeDetails;
@BindView(R.id.row)
public ViewGroup row;
@ -137,7 +136,7 @@ public class ViewHolder extends RecyclerView.ViewHolder {
nameView.setTextSize(fontSize);
description.setTextSize(fontSize);
fontSizeDetails = Math.max(10, fontSize - 2);
int fontSizeDetails = Math.max(10, fontSize - 2);
dueDate.setTextSize(fontSizeDetails);
if (atLeastJellybeanMR1()) {
@ -202,8 +201,13 @@ public class ViewHolder extends RecyclerView.ViewHolder {
this.task = task;
this.isGoogleTaskList = isGoogleTaskList;
setFieldContentsAndVisibility();
setTaskAppearance();
nameView.setText(task.getTitle());
hidden.setVisibility(task.isHidden() ? View.VISIBLE : View.GONE);
setupTitleAndCheckbox();
setupDueDate();
if (preferences.getBoolean(R.string.p_show_list_indicators, true)) {
setupTags();
}
if (preferences.getBoolean(R.string.p_show_description, true)) {
description.setText(task.getNotes());
description.setVisibility(task.hasNotes() ? View.VISIBLE : View.GONE);
@ -218,14 +222,7 @@ public class ViewHolder extends RecyclerView.ViewHolder {
}
}
/** Helper method to set the contents and visibility of each field */
private synchronized void setFieldContentsAndVisibility() {
nameView.setText(task.getTitle());
hidden.setVisibility(task.isHidden() ? View.VISIBLE : View.GONE);
setupDueDateAndTags();
}
private void setTaskAppearance() {
private void setupTitleAndCheckbox() {
if (task.isCompleted()) {
nameView.setTextColor(textColorSecondary);
nameView.setPaintFlags(nameView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
@ -235,21 +232,12 @@ public class ViewHolder extends RecyclerView.ViewHolder {
nameView.setPaintFlags(nameView.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
}
setupDueDateAndTags();
setupCompleteBox();
}
private void setupCompleteBox() {
// complete box
final CheckableImageView checkBoxView = completeBox;
checkBoxView.setChecked(task.isCompleted());
checkBoxView.setImageDrawable(CheckBoxes.getCheckBox(context, task.getTask()));
checkBoxView.invalidate();
completeBox.setChecked(task.isCompleted());
completeBox.setImageDrawable(CheckBoxes.getCheckBox(context, task.getTask()));
completeBox.invalidate();
}
private void setupDueDateAndTags() {
// due date / completion date
private void setupDueDate() {
if (task.hasDueDate()) {
if (task.isOverdue()) {
dueDate.setTextColor(textColorOverdue);
@ -262,28 +250,27 @@ public class ViewHolder extends RecyclerView.ViewHolder {
} else {
dueDate.setVisibility(View.GONE);
}
}
if (preferences.getBoolean(R.string.p_show_list_indicators, true)) {
String tags = task.getTagsString();
List<String> tagUuids = tags != null ? newArrayList(tags.split(",")) : Lists.newArrayList();
List<Chip> chips =
chipProvider.getChips(
context,
task.getCaldav(),
isGoogleTaskList ? null : task.getGoogleTaskList(),
tagUuids);
if (chips.isEmpty()) {
chipGroup.setVisibility(View.GONE);
} else {
chipGroup.removeAllViews();
for (Chip chip : chips) {
chip.setTextSize(fontSizeDetails);
chip.setOnClickListener(view -> callback.onClick((Filter) view.getTag()));
chipGroup.addView(chip);
}
chipGroup.setVisibility(View.VISIBLE);
private void setupTags() {
String tags = task.getTagsString();
List<String> tagUuids = tags != null ? newArrayList(tags.split(",")) : Lists.newArrayList();
List<Chip> chips =
chipProvider.getChips(
context,
task.getCaldav(),
isGoogleTaskList ? null : task.getGoogleTaskList(),
tagUuids);
if (chips.isEmpty()) {
chipGroup.setVisibility(View.GONE);
} else {
chipGroup.removeAllViews();
for (Chip chip : chips) {
chip.setOnClickListener(view -> callback.onClick((Filter) view.getTag()));
chipGroup.addView(chip);
}
chipGroup.setVisibility(View.VISIBLE);
}
}
@ -311,7 +298,7 @@ public class ViewHolder extends RecyclerView.ViewHolder {
}
// set check box to actual action item state
setTaskAppearance();
setupTitleAndCheckbox();
}
public int getIndent() {

@ -100,18 +100,18 @@ public class ChipProvider {
if (!Strings.isNullOrEmpty(googleTask)) {
GtasksFilter googleTaskFilter = googleTaskLists.get(googleTask);
if (googleTaskFilter != null) {
chips.add(newChip(activity, googleTaskFilter));
chips.add(newTagChip(activity, googleTaskFilter));
}
} else if (!Strings.isNullOrEmpty(caldav)) {
CaldavFilter caldavFilter = caldavCalendars.get(caldav);
if (caldavFilter != null) {
chips.add(newChip(activity, caldavFilter));
chips.add(newTagChip(activity, caldavFilter));
}
}
Iterable<TagFilter> tagFilters =
filter(transform(tagUuids, tagDatas::get), Predicates.notNull());
for (TagFilter tagFilter : orderByName.sortedCopy(tagFilters)) {
chips.add(newChip(activity, tagFilter));
chips.add(newTagChip(activity, tagFilter));
}
return chips;
@ -125,13 +125,18 @@ public class ChipProvider {
apply(chip, tagData.getName(), tagData.getColor());
}
private Chip newChip(Activity activity, Filter filter) {
Chip chip = new Chip(activity);
chip.setTag(filter);
private Chip newTagChip(Activity activity, Filter filter) {
Chip chip = newChip(activity, filter);
apply(chip, filter.listingTitle, filter.tint);
return chip;
}
public Chip newChip(Activity activity, Object tag) {
Chip chip = (Chip) activity.getLayoutInflater().inflate(R.layout.chip_tag, null);
chip.setTag(tag);
return chip;
}
private void apply(Chip chip, String name, int theme) {
ThemeColor color = theme >= 0 ? themeCache.getThemeColor(theme) : themeCache.getUntaggedColor();
chip.setText(name);

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

@ -19,8 +19,7 @@
<com.google.android.material.chip.Chip
android:id="@+id/chip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/ChipStyle"
android:visibility="gone"
app:closeIconEnabled="true"/>
</LinearLayout>

@ -80,6 +80,7 @@
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/task_list_item_spacing"
android:paddingStart="@dimen/keyline_content_inset"
android:paddingEnd="@dimen/keyline_first"
android:paddingLeft="@dimen/keyline_content_inset"
@ -93,13 +94,14 @@
android:id="@+id/chip_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/task_list_item_spacing"
android:layout_marginStart="@dimen/keyline_first"
android:layout_marginEnd="@dimen/keyline_content_inset"
android:layout_marginLeft="@dimen/keyline_first"
android:layout_marginRight="@dimen/keyline_content_inset"
android:layout_gravity="end"
android:visibility="gone"
app:chipSpacingVertical="@dimen/chip_spacing"
app:chipSpacingHorizontal="@dimen/chip_spacing"/>
app:chipSpacingHorizontal="@dimen/chip_spacing"
app:chipSpacingVertical="@dimen/chip_spacing"/>
</LinearLayout>

@ -37,6 +37,12 @@
<dimen name="header_gap">8dp</dimen>
<dimen name="row_gap">1px</dimen>
<dimen name="task_list_item_spacing">4dp</dimen>
<dimen name="chip_spacing">4dp</dimen>
<dimen name="chip_stroke">1dp</dimen>
<dimen name="chip_icon_size">18dp</dimen>
<dimen name="chip_min_height">26dp</dimen>
<dimen name="chip_text_padding">4dp</dimen>
</resources>

@ -146,4 +146,21 @@
<item name="lpd_strokeSecondaryColor">@android:color/transparent</item>
</style>
<style name="ChipStyle" parent="Base.Widget.MaterialComponents.Chip">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:maxLines">1</item>
<item name="android:ellipsize">end</item>
<item name="closeIconSize">@dimen/chip_icon_size</item>
<item name="chipIconSize">@dimen/chip_icon_size</item>
<item name="closeIcon">@drawable/ic_outline_clear_24px</item>
<item name="closeIconStartPadding">0dp</item>
<item name="closeIconEndPadding">@dimen/chip_text_padding</item>
<item name="android:textAppearance">@style/TextAppearance.AppCompat.Small</item>
<item name="chipMinHeight">@dimen/chip_min_height</item>
<item name="closeIconVisible">false</item>
<item name="textStartPadding">@dimen/chip_text_padding</item>
<item name="textEndPadding">@dimen/chip_text_padding</item>
</style>
</resources>

Loading…
Cancel
Save