|
2 | 2 |
|
3 | 3 | import static android.view.View.INVISIBLE; |
4 | 4 | import static android.view.View.VISIBLE; |
5 | | -import static it.niedermann.owncloud.notes.shared.util.NotesColorUtil.contrastRatioIsSufficient; |
| 5 | + |
| 6 | +import static com.nextcloud.android.common.ui.util.PlatformThemeUtil.isDarkMode; |
6 | 7 |
|
7 | 8 | import android.content.Context; |
8 | | -import android.content.res.ColorStateList; |
9 | | -import android.graphics.Color; |
10 | 9 | import android.text.SpannableString; |
11 | 10 | import android.text.TextUtils; |
12 | 11 | import android.text.style.BackgroundColorSpan; |
|
26 | 25 | import androidx.recyclerview.widget.RecyclerView; |
27 | 26 |
|
28 | 27 | import com.google.android.material.chip.Chip; |
| 28 | +import com.nextcloud.android.common.ui.theme.utils.ColorRole; |
| 29 | +import com.nextcloud.android.common.ui.util.PlatformThemeUtil; |
29 | 30 |
|
30 | 31 | import java.util.regex.Matcher; |
31 | 32 | import java.util.regex.Pattern; |
32 | 33 |
|
33 | | -import it.niedermann.android.util.ColorUtil; |
34 | | -import it.niedermann.owncloud.notes.NotesApplication; |
35 | 34 | import it.niedermann.owncloud.notes.R; |
36 | 35 | import it.niedermann.owncloud.notes.branding.BrandingUtil; |
37 | 36 | import it.niedermann.owncloud.notes.persistence.entity.Note; |
@@ -60,47 +59,26 @@ protected void bindStatus(AppCompatImageView noteStatus, DBStatus status, int ma |
60 | 59 | DrawableCompat.setTint(noteStatus.getDrawable(), BrandingUtil.of(mainColor, context).notes.getOnPrimaryContainer(context)); |
61 | 60 | } |
62 | 61 |
|
63 | | - protected void bindCategory(@NonNull Context context, @NonNull TextView noteCategory, boolean showCategory, @NonNull String category, int mainColor) { |
64 | | - final boolean isDarkThemeActive = NotesApplication.isDarkThemeActive(context); |
65 | | - noteCategory.setVisibility(showCategory && !category.isEmpty() ? View.VISIBLE : View.GONE); |
66 | | - noteCategory.setText(category); |
| 62 | + protected void bindCategory(@NonNull Context context, @NonNull TextView noteCategory, boolean showCategory, @NonNull String category, int color) { |
| 63 | + if (!showCategory || category.isEmpty()) { |
| 64 | + noteCategory.setVisibility(View.GONE); |
| 65 | + } else { |
| 66 | + noteCategory.setText(category); |
67 | 67 |
|
68 | | - @ColorInt final int categoryForeground; |
69 | | - @ColorInt final int categoryBackground; |
| 68 | + final var util = BrandingUtil.of(color, context); |
70 | 69 |
|
71 | | - if (isDarkThemeActive) { |
72 | | - if (ColorUtil.INSTANCE.isColorDark(mainColor)) { |
73 | | - if (contrastRatioIsSufficient(mainColor, Color.BLACK)) { |
74 | | - categoryBackground = mainColor; |
75 | | - categoryForeground = Color.WHITE; |
| 70 | + if (noteCategory instanceof Chip) { |
| 71 | + util.material.colorChipBackground((Chip) noteCategory); |
| 72 | + } else { |
| 73 | + util.platform.tintDrawable(context, noteCategory.getBackground(), ColorRole.PRIMARY); |
| 74 | + if (isDarkMode(context)) { |
| 75 | + util.platform.colorTextView(noteCategory, ColorRole.ON_PRIMARY); |
76 | 76 | } else { |
77 | | - categoryBackground = Color.WHITE; |
78 | | - categoryForeground = mainColor; |
| 77 | + util.platform.colorTextView(noteCategory, ColorRole.ON_SECONDARY_CONTAINER); |
79 | 78 | } |
80 | | - } else { |
81 | | - categoryBackground = mainColor; |
82 | | - categoryForeground = Color.BLACK; |
83 | 79 | } |
84 | | - } else { |
85 | | - categoryForeground = Color.BLACK; |
86 | | - if (ColorUtil.INSTANCE.isColorDark(mainColor) || contrastRatioIsSufficient(mainColor, Color.WHITE)) { |
87 | | - categoryBackground = mainColor; |
88 | | - } else { |
89 | | - categoryBackground = Color.BLACK; |
90 | | - } |
91 | | - } |
92 | 80 |
|
93 | | - noteCategory.setTextColor(categoryForeground); |
94 | | - if (noteCategory instanceof Chip) { |
95 | | - final Chip chip = (Chip) noteCategory; |
96 | | - chip.setChipStrokeColor(ColorStateList.valueOf(categoryBackground)); |
97 | | - if(isDarkThemeActive) { |
98 | | - chip.setChipBackgroundColor(ColorStateList.valueOf(categoryBackground)); |
99 | | - } else { |
100 | | - chip.setChipBackgroundColorResource(R.color.grid_item_background_selector); |
101 | | - } |
102 | | - } else { |
103 | | - DrawableCompat.setTint(noteCategory.getBackground(), categoryBackground); |
| 81 | + noteCategory.setVisibility(View.VISIBLE); |
104 | 82 | } |
105 | 83 | } |
106 | 84 |
|
|
0 commit comments