Skip to content

Commit

Permalink
feat(done): Display done state and adjust colors
Browse files Browse the repository at this point in the history
Refs: #1556

Signed-off-by: Stefan Niedermann <[email protected]>
  • Loading branch information
stefan-niedermann committed Jan 13, 2024
1 parent 2d62de8 commit 7976b32
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.jetbrains.annotations.Contract;

import java.time.Instant;
import java.time.ZoneId;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -65,8 +66,8 @@ public void bind(@NonNull FullCard fullCard, @NonNull Account account, @Nullable

getNotSyncedYet().setVisibility(DBStatus.LOCAL_EDITED.equals(fullCard.getStatusEnum()) ? View.VISIBLE : View.GONE);

if (fullCard.getCard().getDueDate() != null) {
setupDueDate(getCardDueDate(), fullCard.getCard());
if (fullCard.getCard().getDueDate() != null || fullCard.getCard().getDone() != null) {
setupTemporalChip(getCardDueDate(), fullCard.getCard());
getCardDueDate().setVisibility(View.VISIBLE);
} else {
getCardDueDate().setVisibility(View.GONE);
Expand Down Expand Up @@ -112,9 +113,15 @@ public MaterialCardView getDraggable() {
return getCard();
}

private static void setupDueDate(@NonNull TextView cardDueDate, @NonNull Card card) {
cardDueDate.setText(DateUtil.getRelativeDateTimeString(cardDueDate.getContext(), card.getDueDate().toEpochMilli()));
DeckViewThemeUtils.themeDueDate(cardDueDate, card.getDueDate().atZone(ZoneId.systemDefault()).toLocalDate());
/**
* Sets up a temporal information, e. g. {@link Card#getDone()} or {@link Card#getDueDate()}
*/
private static void setupTemporalChip(@NonNull TextView cardDueDate, @NonNull Card card) {
final boolean isDone = card.getDone() != null;
final Instant temporalInformation = isDone ? card.getDone() : card.getDueDate();

cardDueDate.setText(DateUtil.getRelativeDateTimeString(cardDueDate.getContext(), temporalInformation.toEpochMilli()));
DeckViewThemeUtils.themeTemporalChip(cardDueDate, temporalInformation.atZone(ZoneId.systemDefault()).toLocalDate(), isDone);
}

protected static void setupCoverImages(@NonNull Account account, @NonNull ViewGroup coverImagesHolder, @NonNull FullCard fullCard, int maxCoverImagesCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,25 +197,28 @@ private Optional<LayerDrawable> getStateDrawable(@NonNull StateListDrawable draw


@Deprecated(forRemoval = true)
public static void themeDueDate(@NonNull TextView cardDueDate, @NonNull LocalDate dueDate) {
public static void themeTemporalChip(@NonNull TextView cardDueDate, @NonNull LocalDate date, boolean isDone) {
final var context = cardDueDate.getContext();
final long diff = DAYS.between(LocalDate.now(), dueDate);

@ColorInt @Nullable Integer textColor = null;
@DrawableRes int backgroundDrawable = 0;

if (diff == 1) {
// due date: tomorrow
backgroundDrawable = R.drawable.due_tomorrow_background;
textColor = ContextCompat.getColor(context, R.color.due_text_tomorrow);
} else if (diff == 0) {
// due date: today
backgroundDrawable = R.drawable.due_today_background;
textColor = ContextCompat.getColor(context, R.color.due_text_today);
} else if (diff < 0) {
// due date: overdue
backgroundDrawable = R.drawable.due_overdue_background;
textColor = ContextCompat.getColor(context, R.color.due_text_overdue);
if (isDone) {
// due date: done
backgroundDrawable = R.drawable.due_done_background;
textColor = ContextCompat.getColor(context, R.color.due_text_done);
} else {
final long diff = DAYS.between(LocalDate.now(), date);

if (diff == 0) {
// due date: today
backgroundDrawable = R.drawable.due_today_background;
textColor = ContextCompat.getColor(context, R.color.due_text_today);
} else if (diff < 0) {
// due date: overdue
backgroundDrawable = R.drawable.due_overdue_background;
textColor = ContextCompat.getColor(context, R.color.due_text_overdue);
} // else we use default text styling
}

cardDueDate.setBackgroundResource(backgroundDrawable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ void updateAppWidget(Context context, AppWidgetManager awm, int[] appWidgetIds)
views.setTextViewText(R.id.title, fullModel.getFullCard().getCard().getTitle());
views.setRemoteAdapter(R.id.description_lv, serviceIntent);

if (fullModel.getFullCard().getCard().getDueDate() != null) {
if (fullModel.getFullCard().getCard().getDone() != null) {
views.setTextViewText(R.id.card_due_date, DateUtil.getRelativeDateTimeString(context, fullModel.getFullCard().getCard().getDone().toEpochMilli()));
// TODO Use multiple views for background colors and only set the necessary to View.VISIBLE
// https://stackoverflow.com/a/3376537
// Because otherwise using Reflection is the only way
views.setViewVisibility(R.id.card_due_date, View.VISIBLE);
views.setViewVisibility(R.id.card_due_date_image, View.VISIBLE);
views.setImageViewResource(R.id.card_due_date_image, R.drawable.calendar_blank_grey600_24dp);
} else if (fullModel.getFullCard().getCard().getDueDate() != null) {
views.setTextViewText(R.id.card_due_date, DateUtil.getRelativeDateTimeString(context, fullModel.getFullCard().getCard().getDueDate().toEpochMilli()));
// TODO Use multiple views for background colors and only set the necessary to View.VISIBLE
// https://stackoverflow.com/a/3376537
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/due_tomorrow" />
<solid android:color="@color/due_done" />

<corners
android:radius="4dp" />
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
<!-- ======================================= -->

<!-- Due Date badges -->
<color name="due_tomorrow">#232323</color>
<color name="due_today">#ac7c06</color>
<color name="due_overdue">#aa2926</color>
<color name="due_text_tomorrow">#ffffff</color>
<color name="due_text_today">#ffffff</color>
<color name="due_text_overdue">#ffffff</color>
<color name="due_today">#19c28900</color>
<color name="due_overdue">#19ee312b</color>
<color name="due_done">#1936914e</color>
<color name="due_text_today">#c28900</color>
<color name="due_text_overdue">#f36864</color>
<color name="due_text_done">#3ea75a</color>
</resources>
12 changes: 6 additions & 6 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
<!-- ======================================= -->

<!-- Due Date badges -->
<color name="due_tomorrow">#f2f2f2</color>
<color name="due_today">#f1c14b</color>
<color name="due_overdue">#ef6e6b</color>
<color name="due_text_tomorrow">#666666</color>
<color name="due_text_today">#333333</color>
<color name="due_text_overdue">#ffffff</color>
<color name="due_today">#f8f2e5</color>
<color name="due_overdue">#fbe7e6</color>
<color name="due_done">#e9f1eb</color>
<color name="due_text_today">#855d00</color>
<color name="due_text_overdue">#c61610</color>
<color name="due_text_done">#286c39</color>

<!-- Activity -->
<color name="activity_create">#00D400</color>
Expand Down

0 comments on commit 7976b32

Please sign in to comment.