Skip to content

Commit 643e26d

Browse files
show due date in the search result activity, for #569
1 parent 4d78b2b commit 643e26d

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

app/src/main/java/com/nononsenseapps/helpers/TimeFormatter.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.nononsenseapps.helpers;
1919

2020
import android.content.Context;
21+
import android.content.SharedPreferences;
2122

2223
import androidx.preference.PreferenceManager;
2324

@@ -182,8 +183,7 @@ public static SimpleDateFormat getDateFormatter(final Context context) {
182183
context.getString(R.string.dateformat_just_date));
183184
}
184185

185-
public static SimpleDateFormat getLocalFormatterLongDateOnly(
186-
final Context context) {
186+
public static SimpleDateFormat getLocalFormatterLongDateOnly(final Context context) {
187187
return getLocalFormatter(
188188
context,
189189
PreferenceManager.getDefaultSharedPreferences(context)
@@ -211,18 +211,21 @@ public static SimpleDateFormat getLocalFormatterShort(final Context context) {
211211
withSuitableTime(context, userDateFormat)); // <-- notice this
212212
}
213213

214+
/**
215+
* Returns the format chosen by the user to show dates in the list view. For example,
216+
* a timestamp 1754752027 could be displayed as "sat 9 aug 2025" or "sat, 9 aug"
217+
*/
214218
public static SimpleDateFormat getLocalFormatterShortDateOnly(final Context context) {
215-
return getLocalFormatter(
216-
context,
217-
PreferenceManager.getDefaultSharedPreferences(context)
218-
.getString(context.getString(R.string.pref_locale), ""),
219+
220+
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
221+
String userFavLocale = pref.getString(context.getString(R.string.pref_locale), "");
222+
String userFavShortDateFormat = pref.getString(
223+
context.getString(R.string.key_pref_dateformat_short),
224+
context.getString(R.string.dateformat_short_2));
225+
226+
return getLocalFormatter(context, userFavLocale,
219227
withSuitableDateOnly( // <-- notice this!
220-
context,
221-
PreferenceManager
222-
.getDefaultSharedPreferences(context)
223-
.getString(
224-
context.getString(R.string.key_pref_dateformat_short),
225-
context.getString(R.string.dateformat_short_1))));
228+
context, userFavShortDateFormat));
226229
}
227230

228231
public static SimpleDateFormat getLocalFormatterMicro(final Context context) {

app/src/main/java/com/nononsenseapps/notepad/fragments/FragmentSearch.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ protected SimpleCursorAdapter getAdapter() {
213213
null,
214214
new String[] { Task.Columns.TITLE, Task.Columns.NOTE, Task.Columns.DUE,
215215
Task.Columns.COMPLETED, Task.Columns.LEFT, Task.Columns.RIGHT },
216+
// in tasklist_idem_card_selection.xml, the due date is displayed in a DateView
217+
// with ID = "date", so here Task.Columns.DUE is bound to R.id.date
216218
new int[] { android.R.id.text1, android.R.id.text1, R.id.date, R.id.checkbox,
217219
R.id.drag_handle, R.id.dragpadding },
218220
0);
@@ -242,7 +244,7 @@ protected ViewBinder getViewBinder() {
242244
// Matches order in Task.Columns.Fields
243245
case 1 -> {
244246
// Title
245-
String sTemp = c.getString(colIndex);
247+
String sTemp = c.getString(1);
246248

247249
// Set height of text for non-headers
248250
if (rowCount == 1) {
@@ -266,8 +268,21 @@ protected ViewBinder getViewBinder() {
266268
}
267269
return true;
268270
}
271+
case 4 -> {
272+
// DateView
273+
if (!c.isNull(4)) {
274+
// there IS a due date saved in the dabase for this note
275+
long dueDate = c.getLong(4);
276+
((com.nononsenseapps.ui.DateView) view).setTimeText(dueDate);
277+
view.setVisibility(View.VISIBLE);
278+
} else {
279+
// visibility of the DateView defaults to GONE
280+
// in tasklist_idem_card_selection.xml
281+
}
282+
return true;
283+
}
269284
default -> {
270-
// Checkbox
285+
// Checkbox, DragGripView, DragPadding; as defined in getAdapter() in this file
271286
view.setVisibility(View.GONE);
272287
return true;
273288
}

app/src/main/java/com/nononsenseapps/ui/DateView.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
*/
3737
public class DateView extends AppCompatTextView {
3838

39-
// TODO everything in this "ui" namespace could be moved to its own
40-
// gradle module. This would speed up builds, but maybe it's harder to manage?
39+
// TODO everything in this "ui" namespace should be moved to its own gradle module
4140

4241
private static final int SECONDS_PER_DAY = 3600;
4342

0 commit comments

Comments
 (0)