From b8d1a2a2a90df0c7f08de51076d9f6c3a1015f67 Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Tue, 16 Jan 2024 07:58:11 +0100 Subject: [PATCH] chore(done): Support compact mode Refs: #1556 Signed-off-by: Stefan Niedermann --- .../nextcloud/deck/ui/view/DueDateChip.java | 36 ++++++++++++------- app/src/main/res/layout/item_card_compact.xml | 1 + app/src/main/res/values/attrs.xml | 3 ++ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/DueDateChip.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/DueDateChip.java index 568dfb053..88b86daf3 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/DueDateChip.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/DueDateChip.java @@ -27,24 +27,30 @@ public class DueDateChip extends Chip { - protected @ColorInt int colorOnSurface; + @ColorInt + protected final int colorOnSurface; + protected final boolean compactMode; public DueDateChip(Context context) { - super(context); - initialize(); + this(context, null); } public DueDateChip(Context context, AttributeSet attrs) { - super(context, attrs); - initialize(); + this(context, attrs, R.attr.chipStyle); } public DueDateChip(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - initialize(); - } - private void initialize() { + final var typedValue = new TypedValue(); + final var theme = getContext().getTheme(); + theme.resolveAttribute(R.attr.colorOnSurface, typedValue, true); + this.colorOnSurface = typedValue.data; + + final var styles = context.obtainStyledAttributes(attrs, R.styleable.DueDateChip, defStyleAttr, 0); + this.compactMode = styles.getBoolean(R.styleable.DueDateChip_compactMode, false); + styles.recycle(); + setEnsureMinTouchTargetSize(false); setMinHeight(0); setChipMinHeight(0); @@ -52,14 +58,18 @@ private void initialize() { setPadding(padding, padding, padding, padding); setClickable(false); - final var typedValue = new TypedValue(); - final var theme = getContext().getTheme(); - theme.resolveAttribute(R.attr.colorOnSurface, typedValue, true); - this.colorOnSurface = typedValue.data; + if (compactMode) { + setChipEndPadding(0); + setTextEndPadding(0); + } } public void setDueDate(@NonNull Instant date, boolean isDone) { - setText(DateUtil.getRelativeDateTimeString(getContext(), date.toEpochMilli())); + if (compactMode) { + setText(null); + } else { + setText(DateUtil.getRelativeDateTimeString(getContext(), date.toEpochMilli())); + } @DrawableRes final int chipIconRes; @Nullable @ColorRes final Integer textColorRes; diff --git a/app/src/main/res/layout/item_card_compact.xml b/app/src/main/res/layout/item_card_compact.xml index 16336d4d4..75d95f796 100644 --- a/app/src/main/res/layout/item_card_compact.xml +++ b/app/src/main/res/layout/item_card_compact.xml @@ -56,6 +56,7 @@ android:id="@+id/card_due_date" android:layout_width="wrap_content" android:layout_height="wrap_content" + app:compactMode="true" tools:chipIcon="@drawable/ic_time_24" tools:text="tomorrow" /> diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 715f8b814..8e70e68ea 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -8,4 +8,7 @@ + + + \ No newline at end of file