Skip to content
Snippets Groups Projects
Unverified Commit 1dcf6ce1 authored by Kolya Opahle's avatar Kolya Opahle Committed by GitHub
Browse files

Added relative date formatting to risk card via DateUtils (#276)


* Added relative date formatting to risk card via DateUtils

* lint fixes

Co-authored-by: default avatarharambasicluka <64483219+harambasicluka@users.noreply.github.com>
parent 59d8346f
No related branches found
No related tags found
No related merge requests found
......@@ -2,12 +2,13 @@
package de.rki.coronawarnapp.util.formatter
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.drawable.Drawable
import android.text.format.DateUtils
import de.rki.coronawarnapp.CoronaWarnApplication
import de.rki.coronawarnapp.R
import de.rki.coronawarnapp.risk.RiskLevelConstants
import java.text.DateFormat
import java.util.Date
/*Texter*/
......@@ -190,6 +191,15 @@ fun formatRiskActiveTracingDaysInRetentionPeriod(
}
}
fun formatRelativeDateTimeString(appContext: Context, date: Date): CharSequence? =
DateUtils.getRelativeDateTimeString(
appContext,
date.time,
DateUtils.DAY_IN_MILLIS,
DateUtils.DAY_IN_MILLIS * 2,
0
)
/**
* Formats the risk card text display of the last time diagnosis keys were
* successfully fetched from the server
......@@ -211,9 +221,7 @@ fun formatTimeFetched(
if (lastTimeDiagnosisKeysFetched != null) {
appContext.getString(
R.string.risk_card_body_time_fetched,
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(
lastTimeDiagnosisKeysFetched
)
formatRelativeDateTimeString(appContext, lastTimeDiagnosisKeysFetched)
)
} else {
appContext.getString(R.string.risk_card_body_not_yet_fetched)
......@@ -228,10 +236,7 @@ fun formatTimeFetched(
if (lastTimeDiagnosisKeysFetched != null) {
appContext.getString(
R.string.risk_card_body_time_fetched,
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM)
.format(
lastTimeDiagnosisKeysFetched
)
formatRelativeDateTimeString(appContext, lastTimeDiagnosisKeysFetched)
)
} else {
appContext.getString(R.string.risk_card_body_not_yet_fetched)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment