Add option to always display full date

Closes #1156
pull/1188/head
T0M0F 5 years ago committed by Alex Baker
parent aca3c98914
commit b6059e509d

@ -90,23 +90,30 @@ public class DateUtilities {
public static String getRelativeDateTime(
Context context, long date, java.util.Locale locale, FormatStyle style) {
return getRelativeDateTime(context, date, locale, style, false);
return getRelativeDateTime(context, date, locale, style, false, false);
}
public static String getRelativeDateTime(
Context context, long date, java.util.Locale locale, FormatStyle style, boolean lowercase) {
if (isWithinSixDays(date)) {
String day = getRelativeDay(context, date, locale, isAbbreviated(style), lowercase);
if (Task.hasDueTime(date)) {
String time = getTimeString(context, newDateTime(date));
return newDateTime().startOfDay().equals(newDateTime(date).startOfDay()) ? time : String.format("%s %s", day, time);
} else {
return day;
}
Context context, long date, java.util.Locale locale, FormatStyle style, boolean lowercase) {
return getRelativeDateTime(context, date, locale, style, false, lowercase);
}
public static String getRelativeDateTime(
Context context, long date, java.util.Locale locale, FormatStyle style, boolean alwaysDisplayFullDate, boolean lowercase) {
if(alwaysDisplayFullDate || !isWithinSixDays(date)) {
return Task.hasDueTime(date)
? getFullDateTime(newDateTime(date), locale, style)
: getFullDate(newDateTime(date), locale, style);
}
String day = getRelativeDay(context, date, locale, isAbbreviated(style), lowercase);
if (Task.hasDueTime(date)) {
String time = getTimeString(context, newDateTime(date));
return newDateTime().startOfDay().equals(newDateTime(date).startOfDay()) ? time : String.format("%s %s", day, time);
} else {
return day;
}
return Task.hasDueTime(date)
? getFullDateTime(newDateTime(date), locale, style)
: getFullDate(newDateTime(date), locale, style);
}
private static boolean isAbbreviated(FormatStyle style) {
@ -118,7 +125,7 @@ public class DateUtilities {
long date,
java.util.Locale locale,
FormatStyle style) {
return getRelativeDay(context, date, locale, style, false);
return getRelativeDay(context, date, locale, style, false,false);
}
public static String getRelativeDay(
@ -126,7 +133,11 @@ public class DateUtilities {
long date,
java.util.Locale locale,
FormatStyle style,
boolean alwaysDisplayFullDate,
boolean lowercase) {
if(alwaysDisplayFullDate) {
return getFullDate(newDateTime(date), locale, style);
}
return isWithinSixDays(date)
? getRelativeDay(context, date, locale, isAbbreviated(style), lowercase)
: getFullDate(newDateTime(date), locale, style);

@ -338,6 +338,10 @@ class Preferences @JvmOverloads constructor(
override val showCompletedTemporarily: Boolean
get() = getBoolean(R.string.p_temporarily_show_completed_tasks, false)
override var alwaysDisplayFullDate: Boolean
get() = getBoolean(R.string.p_always_display_full_date, false)
set(value) { setBoolean(R.string.p_always_display_full_date, value)}
private fun setPublicPref(key: String, value: Int) {
val edit = publicPrefs.edit()
edit?.putInt(key, value)?.apply()

@ -15,5 +15,7 @@ interface QueryPreferences {
val showCompletedTemporarily: Boolean
var alwaysDisplayFullDate: Boolean
fun usePagedQueries(): Boolean
}

@ -52,7 +52,7 @@ class DragAndDropRecyclerAdapter(
val viewType = getItemViewType(position)
if (viewType == 1) {
val headerSection = items.getSection(position)
(holder as HeaderViewHolder).bind(taskList.getFilter(), preferences.sortMode, headerSection)
(holder as HeaderViewHolder).bind(taskList.getFilter(), preferences.sortMode, preferences.alwaysDisplayFullDate, headerSection)
} else {
super.onBindViewHolder(holder, position)
}

@ -22,9 +22,9 @@ class HeaderViewHolder(
private val header: TextView = view.findViewById(R.id.header)
private var sortGroup = -1L
fun bind(filter: Filter, sortMode: Int, section: AdapterSection) {
fun bind(filter: Filter, sortMode: Int, alwaysDisplayFullDate: Boolean, section: AdapterSection) {
sortGroup = section.value
val header: String? = if (filter.supportsSorting()) getHeader(sortMode, sortGroup) else null
val header: String? = if (filter.supportsSorting()) getHeader(sortMode, alwaysDisplayFullDate, sortGroup) else null
if (header == null) {
this.header.visibility = View.GONE
@ -38,7 +38,7 @@ class HeaderViewHolder(
}
}
private fun getHeader(sortMode: Int, group: Long): String {
private fun getHeader(sortMode: Int, alwaysDisplayFullDate: Boolean, group: Long): String {
return when {
sortMode == SortHelper.SORT_IMPORTANCE -> context.getString(priorityToString(group.toInt()))
group == 0L -> context.getString(if (sortMode == SortHelper.SORT_DUE) {
@ -47,15 +47,15 @@ class HeaderViewHolder(
R.string.no_date
})
sortMode == SortHelper.SORT_CREATED ->
context.getString(R.string.sort_created_group, getDateString(group))
context.getString(R.string.sort_created_group, getDateString(group, alwaysDisplayFullDate))
sortMode == SortHelper.SORT_MODIFIED ->
context.getString(R.string.sort_modified_group, getDateString(group))
else -> getDateString(group, false)
context.getString(R.string.sort_modified_group, getDateString(group, alwaysDisplayFullDate))
else -> getDateString(group, alwaysDisplayFullDate)
}
}
private fun getDateString(value: Long, lowercase: Boolean = true) =
DateUtilities.getRelativeDay(context, value, locale, FormatStyle.FULL, lowercase)
private fun getDateString(value: Long, alwaysDisplayFullDate: Boolean, lowercase: Boolean = true) =
DateUtilities.getRelativeDay(context, value, locale, FormatStyle.FULL, alwaysDisplayFullDate, lowercase)
@StringRes
private fun priorityToString(priority: Int) = when (priority) {

@ -196,7 +196,7 @@ class TaskViewHolder internal constructor(
DateUtilities.getTimeString(context, newDateTime(task.dueDate))
}
} else {
DateUtilities.getRelativeDateTime(context, task.dueDate, locale, FormatStyle.MEDIUM)
DateUtilities.getRelativeDateTime(context, task.dueDate, locale, FormatStyle.MEDIUM, preferences.alwaysDisplayFullDate, false)
}
dueDate.text = dateValue
dueDate.visibility = View.VISIBLE

@ -45,7 +45,7 @@ class TaskListViewModel @ViewModelInject constructor(
invalidate()
}
private fun removeObserver() = internal?.removeObserver(this)
private fun removeObserver() = internal?.removeObserver(this)
fun invalidate() {
AndroidUtilities.assertMainThread()

@ -192,8 +192,8 @@ internal class ScrollableViewsFactory(
}
}
private fun getDateString(value: Long, lowercase: Boolean = true) =
DateUtilities.getRelativeDay(context, value, locale.locale, FormatStyle.MEDIUM, lowercase)
private fun getDateString(value: Long, lowercase: Boolean = true, alwaysDisplayFullDate: Boolean = false) =
DateUtilities.getRelativeDay(context, value, locale.locale, FormatStyle.MEDIUM, alwaysDisplayFullDate, lowercase)
@StringRes
private fun priorityToString(priority: Int) = when (priority) {

@ -266,6 +266,9 @@ public class WidgetPreferences implements QueryPreferences {
return preferences.getShowCompletedTemporarily();
}
@Override
public boolean getAlwaysDisplayFullDate() { return getBoolean(R.string.p_always_display_full_date, false); }
@Override
public boolean usePagedQueries() {
return preferences.usePagedQueries();
@ -290,4 +293,9 @@ public class WidgetPreferences implements QueryPreferences {
public void setReverseSort(boolean isReverseSort) {
setBoolean(R.string.p_widget_sort_reverse, isReverseSort);
}
@Override
public void setAlwaysDisplayFullDate(boolean noWeekday) {
setBoolean(R.string.p_always_display_full_date, noWeekday);
}
}

@ -485,6 +485,7 @@
<string name="EPr_temp_show_completed_tasks">Aufgaben nach Erledigung noch vorübergehend anzeigen</string>
<string name="EPr_temp_completed_tasks_showing">Aufgaben bleiben nach Erledigung noch für eine kurze Zeit sichtbar</string>
<string name="EPr_temp_completed_tasks_not_showing">Aufgaben verschwinden sofort nach Erledigung</string>
<string name="always_display_full_date">Datum ganz anzeigen</string>
<plurals name="subtask_count">
<item quantity="one">%d Teilaufgabe</item>
<item quantity="other">%d Teilaufgaben</item>

@ -359,6 +359,7 @@
<string name="p_last_backup">last_backup</string>
<string name="p_show_description">show_description</string>
<string name="p_show_full_description">show_full_description</string>
<string name="p_always_display_full_date">always_display_full_date</string>
<string name="p_linkify_task_list">linkify_task_list</string>
<string name="p_linkify_task_edit">linkify_task_edit</string>
<string name="map_provider_mapbox">Mapbox</string>

@ -100,6 +100,7 @@ File %1$s contained %2$s.\n\n
<string name="EPr_temp_show_completed_tasks">Temporarily show tasks upon completion</string>
<string name="EPr_temp_completed_tasks_showing">Tasks will remain temporarily visible in the list after completion</string>
<string name="EPr_temp_completed_tasks_not_showing">Tasks will immediately disappear from the list after completion</string>
<string name="always_display_full_date">Show full date</string>
<string name="EPr_reset_preferences">Reset preferences</string>
<string name="EPr_reset_preferences_warning">Preferences will be reset to default values</string>
<string name="EPr_delete_task_data">Delete task data</string>

@ -78,6 +78,11 @@
android:key="@string/p_show_full_description"
android:title="@string/show_full_description" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/p_always_display_full_date"
android:title="@string/always_display_full_date" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/p_linkify_task_list"

Loading…
Cancel
Save