Skip to content

Commit

Permalink
plusonelabs#281 Add option "Show date on widget header"
Browse files Browse the repository at this point in the history
  • Loading branch information
yvolk committed Sep 12, 2019
1 parent 4ae37dd commit 02ae73a
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {

defaultConfig {
versionCode getCommitCount()
versionName '3.0.2' + "-" + versionCode
versionName '3.0.4' + "-" + versionCode
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
3 changes: 2 additions & 1 deletion app/src/main/res/layout/widget_header_one_row.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/action_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -10,7 +11,7 @@
style="@style/HeaderCurrentDate"
android:layout_width="0dp"
android:paddingTop="4dp"
android:text="@string/today"
tools:text="@string/today"
android:layout_height="wrap_content"
android:layout_weight="1" />

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/widget_header_two_rows.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/action_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -11,7 +12,7 @@
style="@style/HeaderCurrentDate"
android:layout_width="wrap_content"
android:paddingTop="4dp"
android:text="@string/today"
tools:text="@string/today"
android:layout_height="wrap_content" />

<LinearLayout
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<string name="app_description_4000_chars_max_part11">Indicators for alerts and recurring events.</string>
<string name="app_description_4000_chars_max_part12">Lock time zone when travelling to different time zones.</string>
<string name="app_description_4000_chars_max_part13">Turn off Day headers and see dates in the \"Days from today\" column.</string>
<string name="app_description_4000_chars_max_part14">Android 4 to 7 supported. Supports Android tablets.</string>
<string name="app_description_4000_chars_max_part14">Android 4 to 9 supported. Supports Android tablets.</string>

<!-- Preference header: Calendars and Task Lists -->
<string name="calendars_prefs">Calendars and Task Lists</string>
Expand Down Expand Up @@ -78,6 +78,7 @@
<string name="widget_header_layout">Widget header layout</string>
<string name="pref_event_entry_layout_title">Event entry layout</string>
<string name="default_multiline_layout">Time below title</string>
<string name="show_date_on_widget_header">Show date on widget header</string>
<string name="default_value">Default</string>
<string name="single_line_layout">All in one row</string>
<string name="two_rows_layout">Two rows layout</string>
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/xml/preferences_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
android:summary="@string/single_line_layout"
android:title="@string/widget_header_layout" />

<CheckBoxPreference
android:key="showDateOnWidgetHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultValue="true"
android:title="@string/show_date_on_widget_header">
</CheckBoxPreference>

<CheckBoxPreference
android:key="showDayHeaders"
android:layout_width="wrap_content"
Expand Down

0 comments on commit 02ae73a

Please sign in to comment.