From 4b63e1a652e3e3c6ad7db9fb81f10b0dc9b1d5d7 Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Sun, 21 Jan 2024 15:07:02 +0100 Subject: feat(theming): Enhance theming Signed-off-by: Stefan Niedermann --- .../deck/ui/card/AbstractCardViewHolder.java | 24 ++++++++++++++-------- .../deck/ui/card/DefaultCardViewHolder.java | 9 +++++++- .../ui/card/attachments/AttachmentViewHolder.java | 19 +++++++++-------- .../attachments/DefaultAttachmentViewHolder.java | 16 +++++++++++++++ .../deck/ui/theme/DeckViewThemeUtils.java | 9 ++++++++ .../main/res/layout/item_attachment_default.xml | 7 ++++++- 6 files changed, 65 insertions(+), 19 deletions(-) (limited to 'app') diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/AbstractCardViewHolder.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/AbstractCardViewHolder.java index 193fc7a2c..ebaeaf637 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/AbstractCardViewHolder.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/AbstractCardViewHolder.java @@ -55,17 +55,10 @@ public abstract class AbstractCardViewHolder extends RecyclerView.ViewHolder { getCardMenu().setVisibility(hasEditPermission ? View.VISIBLE : View.GONE); getCardTitle().setText(fullCard.getCard().getTitle().trim()); - - if (utils != null) { - utils.platform.colorImageView(getNotSyncedYet(), ColorRole.PRIMARY); - utils.platform.colorImageView(getCardMenu(), ColorRole.ON_SURFACE); - utils.platform.colorTextView(getCardTitle(), ColorRole.ON_SURFACE); - } - // TODO should be discussed with UX - // utils.material.themeCardView(getCard()); - getNotSyncedYet().setVisibility(DBStatus.LOCAL_EDITED.equals(fullCard.getStatusEnum()) ? View.VISIBLE : View.GONE); + applyTheme(utils); + if (fullCard.getCard().getDueDate() != null || fullCard.getCard().getDone() != null) { setupDueDate(getCardDueDate(), fullCard.getCard()); getCardDueDate().setVisibility(View.VISIBLE); @@ -91,6 +84,19 @@ public abstract class AbstractCardViewHolder extends RecyclerView.ViewHolder { }); } + @CallSuper + protected void applyTheme(@Nullable ThemeUtils utils) { + if (utils != null) { + utils.platform.colorImageView(getNotSyncedYet(), ColorRole.PRIMARY); + utils.platform.colorImageView(getCardMenu(), ColorRole.ON_SURFACE); + utils.platform.colorTextView(getCardTitle(), ColorRole.ON_SURFACE); + + // TODO should be discussed with UX + // utils.material.themeCardView(getCard()); + } + + } + protected abstract DueDateChip getCardDueDate(); protected abstract ImageView getNotSyncedYet(); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/DefaultCardViewHolder.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/DefaultCardViewHolder.java index 20ce6dd1d..97144ad44 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/DefaultCardViewHolder.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/DefaultCardViewHolder.java @@ -95,13 +95,20 @@ public class DefaultCardViewHolder extends AbstractCardViewHolder { } } + + } + + @Override + protected void applyTheme(@Nullable ThemeUtils utils) { + super.applyTheme(utils); if (utils != null) { Stream.of( binding.cardCountAttachments, binding.cardCountTasks, binding.cardCountComments ).forEach(v -> { - utils.platform.colorTextView(v, ColorRole.ON_SURFACE_VARIANT ); + utils.deck.colorTextViewCompoundDrawables(v); + utils.platform.colorTextView(v, ColorRole.ON_SURFACE_VARIANT); }); } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/AttachmentViewHolder.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/AttachmentViewHolder.java index 977035940..85c84dc00 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/AttachmentViewHolder.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/AttachmentViewHolder.java @@ -4,6 +4,7 @@ import android.view.MenuInflater; import android.view.View; import android.widget.ImageView; +import androidx.annotation.CallSuper; import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -31,7 +32,8 @@ public abstract class AttachmentViewHolder extends RecyclerView.ViewHolder { ? attachment.getLocalPath() : AttachmentUtil.getCopyDownloadUrl(account, cardRemoteId, attachment); - setNotSyncedYetStatus(!DBStatus.LOCAL_EDITED.equals(attachment.getStatusEnum()), color); + final var synced = !DBStatus.LOCAL_EDITED.equals(attachment.getStatusEnum()); + getNotSyncedYetStatusIcon().setVisibility(synced ? View.GONE : View.VISIBLE); itemView.setOnCreateContextMenuListener((menu, v, menuInfo) -> { menuInflater.inflate(R.menu.attachment_menu, menu); if (EAttachmentType.DECK_FILE.equals(attachment.getType())) { @@ -50,17 +52,18 @@ public abstract class AttachmentViewHolder extends RecyclerView.ViewHolder { menu.findItem(android.R.id.copyUrl).setOnMenuItemClickListener(item -> ClipboardUtil.copyToClipboard(itemView.getContext(), attachment.getFilename(), attachmentUri)); } }); - } - abstract protected ImageView getPreview(); + applyTheme(color); + } - protected void setNotSyncedYetStatus(boolean synced, @ColorInt int color) { - final var notSyncedYet = getNotSyncedYetStatusIcon(); - final var utils = ThemeUtils.of(color, notSyncedYet.getContext()); + @CallSuper + protected void applyTheme(@ColorInt int color) { + final var utils = ThemeUtils.of(color, getPreview().getContext()); - utils.platform.colorImageView(notSyncedYet, ColorRole.PRIMARY); - notSyncedYet.setVisibility(synced ? View.GONE : View.VISIBLE); + utils.platform.colorImageView(getNotSyncedYetStatusIcon(), ColorRole.PRIMARY); } + abstract protected ImageView getPreview(); + abstract protected ImageView getNotSyncedYetStatusIcon(); } \ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/DefaultAttachmentViewHolder.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/DefaultAttachmentViewHolder.java index 505fdf335..544aead89 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/DefaultAttachmentViewHolder.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/DefaultAttachmentViewHolder.java @@ -13,9 +13,12 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.FragmentManager; +import com.nextcloud.android.common.ui.theme.utils.ColorRole; + import it.niedermann.nextcloud.deck.databinding.ItemAttachmentDefaultBinding; import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.Attachment; +import it.niedermann.nextcloud.deck.ui.theme.ThemeUtils; import it.niedermann.nextcloud.deck.util.DateUtil; public class DefaultAttachmentViewHolder extends AttachmentViewHolder { @@ -52,5 +55,18 @@ public class DefaultAttachmentViewHolder extends AttachmentViewHolder { } else { binding.modified.setVisibility(View.GONE); } + + applyTheme(color); + } + + protected void applyTheme(@ColorInt int color) { + super.applyTheme(color); + + final var utils = ThemeUtils.of(color, getPreview().getContext()); + + utils.platform.colorTextView(binding.filename, ColorRole.ON_SURFACE); + utils.platform.colorImageView(getPreview(), ColorRole.ON_SURFACE_VARIANT); + utils.platform.colorTextView(binding.filesize, ColorRole.ON_SURFACE_VARIANT); + utils.platform.colorTextView(binding.modified, ColorRole.ON_SURFACE_VARIANT); } } \ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/theme/DeckViewThemeUtils.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/theme/DeckViewThemeUtils.java index d52b78f96..d2dff1ae4 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/theme/DeckViewThemeUtils.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/theme/DeckViewThemeUtils.java @@ -10,6 +10,7 @@ import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.StateListDrawable; import android.os.Build; import android.widget.ImageView; +import android.widget.TextView; import androidx.annotation.AttrRes; import androidx.annotation.ColorInt; @@ -21,6 +22,7 @@ import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; import androidx.core.content.res.ResourcesCompat; import androidx.core.graphics.drawable.DrawableCompat; +import androidx.core.widget.TextViewCompat; import com.google.android.material.search.SearchBar; import com.google.android.material.search.SearchView; @@ -102,6 +104,13 @@ public class DeckViewThemeUtils extends ViewThemeUtilsBase { }); } + public void colorTextViewCompoundDrawables(@NonNull TextView textView) { + withScheme(textView.getContext(), scheme -> { + TextViewCompat.setCompoundDrawableTintList(textView, ColorStateList.valueOf(scheme.getOnSurfaceVariant())); + return textView; + }); + } + public Drawable themeNavigationViewIcon(@NonNull Context context, @DrawableRes int icon) { return withScheme(context, scheme -> { final var colorStateList = buildColorStateList( diff --git a/app/src/main/res/layout/item_attachment_default.xml b/app/src/main/res/layout/item_attachment_default.xml index 88e2126cd..9d5781c3e 100644 --- a/app/src/main/res/layout/item_attachment_default.xml +++ b/app/src/main/res/layout/item_attachment_default.xml @@ -20,7 +20,8 @@ android:layout_gravity="center" android:contentDescription="@null" android:padding="@dimen/spacer_1hx" - app:srcCompat="@drawable/ic_attach_file_grey600_24dp" /> + app:srcCompat="@drawable/ic_attach_file_grey600_24dp" + app:tint="?attr/colorSecondary" /> @@ -41,6 +43,7 @@ android:layout_marginEnd="@dimen/spacer_1x" android:layout_weight="1" android:textAppearance="?attr/textAppearanceListItem" + android:textColor="?attr/colorOnSurface" tools:maxLength="30" tools:text="@tools:sample/lorem/random" /> @@ -56,6 +59,7 @@ android:layout_height="wrap_content" android:layout_gravity="end" android:textAppearance="?attr/textAppearanceListItemSecondary" + android:textColor="?attr/colorOnSurfaceVariant" tools:text="1.98 MB" /> \ No newline at end of file -- cgit v1.2.3