@@ -110,18 +110,16 @@ import com.philkes.notallyx.presentation.view.note.listitem.ListManager
110110import com.philkes.notallyx.presentation.view.note.listitem.adapter.ListItemVH
111111import com.philkes.notallyx.presentation.viewmodel.BaseNoteModel
112112import com.philkes.notallyx.presentation.viewmodel.preference.DateFormat
113+ import com.philkes.notallyx.presentation.viewmodel.preference.TimeFormat
113114import com.philkes.notallyx.presentation.viewmodel.preference.displayBodySize
114115import com.philkes.notallyx.utils.changehistory.ChangeHistory
115116import com.philkes.notallyx.utils.changehistory.EditTextState
116117import com.philkes.notallyx.utils.changehistory.EditTextWithHistoryChange
117118import com.philkes.notallyx.utils.getUrl
118- import java.text.SimpleDateFormat
119119import java.util.Date
120- import java.util.Locale
121120import me.zhanghai.android.fastscroll.FastScrollNestedScrollView
122121import me.zhanghai.android.fastscroll.FastScrollerBuilder
123122import me.zhanghai.android.fastscroll.PopupStyles
124- import org.ocpsoft.prettytime.PrettyTime
125123
126124/* *
127125 * For some reason, this method crashes sometimes with an IndexOutOfBoundsException that I've not
@@ -290,12 +288,14 @@ fun ViewGroup.addIconButton(
290288fun TextView.displayFormattedTimestamp (
291289 timestamp : Long? ,
292290 dateFormat : DateFormat ,
291+ timeFormat : TimeFormat ,
293292 prefixResId : Int? = null,
294293) {
295- if (dateFormat != DateFormat .NONE && timestamp != null ) {
294+ if (( dateFormat != DateFormat .NONE || timeFormat != TimeFormat . NONE ) && timestamp != null ) {
296295 visibility = View .VISIBLE
297296 text =
298- " ${prefixResId?.let { getString(it) } ? : " " } ${formatTimestamp(timestamp, dateFormat)} "
297+ " ${prefixResId?.let { getString(it) } ? : " " } ${Date (timestamp).format(dateFormat, timeFormat)} "
298+ .trim()
299299 } else visibility = View .GONE
300300}
301301
@@ -456,6 +456,17 @@ fun <T, C> NotNullLiveData<T>.merge(liveData: NotNullLiveData<C>): MediatorLiveD
456456 }
457457}
458458
459+ fun <T , C , B > NotNullLiveData<T>.merge (
460+ liveData : NotNullLiveData <C >,
461+ liveData2 : NotNullLiveData <B >,
462+ ): MediatorLiveData <Triple <T , C , B >> {
463+ return MediatorLiveData <Triple <T , C , B >>().apply {
464+ addSource(this @merge) { value1 -> value = Triple (value1, liveData.value, liveData2.value) }
465+ addSource(liveData) { value2 -> value = Triple (this @merge.value, value2, liveData2.value) }
466+ addSource(liveData2) { value3 -> value = Triple (this @merge.value, liveData.value, value3) }
467+ }
468+ }
469+
459470fun <T , C > NotNullLiveData<T>.merge (liveData : LiveData <C >): MediatorLiveData <Pair <T , C ?>> {
460471 return MediatorLiveData <Pair <T , C ?>>().apply {
461472 addSource(this @merge) { value1 -> value = Pair (value1, liveData.value) }
@@ -612,29 +623,28 @@ fun Context.displayEditLabelDialog(
612623 }
613624}
614625
615- private fun formatTimestamp (timestamp : Long , dateFormat : DateFormat ): String {
616- return Date (timestamp).format(dateFormat)
617- }
626+ fun Date.format (
627+ dateFormat : DateFormat = DateFormat .DD_MM_YY_GER ,
628+ timeFormat : TimeFormat = TimeFormat .TWENTY_FOUR_H ,
629+ ensureFullFormat : Boolean = false,
630+ ): String {
631+ val (effectiveDateFormat, effectiveTimeFormat) =
632+ if (ensureFullFormat && dateFormat != DateFormat .RELATIVE ) {
633+ Pair (
634+ dateFormat.takeIf { it != DateFormat .NONE } ? : DateFormat .DD_MM_YY_GER ,
635+ timeFormat.takeIf { it != TimeFormat .NONE } ? : TimeFormat .TWENTY_FOUR_H ,
636+ )
637+ } else Pair (dateFormat, timeFormat)
638+ if (effectiveDateFormat == DateFormat .NONE && effectiveTimeFormat == TimeFormat .NONE ) {
639+ return " "
640+ }
641+ val datePart = effectiveDateFormat.format(this )
642+ val timePart = effectiveTimeFormat.format(this )
618643
619- private val ISO_DATE_FORMAT = SimpleDateFormat (" yyyy-MM-dd" , Locale .US )
620-
621- fun Date.format (dateFormat : DateFormat = DateFormat .TIMESTAMP_SHORT ): String {
622- return when (dateFormat) {
623- DateFormat .NONE -> " "
624- DateFormat .RELATIVE -> PrettyTime ().format(this )
625- DateFormat .ABSOLUTE ->
626- java.text.DateFormat .getDateInstance(java.text.DateFormat .FULL ).format(this )
627- DateFormat .ABSOLUTE_SHORT ->
628- java.text.DateFormat .getDateInstance(java.text.DateFormat .SHORT ).format(this )
629- DateFormat .SHORT_ISO -> {
630- ISO_DATE_FORMAT .format(this )
631- }
632- DateFormat .TIMESTAMP_SHORT ->
633- java.text.DateFormat .getDateTimeInstance(
634- java.text.DateFormat .SHORT ,
635- java.text.DateFormat .SHORT ,
636- )
637- .format(this )
644+ return if (datePart.isNotEmpty() && timePart.isNotEmpty()) {
645+ " $datePart $timePart "
646+ } else {
647+ datePart + timePart
638648 }
639649}
640650
@@ -1142,7 +1152,12 @@ fun Context.createTextView(textResId: Int, padding: Int = 16.dp): TextView {
11421152 }
11431153}
11441154
1145- fun Chip.setupReminderChip (baseNote : BaseNote , textSize : Float? = null) {
1155+ fun Chip.setupReminderChip (
1156+ baseNote : BaseNote ,
1157+ dateFormat : DateFormat ,
1158+ timeFormat : TimeFormat ,
1159+ textSize : Float? = null,
1160+ ) {
11461161 val now = Date (System .currentTimeMillis())
11471162 val mostRecentNotificationDate =
11481163 baseNote.reminders.findNextNotificationDate()
@@ -1153,7 +1168,7 @@ fun Chip.setupReminderChip(baseNote: BaseNote, textSize: Float? = null) {
11531168 }
11541169 this .apply {
11551170 visibility = VISIBLE
1156- text = mostRecentNotificationDate.format()
1171+ text = mostRecentNotificationDate.format(dateFormat, timeFormat, ensureFullFormat = true )
11571172 textSize?.let {
11581173 setTextSizeSp(it)
11591174 chipIconSize =
0 commit comments