Skip to content

Commit

Permalink
plusonelabs#174 Add option: "Show event icon" (Show Calendar color ba…
Browse files Browse the repository at this point in the history
…r / Task icon for event). True by default

plusonelabs#283 Add option: "Show number of days to event" (in the "All in one row" event layout)
  • Loading branch information
yvolk committed Aug 24, 2019
1 parent 9f2046e commit c8fe185
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ private void setIndicator(RemoteViews rv, boolean showIndication, int viewId, in
}

private void setColor(CalendarEntry entry, RemoteViews rv) {
setBackgroundColor(rv, R.id.event_entry_icon, entry.getColor());
if (getSettings().getShowEventIcon()) {
rv.setViewVisibility(R.id.event_entry_icon, View.VISIBLE);
setBackgroundColor(rv, R.id.event_entry_icon, entry.getColor());
} else {
rv.setViewVisibility(R.id.event_entry_icon, View.GONE);
}
if (entry.getEndDate().isBefore(DateUtil.now(entry.getEndDate().getZone()))) {
setBackgroundColor(rv, R.id.event_entry, getSettings().getPastEventsBackgroundColor());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class ApplicationPreferences {
static final String PREF_SHOW_PAST_EVENTS_WITH_DEFAULT_COLOR = "showPastEventsWithDefaultColor";
static final String PREF_PAST_EVENTS_BACKGROUND_COLOR = "pastEventsBackgroundColor";
static final int PREF_PAST_EVENTS_BACKGROUND_COLOR_DEFAULT = 0x4affff2b;
static final String PREF_SHOW_EVENT_ICON = "showEventIcon";
static final String PREF_SHOW_NUMBER_OF_DAYS_TO_EVENT = "showNumberOfDaysToEvent";
static final String PREF_HIDE_BASED_ON_KEYWORDS = "hideBasedOnKeywords";
static final String KEY_SHARE_EVENTS_FOR_DEBUGGING = "shareEventsForDebugging";
static final String PREF_ABBREVIATE_DATES = "abbreviateDates";
Expand Down Expand Up @@ -86,6 +88,8 @@ public static void startEditing(Context context, Integer widgetId) {
setShowDayHeaders(context, settings.getShowDayHeaders());
setShowPastEventsUnderOneHeader(context, settings.getShowPastEventsUnderOneHeader());
setShowPastEventsWithDefaultColor(context, settings.getShowPastEventsWithDefaultColor());
setShowEventIcon(context, settings.getShowEventIcon());
setShowNumberOfDaysToEvent(context, settings.getShowNumberOfDaysToEvent());
setBoolean(context, PREF_SHOW_END_TIME, settings.getShowEndTime());
setBoolean(context, PREF_SHOW_LOCATION, settings.getShowLocation());
setString(context, PREF_DATE_FORMAT, settings.getDateFormat());
Expand Down Expand Up @@ -210,6 +214,24 @@ private static void setShowPastEventsUnderOneHeader(Context context, boolean val
setBoolean(context, PREF_SHOW_PAST_EVENTS_UNDER_ONE_HEADER, value);
}

public static boolean getShowEventIcon(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(PREF_SHOW_EVENT_ICON, false);
}

public static boolean getShowNumberOfDaysToEvent(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(PREF_SHOW_NUMBER_OF_DAYS_TO_EVENT, false);
}

public static void setShowEventIcon(Context context, boolean value) {
setBoolean(context, PREF_SHOW_EVENT_ICON, value);
}

public static void setShowNumberOfDaysToEvent(Context context, boolean value) {
setBoolean(context, PREF_SHOW_NUMBER_OF_DAYS_TO_EVENT, value);
}

public static boolean getShowPastEventsWithDefaultColor(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(PREF_SHOW_PAST_EVENTS_WITH_DEFAULT_COLOR, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_SHOW_DAY_HEADERS;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_SHOW_END_TIME;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_SHOW_END_TIME_DEFAULT;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_SHOW_EVENT_ICON;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_SHOW_LOCATION;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_SHOW_LOCATION_DEFAULT;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_SHOW_NUMBER_OF_DAYS_TO_EVENT;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_SHOW_ONLY_CLOSEST_INSTANCE_OF_RECURRING_EVENT;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_SHOW_PAST_EVENTS_UNDER_ONE_HEADER;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_SHOW_PAST_EVENTS_WITH_DEFAULT_COLOR;
Expand Down Expand Up @@ -93,6 +95,8 @@ public class InstanceSettings {
private boolean showDayHeaders = true;
private boolean showPastEventsUnderOneHeader = false;
private boolean showPastEventsWithDefaultColor = false;
private boolean showNumberOfDaysToEvent = true;
private boolean showEventIcon = true;
private boolean showEndTime = PREF_SHOW_END_TIME_DEFAULT;
private boolean showLocation = PREF_SHOW_LOCATION_DEFAULT;
private String dateFormat = PREF_DATE_FORMAT_DEFAULT;
Expand Down Expand Up @@ -151,6 +155,12 @@ public static InstanceSettings fromJson(Context context, JSONObject json) throws
if (json.has(PREF_SHOW_PAST_EVENTS_WITH_DEFAULT_COLOR)) {
settings.showPastEventsWithDefaultColor = json.getBoolean(PREF_SHOW_PAST_EVENTS_WITH_DEFAULT_COLOR);
}
if (json.has(PREF_SHOW_EVENT_ICON)) {
settings.showEventIcon = json.getBoolean(PREF_SHOW_EVENT_ICON);
}
if (json.has(PREF_SHOW_NUMBER_OF_DAYS_TO_EVENT)) {
settings.showNumberOfDaysToEvent = json.getBoolean(PREF_SHOW_NUMBER_OF_DAYS_TO_EVENT);
}
if (json.has(PREF_SHOW_END_TIME)) {
settings.showEndTime = json.getBoolean(PREF_SHOW_END_TIME);
}
Expand Down Expand Up @@ -221,6 +231,8 @@ static InstanceSettings fromApplicationPreferences(Context context, int widgetId
settings.showDayHeaders = ApplicationPreferences.getShowDayHeaders(context);
settings.showPastEventsUnderOneHeader = ApplicationPreferences.getShowPastEventsUnderOneHeader(context);
settings.showPastEventsWithDefaultColor = ApplicationPreferences.getShowPastEventsWithDefaultColor(context);
settings.showEventIcon = ApplicationPreferences.getShowEventIcon(context);
settings.showNumberOfDaysToEvent = ApplicationPreferences.getShowNumberOfDaysToEvent(context);
settings.showEndTime = ApplicationPreferences.getShowEndTime(context);
settings.showLocation = ApplicationPreferences.getShowLocation(context);
settings.dateFormat = ApplicationPreferences.getDateFormat(context);
Expand Down Expand Up @@ -285,6 +297,8 @@ public JSONObject toJson() {
json.put(PREF_SHOW_DAY_HEADERS, showDayHeaders);
json.put(PREF_SHOW_PAST_EVENTS_UNDER_ONE_HEADER, showPastEventsUnderOneHeader);
json.put(PREF_SHOW_PAST_EVENTS_WITH_DEFAULT_COLOR, showPastEventsWithDefaultColor);
json.put(PREF_SHOW_EVENT_ICON, showEventIcon);
json.put(PREF_SHOW_NUMBER_OF_DAYS_TO_EVENT, showNumberOfDaysToEvent);
json.put(PREF_SHOW_END_TIME, showEndTime);
json.put(PREF_SHOW_LOCATION, showLocation);
json.put(PREF_DATE_FORMAT, dateFormat);
Expand Down Expand Up @@ -379,6 +393,14 @@ public boolean getShowPastEventsWithDefaultColor() {
return showPastEventsWithDefaultColor;
}

public boolean getShowNumberOfDaysToEvent() {
return showNumberOfDaysToEvent;
}

public boolean getShowEventIcon() {
return showEventIcon;
}

public boolean getShowEndTime() {
return showEndTime;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ public RemoteViews getRemoteView(WidgetEntry eventEntry) {
}

private void setColor(TaskEntry entry, RemoteViews rv) {
rv.setTextColor(R.id.event_entry_icon, entry.getEvent().getColor());
if (getSettings().getShowEventIcon()) {
rv.setViewVisibility(R.id.event_entry_icon, View.VISIBLE);
rv.setTextColor(R.id.event_entry_icon, entry.getEvent().getColor());
} else {
rv.setViewVisibility(R.id.event_entry_icon, View.GONE);
}
if (entry.getEvent().getDueDate().isBefore(DateUtil.now(entry.getEvent().getDueDate().getZone()))) {
setBackgroundColor(rv, R.id.event_entry, getSettings().getPastEventsBackgroundColor());
} else {
Expand All @@ -55,25 +60,27 @@ private void setDaysToEvent(TaskEntry entry, RemoteViews rv) {
rv.setViewVisibility(R.id.task_one_line_days_right, View.GONE);
rv.setViewVisibility(R.id.task_one_line_spacer, View.GONE);
} else {
if (getSettings().getShowDayHeaders()) {
rv.setViewVisibility(R.id.task_one_line_days, View.GONE);
rv.setViewVisibility(R.id.task_one_line_days_right, View.GONE);
rv.setViewVisibility(R.id.task_one_line_spacer, View.VISIBLE);
} else {
if (getSettings().getShowNumberOfDaysToEvent()) {
int days = entry.getDaysFromToday();
int viewToShow = days < -1 || days > 1 ? R.id.task_one_line_days_right : R.id.task_one_line_days;
int viewToHide = viewToShow == R.id.task_one_line_days ? R.id.task_one_line_days_right : R.id.task_one_line_days;
rv.setViewVisibility(viewToHide, View.GONE);
rv.setViewVisibility(viewToShow, View.VISIBLE);
rv.setTextViewText(viewToShow, DateUtil.getDaysFromTodayString(getSettings().getEntryThemeContext(), days));
rv.setViewVisibility(R.id.task_one_line_spacer, View.VISIBLE);
} else {
rv.setViewVisibility(R.id.task_one_line_days, View.GONE);
rv.setViewVisibility(R.id.task_one_line_days_right, View.GONE);
rv.setViewVisibility(R.id.task_one_line_spacer, View.VISIBLE);
}
}
}

private void setTitle(TaskEntry entry, RemoteViews rv) {
rv.setTextViewText(R.id.event_entry_title, entry.getTitle());
setTextSize(getSettings(), rv, R.id.event_entry_icon, R.dimen.event_entry_title);
if (getSettings().getShowEventIcon()) {
setTextSize(getSettings(), rv, R.id.event_entry_icon, R.dimen.event_entry_title);
}
setTextSize(getSettings(), rv, R.id.event_entry_title, R.dimen.event_entry_title);
setTextColorFromAttr(getSettings().getEntryThemeContext(), rv, R.id.event_entry_title, R.attr.eventEntryTitle);
setMultiline(rv, R.id.event_entry_title, getSettings().isTitleMultiline());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ protected String getTitleString(CalendarEntry event) {

@Override
protected void setEventDate(CalendarEntry entry, RemoteViews rv) {
if (entry.getSettings().getShowDayHeaders()) {
rv.setViewVisibility(R.id.event_entry_date, View.GONE);
rv.setViewVisibility(R.id.event_entry_date_right, View.GONE);
} else {
if (entry.getSettings().getShowNumberOfDaysToEvent()) {
int days = entry.getDaysFromToday();
int viewToShow = days < -1 || days > 1 ? R.id.event_entry_date_right : R.id.event_entry_date;
int viewToHide = viewToShow == R.id.event_entry_date ? R.id.event_entry_date_right : R.id.event_entry_date;
rv.setViewVisibility(viewToHide, View.GONE);
rv.setViewVisibility(viewToShow, View.VISIBLE);
rv.setTextViewText(viewToShow, DateUtil.getDaysFromTodayString(entry.getSettings().getEntryThemeContext(), days));
} else {
rv.setViewVisibility(R.id.event_entry_date, View.GONE);
rv.setViewVisibility(R.id.event_entry_date_right, View.GONE);
}
}

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
<string name="appearance_display_header_desc">Show the date and settings header</string>
<string name="show_past_events_under_one_header_title">Header for past/due events</string>
<string name="show_past_events_under_one_header_desc">Show all past/due events under one "Past and due" header</string>
<string name="show_event_icon_title">Show event icon</string>
<string name="show_event_icon_desc">Show Calendar color bar / Task icon for event</string>
<string name="show_number_of_days_to_event_title">Show number of days to event</string>
<string name="show_number_of_days_to_event_desc">Show column with a number of days to event in the \"All in one row\" event layout</string>

<!-- Preference header: Colors -->
<string name="appearance_group_color_title">Colors</string>
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/xml/preferences_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@
android:summary="@string/default_multiline_layout"
android:title="@string/pref_event_entry_layout_title" />

<CheckBoxPreference
android:key="showEventIcon"
android:defaultValue="true"
android:summary="@string/show_event_icon_desc"
android:title="@string/show_event_icon_title">
</CheckBoxPreference>

<CheckBoxPreference
android:key="showNumberOfDaysToEvent"
android:defaultValue="true"
android:summary="@string/show_number_of_days_to_event_desc"
android:title="@string/show_number_of_days_to_event_title">
</CheckBoxPreference>

<CheckBoxPreference
android:key="multiline_title"
android:defaultValue="false"
Expand Down

0 comments on commit c8fe185

Please sign in to comment.