diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-10-30 20:23:20 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-10-30 20:23:20 +0300 |
commit | b5d1096f5334c21a1760fa2c2708d195528bf0e6 (patch) | |
tree | e3c4e8e95d11d99cc3bde26a0674bc0472417d58 /app/src/main/java/it/niedermann/nextcloud/deck/util | |
parent | 8f433ce9052cfeaef6eaba0e7ee71c7d42f4eb7e (diff) | |
parent | a60dd0bcf606b061681fd9cb3ca6edb72bcfc4da (diff) |
Merge branch 'master' into 289-upload-sources
# Conflicts:
# app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/util')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/util/DateUtil.java | 51 | ||||
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/util/ViewUtil.java | 7 |
2 files changed, 10 insertions, 48 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/util/DateUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/util/DateUtil.java index 5c2ffd76c..ac88519ff 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/util/DateUtil.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/util/DateUtil.java @@ -3,9 +3,9 @@ package it.niedermann.nextcloud.deck.util; import android.content.Context; import android.text.format.DateUtils; -import java.util.Date; -import java.util.TimeZone; -import java.util.concurrent.TimeUnit; +import androidx.annotation.NonNull; + +import java.time.ZonedDateTime; import it.niedermann.nextcloud.deck.R; @@ -15,48 +15,9 @@ public final class DateUtil { private DateUtil() { } - public static Date nowInGMT() { - return convertToGMT(new Date()); - } - - private static Date convertToGMT(Date date ){ - TimeZone tz = TimeZone.getDefault(); - Date ret = new Date( date.getTime() - tz.getRawOffset() ); - - // if we are now in DST, back off by the delta. Note that we are checking the GMT date, this is the KEY. - if ( tz.inDaylightTime( ret )){ - Date dstDate = new Date( ret.getTime() - tz.getDSTSavings() ); - - // check to make sure we have not crossed back into standard time - // this happens when we are on the cusp of DST (7pm the day before the change for PDT) - if ( tz.inDaylightTime( dstDate )){ - ret = dstDate; - } - } - return ret; - } - - /** - * Get difference between 2 dates in days (hours, minutes will be set to zero). - * - * @param sourceDateFrom start date - * @param sourceDateUntil end date - * @return difference between the to dates in days. - */ - public static long getDayDifference(Date sourceDateFrom, Date sourceDateUntil) { - Date dateFrom = new Date(sourceDateFrom.getTime()); - dateFrom.setHours(0); - dateFrom.setMinutes(0); - - Date dateUntil = new Date(sourceDateUntil.getTime()); - dateUntil.setHours(0); - dateUntil.setMinutes(0); - - return TimeUnit.DAYS.convert(dateUntil.getTime() - dateFrom.getTime(), TimeUnit.MILLISECONDS); - } - - public static CharSequence getRelativeDateTimeString(Context context, long time) { - if ((System.currentTimeMillis() - time) < 60 * 1000 && System.currentTimeMillis() > time) { + public static CharSequence getRelativeDateTimeString(@NonNull Context context, long time) { + long now = ZonedDateTime.now().toInstant().toEpochMilli(); + if ((now - time) < 60 * 1000 && now > time) { // < 60 seconds -> seconds ago return context.getString(R.string.seconds_ago); } else { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/util/ViewUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/util/ViewUtil.java index a52053ec1..b676fcedb 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/util/ViewUtil.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/util/ViewUtil.java @@ -25,7 +25,7 @@ import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.transition.Transition; -import java.util.Date; +import java.time.LocalDate; import java.util.List; import it.niedermann.android.util.DimensionUtil; @@ -34,6 +34,7 @@ import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.ocs.comment.Mention; import static it.niedermann.nextcloud.deck.DeckApplication.isDarkTheme; +import static java.time.temporal.ChronoUnit.DAYS; public final class ViewUtil { private ViewUtil() { @@ -53,8 +54,8 @@ public final class ViewUtil { .into(avatar); } - public static void themeDueDate(Context context, TextView cardDueDate, Date dueDate) { - long diff = DateUtil.getDayDifference(new Date(), dueDate); + public static void themeDueDate(@NonNull Context context, @NonNull TextView cardDueDate, @NonNull LocalDate dueDate) { + long diff = DAYS.between(LocalDate.now(), dueDate); int backgroundDrawable = 0; int textColor = isDarkTheme(context) ? R.color.dark_fg_primary : R.color.grey600; |