Skip to content

Commit

Permalink
Fully replace custom color roles with attributes and implement dynami…
Browse files Browse the repository at this point in the history
…c contrast for custom colors
  • Loading branch information
patzly committed Dec 27, 2023
1 parent cff3fab commit 05911b9
Show file tree
Hide file tree
Showing 28 changed files with 478 additions and 749 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,13 @@ public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int positionD
ResourcesCompat.getFont(context, R.font.jost_medium)
);

ColorRoles colorBlue = ResUtil.getHarmonizedRoles(context, R.color.blue);
ColorRoles colorYellow = ResUtil.getHarmonizedRoles(context, R.color.yellow);
int color;
if (days < 0) {
color = ResUtil.getColorAttr(context, R.attr.colorError);
} else if (days == 0) {
color = colorBlue.getAccent();
color = ResUtil.getColorAttr(context, R.attr.colorCustomBlue);
} else {
color = colorYellow.getAccent();
color = ResUtil.getColorAttr(context, R.attr.colorCustomYellow);
}
holder.binding.days.setTextColor(color);
holder.binding.daysHuman.setTextColor(color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int positionD
binding.timelineView.setPosition(entry.getItemPosition());

Context context = binding.getRoot().getContext();
ColorRoles colorBlue = ResUtil.getHarmonizedRoles(context, R.color.blue);

binding.title.setText(entry.getType());
binding.picture.setVisibility(View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ public class RecipePositionAdapter extends

private final PluralUtil pluralUtil;
private final int maxDecimalPlacesAmount;
private final ColorRoles colorGreen;
private final ColorRoles colorYellow;
private final int colorRed;
private final int colorGreen, colorYellow, colorRed;

public RecipePositionAdapter(
Context context,
Expand Down Expand Up @@ -110,8 +108,8 @@ public RecipePositionAdapter(
this.listener = listener;
this.pluralUtil = new PluralUtil(context);

colorGreen = ResUtil.getHarmonizedRoles(context, R.color.green);
colorYellow = ResUtil.getHarmonizedRoles(context, R.color.yellow);
colorGreen = ResUtil.getColorAttr(context, R.attr.colorCustomGreen);
colorYellow = ResUtil.getColorAttr(context, R.attr.colorCustomYellow);
colorRed = ResUtil.getColorAttr(context, R.attr.colorError);
}

Expand Down Expand Up @@ -262,9 +260,7 @@ public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int positionD
R.drawable.ic_round_check_circle_outline,
null
));
holder.binding.imageFulfillment.setImageTintList(
ColorStateList.valueOf(colorGreen.getAccent())
);
holder.binding.imageFulfillment.setImageTintList(ColorStateList.valueOf(colorGreen));
holder.binding.missing.setVisibility(View.GONE);
} else {
holder.binding.fulfilled.setText(R.string.msg_recipes_not_enough);
Expand All @@ -276,9 +272,7 @@ public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int positionD
null
));
holder.binding.imageFulfillment.setImageTintList(
ColorStateList.valueOf(
amountShoppingList >= amountMissing ? colorYellow.getAccent() : colorRed
)
ColorStateList.valueOf(amountShoppingList >= amountMissing ? colorYellow : colorRed)
);
holder.binding.missing.setText(
context.getString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ public class RecipePositionResolvedAdapter extends
private final PluralUtil pluralUtil;
private final int maxDecimalPlacesAmount;
private final int maxDecimalPlacesPrice;
private final ColorRoles colorGreen;
private final ColorRoles colorYellow;
private final int colorRed;
private final int colorGreen, colorYellow, colorRed;
private final String energyUnit;
private final String currency;

Expand Down Expand Up @@ -119,8 +117,8 @@ public RecipePositionResolvedAdapter(
this.listener = listener;
this.pluralUtil = new PluralUtil(context);

colorGreen = ResUtil.getHarmonizedRoles(context, R.color.green);
colorYellow = ResUtil.getHarmonizedRoles(context, R.color.yellow);
colorGreen = ResUtil.getColorAttr(context, R.attr.colorCustomGreen);
colorYellow = ResUtil.getColorAttr(context, R.attr.colorCustomYellow);
colorRed = ResUtil.getColorAttr(context, R.attr.colorError);
}

Expand Down Expand Up @@ -329,9 +327,7 @@ public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int positionD
R.drawable.ic_round_check_circle_outline,
null
));
holder.binding.imageFulfillment.setImageTintList(
ColorStateList.valueOf(colorGreen.getAccent())
);
holder.binding.imageFulfillment.setImageTintList(ColorStateList.valueOf(colorGreen));
holder.binding.missing.setVisibility(View.GONE);
} else {
double amountMissing = conversion != null
Expand All @@ -350,9 +346,7 @@ public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int positionD
null
));
holder.binding.imageFulfillment.setImageTintList(
ColorStateList.valueOf(
amountShoppingList >= amountMissing ? colorYellow.getAccent() : colorRed
)
ColorStateList.valueOf(amountShoppingList >= amountMissing ? colorYellow : colorRed)
);
holder.binding.missing.setText(
context.getString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,6 @@ public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int positionD
RowShoppingListItemBinding binding = ((ShoppingListItemViewHolder) viewHolder).binding;

Context context = binding.getRoot().getContext();
ColorRoles colorBlue = ResUtil.getHarmonizedRoles(context, R.color.blue);

// NAME

Expand Down Expand Up @@ -472,8 +471,10 @@ public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int positionD
}
Chip chipAmount = createChip(context, stringBuilderAmount.toString());
if (item.hasProduct() && missingProductIds.contains(item.getProductIdInt())) {
chipAmount.setTextColor(colorBlue.getOnAccentContainer());
chipAmount.setChipBackgroundColor(ColorStateList.valueOf(colorBlue.getAccentContainer()));
chipAmount.setTextColor(ResUtil.getColorAttr(context, R.attr.colorOnCustomBlueContainer));
chipAmount.setChipBackgroundColor(ColorStateList.valueOf(
ResUtil.getColorAttr(context, R.attr.colorCustomBlueContainer)
));
}
if (item.isUndone()) {
chipAmount.setPaintFlags(chipAmount.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,6 @@ public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int positionD
ShoppingListItem item = (ShoppingListItem) groupedListItem;
RowShoppingModeItemBinding binding = ((ShoppingItemViewHolder) viewHolder).binding;

ColorRoles colorBlue = ResUtil.getHarmonizedRoles(context, R.color.blue);

if (useSmallerFonts) {
int dp8 = UiUtil.dpToPx(binding.name.getContext(), 8);
binding.card.setContentPadding(dp8, 0, dp8, 0);
Expand Down Expand Up @@ -439,8 +437,10 @@ public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int positionD
}
Chip chipAmount = createChip(context, stringBuilderAmount.toString());
if (item.hasProduct() && missingProductIds.contains(item.getProductIdInt())) {
chipAmount.setTextColor(colorBlue.getOnAccentContainer());
chipAmount.setChipBackgroundColor(ColorStateList.valueOf(colorBlue.getAccentContainer()));
chipAmount.setTextColor(ResUtil.getColorAttr(context, R.attr.colorOnCustomBlueContainer));
chipAmount.setChipBackgroundColor(ColorStateList.valueOf(
ResUtil.getColorAttr(context, R.attr.colorCustomBlueContainer)
));
}
if (item.isUndone()) {
chipAmount.setPaintFlags(chipAmount.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,16 +328,13 @@ public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int positionD
ResourcesCompat.getFont(context, R.font.jost_medium)
);

ColorRoles colorYellow = ResUtil.getHarmonizedRoles(context, R.color.yellow);
ColorRoles colorOrange = ResUtil.getHarmonizedRoles(context, R.color.orange);

int color;
if (Integer.parseInt(days) >= 0) {
color = colorYellow.getAccent();
color = ResUtil.getColorAttr(context, R.attr.colorCustomYellow);
} else if (product != null && product.getDueDateTypeInt() == StockItem.DUE_TYPE_EXPIRATION) {
color = ResUtil.getColorAttr(context, R.attr.colorError);
} else {
color = colorOrange.getAccent(); // formally DIRT
color = ResUtil.getColorAttr(context, R.attr.colorCustomOrange);
}
holder.binding.dueDate.setTextColor(color);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,6 @@ public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int positionD

Context context = holder.binding.getRoot().getContext();

ColorRoles colorBlue = ResUtil.getHarmonizedRoles(context, R.color.blue);
ColorRoles colorYellow = ResUtil.getHarmonizedRoles(context, R.color.yellow);
ColorRoles colorOrange = ResUtil.getHarmonizedRoles(context, R.color.orange);

holder.binding.flexboxLayout.removeAllViews();

// NAME
Expand All @@ -365,7 +361,7 @@ public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int positionD
&& shoppingListFeatureEnabled) {
holder.binding.viewOnShoppingList.setVisibility(View.VISIBLE);
holder.binding.viewOnShoppingList.setBackgroundTintList(
ColorStateList.valueOf(colorBlue.getAccent())
ColorStateList.valueOf(ResUtil.getColorAttr(context, R.attr.colorCustomBlue))
);
} else {
holder.binding.viewOnShoppingList.setVisibility(View.GONE);
Expand All @@ -378,14 +374,16 @@ public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int positionD
);

if (activeFields.contains(StockOverviewViewModel.FIELD_AMOUNT)) {
int colorBlueContainer = ResUtil.getColorAttr(context, R.attr.colorCustomBlueContainer);
int colorOnBlueContainer = ResUtil.getColorAttr(context, R.attr.colorOnCustomBlueContainer);
StringBuilder stringBuilderAmount = new StringBuilder();
if (!stockItem.getProduct().getNoOwnStockBoolean()) {
AmountUtil.addStockAmountNormalInfo(context, pluralUtil, stringBuilderAmount, stockItem,
quantityUnitStock, maxDecimalPlacesAmount);
Chip chipAmount = createChip(context, stringBuilderAmount.toString());
if (missingItemsProductIds.contains(stockItem.getProductId())) {
chipAmount.setTextColor(colorBlue.getOnAccentContainer());
chipAmount.setChipBackgroundColor(ColorStateList.valueOf(colorBlue.getAccentContainer()));
chipAmount.setTextColor(colorOnBlueContainer);
chipAmount.setChipBackgroundColor(ColorStateList.valueOf(colorBlueContainer));
}
holder.binding.flexboxLayout.addView(chipAmount);
}
Expand All @@ -395,8 +393,8 @@ public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int positionD
if (!stringBuilderAmountAggregated.toString().isBlank()) {
Chip chipAmountAggregated = createChip(context, stringBuilderAmountAggregated.toString());
if (missingItemsProductIds.contains(stockItem.getProductId())) {
chipAmountAggregated.setTextColor(colorBlue.getOnAccentContainer());
chipAmountAggregated.setChipBackgroundColor(ColorStateList.valueOf(colorBlue.getAccentContainer()));
chipAmountAggregated.setTextColor(colorOnBlueContainer);
chipAmountAggregated.setChipBackgroundColor(ColorStateList.valueOf(colorBlueContainer));
}
holder.binding.flexboxLayout.addView(chipAmountAggregated);
}
Expand All @@ -419,11 +417,15 @@ public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int positionD
if (Integer.parseInt(days) <= daysExpiringSoon
&& !stockItem.getProduct().getNoOwnStockBoolean()) { // don't color days text if product has no own stock (children will be colored)
if (Integer.parseInt(days) >= 0) {
chipDate.setTextColor(colorYellow.getOnAccentContainer());
chipDate.setChipBackgroundColor(ColorStateList.valueOf(colorYellow.getAccentContainer()));
chipDate.setTextColor(ResUtil.getColorAttr(context, R.attr.colorOnCustomYellowContainer));
chipDate.setChipBackgroundColor(ColorStateList.valueOf(
ResUtil.getColorAttr(context, R.attr.colorCustomYellowContainer)
));
} else if (stockItem.getDueTypeInt() == StockItem.DUE_TYPE_BEST_BEFORE) {
chipDate.setTextColor(colorOrange.getOnAccentContainer());
chipDate.setChipBackgroundColor(ColorStateList.valueOf(colorOrange.getAccentContainer())); // formally DIRT
chipDate.setTextColor(ResUtil.getColorAttr(context, R.attr.colorOnCustomOrangeContainer));
chipDate.setChipBackgroundColor(ColorStateList.valueOf(
ResUtil.getColorAttr(context, R.attr.colorCustomOrangeContainer)
));
} else {
chipDate.setTextColor(ResUtil.getColorAttr(context, R.attr.colorOnErrorContainer));
chipDate.setChipBackgroundColor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,13 @@ public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int positionD
ResourcesCompat.getFont(context, R.font.jost_medium)
);

ColorRoles colorBlue = ResUtil.getHarmonizedRoles(context, R.color.blue);
ColorRoles colorYellow = ResUtil.getHarmonizedRoles(context, R.color.yellow);
int color;
if (days < 0) {
color = ResUtil.getColorAttr(context, R.attr.colorError);
} else if (days == 0) {
color = colorBlue.getAccent();
color = ResUtil.getColorAttr(context, R.attr.colorCustomBlue);
} else {
color = colorYellow.getAccent();
color = ResUtil.getColorAttr(context, R.attr.colorCustomYellow);
}
holder.binding.days.setTextColor(color);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ public void onViewCreated(@Nullable View view, @Nullable Bundle savedInstanceSta
|| viewModel.isProductWillBeFilled()) && viewModel.getFormData().isScannerVisible()
);

ColorRoles roles = ResUtil.getHarmonizedRoles(activity, R.color.blue);
int colorBlue = ResUtil.getColorAttr(activity, R.attr.colorCustomBlue);
viewModel.getQuickModeEnabled().observe(
getViewLifecycleOwner(), value -> binding.toolbar.setTitleTextColor(
value ? roles.getAccent() : ResUtil.getColorAttr(activity, R.attr.colorOnSurface)
value ? colorBlue : ResUtil.getColorAttr(activity, R.attr.colorOnSurface)
)
);
binding.textInputAmount.setHelperTextColor(ColorStateList.valueOf(roles.getAccent()));
binding.textInputAmount.setHelperTextColor(ColorStateList.valueOf(colorBlue));
viewModel.getFormData().getQuantityUnitErrorLive().observe(
getViewLifecycleOwner(), value -> binding.textQuantityUnit.setTextColor(
ResUtil.getColorAttr(activity, value ? R.attr.colorError : R.attr.colorOnSurfaceVariant)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ public void onViewCreated(@Nullable View view, @Nullable Bundle savedInstanceSta
|| viewModel.isProductWillBeFilled()) && viewModel.getFormData().isScannerVisible()
);

ColorRoles roles = ResUtil.getHarmonizedRoles(activity, R.color.blue);
int colorBlue = ResUtil.getColorAttr(activity, R.attr.colorCustomBlue);
viewModel.getQuickModeEnabled().observe(
getViewLifecycleOwner(), value -> binding.toolbar.setTitleTextColor(
value ? roles.getAccent() : ResUtil.getColorAttr(activity, R.attr.colorOnSurface)
value ? colorBlue : ResUtil.getColorAttr(activity, R.attr.colorOnSurface)
)
);
binding.textInputAmount.setHelperTextColor(ColorStateList.valueOf(roles.getAccent()));
binding.textInputPurchasePrice.setHelperTextColor(ColorStateList.valueOf(roles.getAccent()));
binding.textInputAmount.setHelperTextColor(ColorStateList.valueOf(colorBlue));
binding.textInputPurchasePrice.setHelperTextColor(ColorStateList.valueOf(colorBlue));
viewModel.getFormData().getDueDateErrorLive().observe(
getViewLifecycleOwner(), value -> binding.textDueDate.setTextColor(
ResUtil.getColorAttr(activity, value ? R.attr.colorError : R.attr.colorOnSurfaceVariant)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
viewModel.getInfoFullscreenLive().setValue(infoFullscreen);
});

ColorRoles roles = ResUtil.getHarmonizedRoles(activity, R.color.blue);
binding.textInputAmount.setHelperTextColor(ColorStateList.valueOf(roles.getAccent()));
binding.textInputAmount.setHelperTextColor(ColorStateList.valueOf(
ResUtil.getColorAttr(activity, R.attr.colorCustomBlue)
));

embeddedFragmentScanner.setScannerVisibilityLive(
viewModel.getFormData().getScannerVisibilityLive()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
viewModel.getInfoFullscreenLive().setValue(infoFullscreen);
});

ColorRoles roles = ResUtil.getHarmonizedRoles(activity, R.color.blue);
binding.textInputFactor.setHelperTextColor(ColorStateList.valueOf(roles.getAccent()));
binding.textInputFactor.setHelperTextColor(ColorStateList.valueOf(
ResUtil.getColorAttr(activity, R.attr.colorCustomBlue)
));

// necessary because else getValue() doesn't give current value (?)
viewModel.getFormData().getQuantityUnitsLive().observe(getViewLifecycleOwner(), qUs -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,12 @@ public void onGlobalLayout() {
// DEBUG LABEL

if (BuildConfig.DEBUG) {
ColorRoles roles = ResUtil.getHarmonizedRoles(activity, R.color.yellow);
binding.imageLabelDebug.setColorFilter(roles.getOnAccent());
binding.imageLabelDebugBg.setColorFilter(roles.getAccent());
binding.imageLabelDebug.setColorFilter(
ResUtil.getColorAttr(activity, R.attr.colorOnCustomYellow)
);
binding.imageLabelDebugBg.setColorFilter(
ResUtil.getColorAttr(activity, R.attr.colorCustomYellow)
);
}

// UPDATE UI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,14 @@ public void onViewCreated(@Nullable View view, @Nullable Bundle savedInstanceSta
|| viewModel.isProductWillBeFilled()) && viewModel.getFormData().isScannerVisible()
);

ColorRoles roles = ResUtil.getHarmonizedRoles(activity, R.color.blue);
int colorBlue = ResUtil.getColorAttr(activity, R.attr.colorCustomBlue);
viewModel.getQuickModeEnabled().observe(
getViewLifecycleOwner(), value -> binding.toolbar.setTitleTextColor(
value ? roles.getAccent() : ResUtil.getColorAttr(activity, R.attr.colorOnSurface)
value ? colorBlue : ResUtil.getColorAttr(activity, R.attr.colorOnSurface)
)
);
binding.textInputAmount.setHelperTextColor(ColorStateList.valueOf(roles.getAccent()));
binding.textInputPurchasePrice.setHelperTextColor(ColorStateList.valueOf(roles.getAccent()));
binding.textInputAmount.setHelperTextColor(ColorStateList.valueOf(colorBlue));
binding.textInputPurchasePrice.setHelperTextColor(ColorStateList.valueOf(colorBlue));
viewModel.getFormData().getDueDateErrorLive().observe(
getViewLifecycleOwner(), value -> binding.textDueDate.setTextColor(
ResUtil.getColorAttr(activity, value ? R.attr.colorError : R.attr.colorOnSurfaceVariant)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
activity.navUtil.navigateFragment(R.id.photoViewerFragment, argsPhotoViewer);
});

ColorRoles colorYellow = ResUtil.getHarmonizedRoles(requireContext(), R.color.yellow);
binding.buttonFulfillmentInfo.setIconTint(ColorStateList.valueOf(colorYellow.getAccent()));
binding.buttonFulfillmentInfo.setIconTint(ColorStateList.valueOf(
ResUtil.getColorAttr(activity, R.attr.colorCustomYellow)
));

binding.recycler.setLayoutManager(
new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
Expand Down
Loading

0 comments on commit 05911b9

Please sign in to comment.