diff options
author | Stefan Niedermann <info@niedermann.it> | 2021-04-09 21:11:11 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2021-04-10 14:38:50 +0300 |
commit | ec169382d41f5c12f62dc33e6469b6e26830c7da (patch) | |
tree | 8c8019fb1030fe82a1bd460115a3e5bb15757eac /app | |
parent | a5ef1b4930cb7bef7499fe2fce32b9a5cd02d171 (diff) |
#690 Upcoming cards
Refactor to common enums and utils
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app')
4 files changed, 78 insertions, 108 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/upcomingcards/EUpcomingDueType.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/upcomingcards/EUpcomingDueType.java new file mode 100644 index 000000000..fb0ee2863 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/upcomingcards/EUpcomingDueType.java @@ -0,0 +1,34 @@ +package it.niedermann.nextcloud.deck.ui.upcomingcards; + +import android.content.Context; + +import androidx.annotation.NonNull; +import androidx.annotation.StringRes; + +import it.niedermann.nextcloud.deck.R; + +public enum EUpcomingDueType { + OVERDUE(1, R.string.filter_overdue), + TODAY(2, R.string.filter_today), + TOMORROW(3, R.string.filter_tomorrow), + WEEK(4, R.string.filter_week), + LATER(5, R.string.filter_later), + NO_DUE(6, R.string.filter_no_due); + + private final int value; + private final int id; + + EUpcomingDueType(int id, @StringRes int value) { + this.value = value; + this.id = id; + } + + public int getId() { + return id; + } + + @NonNull + public String toString(Context context) { + return context.getString(this.value); + } +}
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/upcomingcards/UpcomingCardsAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/upcomingcards/UpcomingCardsAdapter.java index 3d17728c3..4395742d5 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/upcomingcards/UpcomingCardsAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/upcomingcards/UpcomingCardsAdapter.java @@ -1,21 +1,15 @@ package it.niedermann.nextcloud.deck.ui.upcomingcards; import android.app.Activity; -import android.content.Context; import android.view.LayoutInflater; import android.view.ViewGroup; import androidx.annotation.ColorInt; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.StringRes; import androidx.core.content.ContextCompat; import androidx.fragment.app.FragmentManager; import androidx.recyclerview.widget.RecyclerView; -import java.time.Instant; -import java.time.LocalDate; -import java.time.ZoneId; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -37,7 +31,7 @@ import it.niedermann.nextcloud.deck.ui.card.DefaultCardViewHolder; import it.niedermann.nextcloud.deck.ui.card.EditActivity; import static androidx.preference.PreferenceManager.getDefaultSharedPreferences; -import static java.time.temporal.ChronoUnit.DAYS; +import static it.niedermann.nextcloud.deck.ui.upcomingcards.UpcomingCardsUtil.getDueType; public class UpcomingCardsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { @@ -156,12 +150,13 @@ public class UpcomingCardsAdapter extends RecyclerView.Adapter<RecyclerView.View } return null; }), Comparator.nullsLast(Comparator.naturalOrder())); + comparator.thenComparing(card -> { if (card != null && card.getFullCard() != null && card.getFullCard().getCard().getDueDate() != null) { - Card c = card.getFullCard().getCard(); + final Card c = card.getFullCard().getCard(); if (c.getLastModified() == null && c.getLastModifiedLocal() != null) { return c.getLastModifiedLocal(); @@ -179,6 +174,7 @@ public class UpcomingCardsAdapter extends RecyclerView.Adapter<RecyclerView.View items, comparator ); + EUpcomingDueType lastDueType = null; for (UpcomingCardsAdapterItem filterWidgetCard : items) { final EUpcomingDueType nextDueType = getDueType(filterWidgetCard.getFullCard().getCard().getDueDate()); @@ -192,51 +188,4 @@ public class UpcomingCardsAdapter extends RecyclerView.Adapter<RecyclerView.View notifyDataSetChanged(); } - - @NonNull - private static EUpcomingDueType getDueType(@Nullable Instant dueDate) { - if (dueDate == null) { - return EUpcomingDueType.NO_DUE; - } - - long diff = DAYS.between(LocalDate.now(), dueDate.atZone(ZoneId.systemDefault()).toLocalDate()); - - if (diff > 7) { - return EUpcomingDueType.LATER; - } else if (diff > 1) { - return EUpcomingDueType.WEEK; - } else if (diff > 0) { - return EUpcomingDueType.TOMORROW; - } else if (diff == 0) { - return EUpcomingDueType.TODAY; - } else { - return EUpcomingDueType.OVERDUE; - } - } - - private enum EUpcomingDueType { - OVERDUE(1, R.string.filter_overdue), - TODAY(2, R.string.filter_today), - TOMORROW(3, R.string.filter_tomorrow), - WEEK(4, R.string.filter_week), - LATER(5, R.string.filter_later), - NO_DUE(6, R.string.filter_no_due); - - private final int value; - private final int id; - - EUpcomingDueType(int id, @StringRes int value) { - this.value = value; - this.id = id; - } - - public int getId() { - return id; - } - - @NonNull - public String toString(Context context) { - return context.getString(this.value); - } - } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/upcomingcards/UpcomingCardsUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/upcomingcards/UpcomingCardsUtil.java new file mode 100644 index 000000000..515afec78 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/upcomingcards/UpcomingCardsUtil.java @@ -0,0 +1,38 @@ +package it.niedermann.nextcloud.deck.ui.upcomingcards; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneId; + +import static java.time.temporal.ChronoUnit.DAYS; + +public class UpcomingCardsUtil { + + private UpcomingCardsUtil() { + throw new UnsupportedOperationException("This class must not get instantiated"); + } + + @NonNull + public static EUpcomingDueType getDueType(@Nullable Instant dueDate) { + if (dueDate == null) { + return EUpcomingDueType.NO_DUE; + } + + long diff = DAYS.between(LocalDate.now(), dueDate.atZone(ZoneId.systemDefault()).toLocalDate()); + + if (diff > 7) { + return EUpcomingDueType.LATER; + } else if (diff > 1) { + return EUpcomingDueType.WEEK; + } else if (diff > 0) { + return EUpcomingDueType.TOMORROW; + } else if (diff == 0) { + return EUpcomingDueType.TODAY; + } else { + return EUpcomingDueType.OVERDUE; + } + } +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/upcoming/UpcomingWidgetFactory.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/upcoming/UpcomingWidgetFactory.java index 964c21ffa..deaaf6712 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/upcoming/UpcomingWidgetFactory.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/widget/upcoming/UpcomingWidgetFactory.java @@ -8,12 +8,7 @@ import android.widget.RemoteViews; import android.widget.RemoteViewsService; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.StringRes; -import java.time.Instant; -import java.time.LocalDate; -import java.time.ZoneId; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -28,8 +23,9 @@ import it.niedermann.nextcloud.deck.model.full.FullCard; import it.niedermann.nextcloud.deck.model.widget.filter.dto.FilterWidgetCard; import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; import it.niedermann.nextcloud.deck.ui.card.EditActivity; +import it.niedermann.nextcloud.deck.ui.upcomingcards.EUpcomingDueType; -import static java.time.temporal.ChronoUnit.DAYS; +import static it.niedermann.nextcloud.deck.ui.upcomingcards.UpcomingCardsUtil.getDueType; public class UpcomingWidgetFactory implements RemoteViewsService.RemoteViewsFactory { private final Context context; @@ -167,53 +163,6 @@ public class UpcomingWidgetFactory implements RemoteViewsService.RemoteViewsFact return true; } - @NonNull - private static EUpcomingDueType getDueType(@Nullable Instant dueDate) { - if (dueDate == null) { - return EUpcomingDueType.NO_DUE; - } - - long diff = DAYS.between(LocalDate.now(), dueDate.atZone(ZoneId.systemDefault()).toLocalDate()); - - if (diff > 7) { - return EUpcomingDueType.LATER; - } else if (diff > 1) { - return EUpcomingDueType.WEEK; - } else if (diff > 0) { - return EUpcomingDueType.TOMORROW; - } else if (diff == 0) { - return EUpcomingDueType.TODAY; - } else { - return EUpcomingDueType.OVERDUE; - } - } - - private enum EUpcomingDueType { - OVERDUE(1, R.string.filter_overdue), - TODAY(2, R.string.filter_today), - TOMORROW(3, R.string.filter_tomorrow), - WEEK(4, R.string.filter_week), - LATER(5, R.string.filter_later), - NO_DUE(6, R.string.filter_no_due); - - private final int value; - private final int id; - - EUpcomingDueType(int id, @StringRes int value) { - this.value = value; - this.id = id; - } - - public int getId() { - return id; - } - - @NonNull - public String toString(Context context) { - return context.getString(this.value); - } - } - private static class Separator { public String title; |