From 02ae73ad72ecf6d96dc1baa47e9490be4f1627db Mon Sep 17 00:00:00 2001 From: Yuri Volkov Date: Thu, 12 Sep 2019 21:36:16 +0300 Subject: [PATCH] #281 Add option "Show date on widget header" --- app/build.gradle | 2 +- .../org/andstatus/todoagenda/AppWidgetProvider.java | 5 +++-- .../todoagenda/prefs/ApplicationPreferences.java | 6 ++++++ .../andstatus/todoagenda/prefs/InstanceSettings.java | 11 +++++++++++ app/src/main/res/layout/widget_header_one_row.xml | 3 ++- app/src/main/res/layout/widget_header_two_rows.xml | 3 ++- app/src/main/res/values/strings.xml | 3 ++- app/src/main/res/xml/preferences_layout.xml | 8 ++++++++ 8 files changed, 35 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 85ac4b4d..e9e9007c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,7 +8,7 @@ android { defaultConfig { versionCode getCommitCount() - versionName '3.0.2' + "-" + versionCode + versionName '3.0.4' + "-" + versionCode minSdkVersion rootProject.minSdkVersion targetSdkVersion rootProject.targetSdkVersion diff --git a/app/src/main/java/org/andstatus/todoagenda/AppWidgetProvider.java b/app/src/main/java/org/andstatus/todoagenda/AppWidgetProvider.java index d6778f72..72bb8dd0 100644 --- a/app/src/main/java/org/andstatus/todoagenda/AppWidgetProvider.java +++ b/app/src/main/java/org/andstatus/todoagenda/AppWidgetProvider.java @@ -138,8 +138,9 @@ private static void configureWidgetHeader(InstanceSettings settings, RemoteViews private static void configureCurrentDate(InstanceSettings settings, RemoteViews rv) { int viewId = R.id.calendar_current_date; rv.setOnClickPendingIntent(viewId, createOpenCalendarPendingIntent(settings)); - String formattedDate = DateUtil.createDateString(settings, - DateUtil.now(settings.getTimeZone())).toUpperCase(Locale.getDefault()); + String formattedDate = settings.getShowDateOnWidgetHeader() + ? DateUtil.createDateString(settings, DateUtil.now(settings.getTimeZone())).toUpperCase(Locale.getDefault()) + : " "; rv.setTextViewText(viewId, formattedDate); setTextSize(settings, rv, viewId, R.dimen.widget_header_title); setTextColorFromAttr(settings.getWidgetHeaderThemeContext(), rv, viewId, R.attr.header); diff --git a/app/src/main/java/org/andstatus/todoagenda/prefs/ApplicationPreferences.java b/app/src/main/java/org/andstatus/todoagenda/prefs/ApplicationPreferences.java index fc072be1..4ef3d91d 100644 --- a/app/src/main/java/org/andstatus/todoagenda/prefs/ApplicationPreferences.java +++ b/app/src/main/java/org/andstatus/todoagenda/prefs/ApplicationPreferences.java @@ -23,6 +23,7 @@ public class ApplicationPreferences { @Deprecated static final String PREF_SHOW_WIDGET_HEADER = "showHeader"; static final String PREF_WIDGET_HEADER_LAYOUT = "widgetHeaderLayout"; + static final String PREF_SHOW_DATE_ON_WIDGET_HEADER = "showDateOnWidgetHeader"; static final String PREF_MULTILINE_TITLE = "multiline_title"; static final boolean PREF_MULTILINE_TITLE_DEFAULT = false; static final String PREF_SHOW_DAYS_WITHOUT_EVENTS = "showDaysWithoutEvents"; @@ -95,6 +96,7 @@ private ApplicationPreferences() { public static void startEditing(Context context, Integer widgetId) { InstanceSettings settings = AllSettings.instanceFromId(context, widgetId); setWidgetId(context, widgetId == 0 ? settings.getWidgetId() : widgetId); + setBoolean(context, PREF_SHOW_DATE_ON_WIDGET_HEADER, settings.getShowDateOnWidgetHeader()); setString(context, PREF_WIDGET_INSTANCE_NAME, settings.getWidgetInstanceName()); setActiveEventSources(context, settings.getActiveEventSources()); setEventRange(context, settings.getEventRange()); @@ -369,4 +371,8 @@ public static String getWidgetInstanceName(Context context) { public static WidgetHeaderLayout getWidgetHeaderLayout(Context context) { return WidgetHeaderLayout.fromValue(getString(context, PREF_WIDGET_HEADER_LAYOUT, "")); } + + public static boolean getShowDateOnWidgetHeader(Context context) { + return getBoolean(context, PREF_SHOW_DATE_ON_WIDGET_HEADER, true); + } } diff --git a/app/src/main/java/org/andstatus/todoagenda/prefs/InstanceSettings.java b/app/src/main/java/org/andstatus/todoagenda/prefs/InstanceSettings.java index 60995425..54f83adf 100644 --- a/app/src/main/java/org/andstatus/todoagenda/prefs/InstanceSettings.java +++ b/app/src/main/java/org/andstatus/todoagenda/prefs/InstanceSettings.java @@ -51,6 +51,7 @@ import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_MULTILINE_TITLE_DEFAULT; import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_PAST_EVENTS_BACKGROUND_COLOR; import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_PAST_EVENTS_BACKGROUND_COLOR_DEFAULT; +import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_SHOW_DATE_ON_WIDGET_HEADER; import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_SHOW_DAYS_WITHOUT_EVENTS; import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_SHOW_DAY_HEADERS; import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_SHOW_END_TIME; @@ -97,6 +98,7 @@ public class InstanceSettings { private int pastEventsBackgroundColor = PREF_PAST_EVENTS_BACKGROUND_COLOR_DEFAULT; private int todaysEventsBackgroundColor = PREF_TODAYS_EVENTS_BACKGROUND_COLOR_DEFAULT; private int eventsBackgroundColor = PREF_EVENTS_BACKGROUND_COLOR_DEFAULT; + private boolean showDateOnWidgetHeader = true; private boolean showDaysWithoutEvents = false; private boolean showDayHeaders = true; private boolean showPastEventsUnderOneHeader = false; @@ -126,6 +128,9 @@ public static InstanceSettings fromJson(Context context, JSONObject json) throws if (settings.widgetId == 0) { return settings; } + if (json.has(PREF_SHOW_DATE_ON_WIDGET_HEADER)) { + settings.showDateOnWidgetHeader = json.getBoolean(PREF_SHOW_DATE_ON_WIDGET_HEADER); + } if (json.has(PREF_ACTIVE_SOURCES)) { JSONArray jsonArray = json.getJSONArray(PREF_ACTIVE_SOURCES); settings.setActiveEventSources(EventSource.fromJsonArray(jsonArray)); @@ -231,6 +236,7 @@ static InstanceSettings fromApplicationPreferences(Context context, int widgetId InstanceSettings settings = new InstanceSettings(context, widgetId, ApplicationPreferences.getString(context, PREF_WIDGET_INSTANCE_NAME, ApplicationPreferences.getString(context, PREF_WIDGET_INSTANCE_NAME, ""))); + settings.showDateOnWidgetHeader = ApplicationPreferences.getShowDateOnWidgetHeader(context); settings.setActiveEventSources(ApplicationPreferences.getActiveEventSources(context)); settings.eventRange = ApplicationPreferences.getEventRange(context); settings.eventsEnded = ApplicationPreferences.getEventsEnded(context); @@ -296,6 +302,7 @@ public JSONObject toJson() { JSONObject json = new JSONObject(); try { json.put(PREF_WIDGET_ID, widgetId); + json.put(PREF_SHOW_DATE_ON_WIDGET_HEADER, showDateOnWidgetHeader); json.put(PREF_WIDGET_INSTANCE_NAME, widgetInstanceName); json.put(PREF_ACTIVE_SOURCES, EventSource.toJsonArray(getActiveEventSources())); json.put(PREF_EVENT_RANGE, eventRange); @@ -536,4 +543,8 @@ public String getDayHeaderAlignment() { public void logMe(Class tag, String message, int widgetId) { Log.v(tag.getSimpleName(), message + ", widgetId:" + widgetId + "\n" + toJson()); } + + public boolean getShowDateOnWidgetHeader() { + return showDateOnWidgetHeader; + } } diff --git a/app/src/main/res/layout/widget_header_one_row.xml b/app/src/main/res/layout/widget_header_one_row.xml index 812f91dc..acb779e6 100644 --- a/app/src/main/res/layout/widget_header_one_row.xml +++ b/app/src/main/res/layout/widget_header_one_row.xml @@ -1,5 +1,6 @@ diff --git a/app/src/main/res/layout/widget_header_two_rows.xml b/app/src/main/res/layout/widget_header_two_rows.xml index dd37c9d4..edf1f590 100644 --- a/app/src/main/res/layout/widget_header_two_rows.xml +++ b/app/src/main/res/layout/widget_header_two_rows.xml @@ -1,5 +1,6 @@ Indicators for alerts and recurring events. Lock time zone when travelling to different time zones. Turn off Day headers and see dates in the \"Days from today\" column. - Android 4 to 7 supported. Supports Android tablets. + Android 4 to 9 supported. Supports Android tablets. Calendars and Task Lists @@ -78,6 +78,7 @@ Widget header layout Event entry layout Time below title + Show date on widget header Default All in one row Two rows layout diff --git a/app/src/main/res/xml/preferences_layout.xml b/app/src/main/res/xml/preferences_layout.xml index c592e86b..b5321930 100644 --- a/app/src/main/res/xml/preferences_layout.xml +++ b/app/src/main/res/xml/preferences_layout.xml @@ -8,6 +8,14 @@ android:summary="@string/single_line_layout" android:title="@string/widget_header_layout" /> + + +