From 76bb10c40d571a72d6b4ac751fdb67a7cd60b2f7 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Tue, 2 Jul 2019 15:39:09 -0500 Subject: [PATCH] Reduce chip size --- .../todoroo/astrid/tags/TagsControlSet.java | 2 +- .../java/org/tasks/tasklist/ViewHolder.java | 79 ++++++++----------- .../main/java/org/tasks/ui/ChipProvider.java | 17 ++-- app/src/main/res/layout/chip_tag.xml | 3 + .../res/layout/control_set_remote_list.xml | 3 +- .../main/res/layout/task_adapter_row_body.xml | 6 +- app/src/main/res/values/dimens.xml | 6 ++ app/src/main/res/values/styles.xml | 17 ++++ 8 files changed, 76 insertions(+), 57 deletions(-) create mode 100644 app/src/main/res/layout/chip_tag.xml diff --git a/app/src/main/java/com/todoroo/astrid/tags/TagsControlSet.java b/app/src/main/java/com/todoroo/astrid/tags/TagsControlSet.java index f7b445fff..905154643 100644 --- a/app/src/main/java/com/todoroo/astrid/tags/TagsControlSet.java +++ b/app/src/main/java/com/todoroo/astrid/tags/TagsControlSet.java @@ -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()); diff --git a/app/src/main/java/org/tasks/tasklist/ViewHolder.java b/app/src/main/java/org/tasks/tasklist/ViewHolder.java index 6ca6c438b..684ed4e33 100644 --- a/app/src/main/java/org/tasks/tasklist/ViewHolder.java +++ b/app/src/main/java/org/tasks/tasklist/ViewHolder.java @@ -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 tagUuids = tags != null ? newArrayList(tags.split(",")) : Lists.newArrayList(); - - List 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 tagUuids = tags != null ? newArrayList(tags.split(",")) : Lists.newArrayList(); + + List 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() { diff --git a/app/src/main/java/org/tasks/ui/ChipProvider.java b/app/src/main/java/org/tasks/ui/ChipProvider.java index af8f63995..d4231c12b 100644 --- a/app/src/main/java/org/tasks/ui/ChipProvider.java +++ b/app/src/main/java/org/tasks/ui/ChipProvider.java @@ -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 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); diff --git a/app/src/main/res/layout/chip_tag.xml b/app/src/main/res/layout/chip_tag.xml new file mode 100644 index 000000000..052dc91c9 --- /dev/null +++ b/app/src/main/res/layout/chip_tag.xml @@ -0,0 +1,3 @@ + + diff --git a/app/src/main/res/layout/control_set_remote_list.xml b/app/src/main/res/layout/control_set_remote_list.xml index e07c3ee04..836803458 100644 --- a/app/src/main/res/layout/control_set_remote_list.xml +++ b/app/src/main/res/layout/control_set_remote_list.xml @@ -19,8 +19,7 @@ diff --git a/app/src/main/res/layout/task_adapter_row_body.xml b/app/src/main/res/layout/task_adapter_row_body.xml index c9d155ec6..1fea34f7b 100644 --- a/app/src/main/res/layout/task_adapter_row_body.xml +++ b/app/src/main/res/layout/task_adapter_row_body.xml @@ -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"/> \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 9eb24b48b..b7b6698c9 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -37,6 +37,12 @@ 8dp 1px + 4dp + 4dp + 1dp + 18dp + 26dp + 4dp \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index a843a8d92..442b8583f 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -146,4 +146,21 @@ @android:color/transparent + +