File tree Expand file tree Collapse file tree 2 files changed +22
-9
lines changed
app/src/main/java/com/philkes/notallyx/presentation Expand file tree Collapse file tree 2 files changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -595,10 +595,23 @@ fun Context.displayEditLabelDialog(
595595}
596596
597597private fun formatTimestamp (timestamp : Long , dateFormat : DateFormat ): String {
598- val date = Date (timestamp)
598+ return Date (timestamp).format(dateFormat)
599+ }
600+
601+ fun Date.format (dateFormat : DateFormat ): String {
599602 return when (dateFormat) {
600- DateFormat .RELATIVE -> PrettyTime ().format(date)
601- else -> java.text.DateFormat .getDateInstance(java.text.DateFormat .FULL ).format(date)
603+ DateFormat .NONE -> " "
604+ DateFormat .RELATIVE -> PrettyTime ().format(this )
605+ DateFormat .ABSOLUTE ->
606+ java.text.DateFormat .getDateInstance(java.text.DateFormat .FULL ).format(this )
607+ DateFormat .ABSOLUTE_SHORT ->
608+ java.text.DateFormat .getDateInstance(java.text.DateFormat .SHORT ).format(this )
609+ DateFormat .TIMESTAMP_SHORT ->
610+ java.text.DateFormat .getDateTimeInstance(
611+ java.text.DateFormat .SHORT ,
612+ java.text.DateFormat .SHORT ,
613+ )
614+ .format(this )
602615 }
603616}
604617
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import androidx.lifecycle.LiveData
99import androidx.lifecycle.MediatorLiveData
1010import androidx.lifecycle.Observer
1111import com.philkes.notallyx.R
12+ import com.philkes.notallyx.presentation.format
1213import com.philkes.notallyx.presentation.merge
1314import com.philkes.notallyx.presentation.view.misc.NotNullLiveData
1415import com.philkes.notallyx.utils.createObserverSkipFirst
@@ -19,7 +20,6 @@ import com.philkes.notallyx.utils.toPreservedString
1920import java.security.SecureRandom
2021import java.util.Date
2122import javax.crypto.Cipher
22- import org.ocpsoft.prettytime.PrettyTime
2323
2424/* *
2525 * Every Preference can be observed like a [NotNullLiveData].
@@ -302,15 +302,15 @@ enum class Theme(override val textResId: Int) : StaticTextProvider {
302302enum class DateFormat : TextProvider {
303303 NONE ,
304304 RELATIVE ,
305+ ABSOLUTE_SHORT ,
306+ TIMESTAMP_SHORT ,
305307 ABSOLUTE ;
306308
307309 override fun getText (context : Context ): String {
308- val date = Date (System .currentTimeMillis() - 86400000 )
309- return when (this ) {
310- NONE -> context.getString(R .string.none)
311- RELATIVE -> PrettyTime ().format(date)
312- ABSOLUTE -> java.text.DateFormat .getDateInstance(java.text.DateFormat .FULL ).format(date)
310+ if (this == NONE ) {
311+ return context.getString(R .string.none)
313312 }
313+ return Date (System .currentTimeMillis() - 86400000 ).format(this )
314314 }
315315}
316316
You can’t perform that action at this time.
0 commit comments