Skip to content

Commit

Permalink
plusonelabs#326 Add option "Horizontal line below Day header", false …
Browse files Browse the repository at this point in the history
…by default.
  • Loading branch information
yvolk committed Sep 28, 2019
1 parent bf8d83a commit c8924b6
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 74 deletions.
17 changes: 8 additions & 9 deletions app/src/main/java/org/andstatus/todoagenda/Alignment.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package org.andstatus.todoagenda;

import android.view.Gravity;

public enum Alignment {

LEFT(R.layout.day_header_left),
CENTER(R.layout.day_header_center),
RIGHT(R.layout.day_header_right);
LEFT(Gravity.LEFT),
CENTER(android.view.Gravity.CENTER),
RIGHT(Gravity.RIGHT);

private int layoutId;
public final int gravity;

Alignment(int layoutId) {
this.layoutId = layoutId;
Alignment(int gravity) {
this.gravity = gravity;
}

public int getLayoutId() {
return layoutId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_FILL_ALL_DAY;
import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_FILL_ALL_DAY_DEFAULT;
import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_HIDE_BASED_ON_KEYWORDS;
import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_HORIZONTAL_LINE_BELOW_DAY_HEADER;
import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_INDICATE_ALERTS;
import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_INDICATE_RECURRING;
import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_LOCKED_TIME_ZONE_ID;
Expand Down Expand Up @@ -79,6 +80,7 @@ public static void fromInstanceSettings(Context context, Integer widgetId) {
setInt(context, PREF_EVENTS_BACKGROUND_COLOR, settings.getEventsBackgroundColor());
setShowDaysWithoutEvents(context, settings.getShowDaysWithoutEvents());
setShowDayHeaders(context, settings.getShowDayHeaders());
setHorizontalLineBelowDayHeader(context, settings.getHorizontalLineBelowDayHeader());
setShowPastEventsUnderOneHeader(context, settings.getShowPastEventsUnderOneHeader());
setShowPastEventsWithDefaultColor(context, settings.getShowPastEventsWithDefaultColor());
setShowEventIcon(context, settings.getShowEventIcon());
Expand Down Expand Up @@ -196,6 +198,15 @@ public static int getEventsBackgroundColor(Context context) {
PREF_EVENTS_BACKGROUND_COLOR_DEFAULT);
}

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

private static void setHorizontalLineBelowDayHeader(Context context, boolean value) {
setBoolean(context, PREF_HORIZONTAL_LINE_BELOW_DAY_HEADER, value);
}

public static boolean getShowDaysWithoutEvents(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(PREF_SHOW_DAYS_WITHOUT_EVENTS, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public class InstanceSettings {
static final String PREF_DAY_HEADER_ALIGNMENT = "dayHeaderAlignment";
private static final String PREF_DAY_HEADER_ALIGNMENT_DEFAULT = Alignment.RIGHT.name();
private String dayHeaderAlignment = PREF_DAY_HEADER_ALIGNMENT_DEFAULT;
static final String PREF_HORIZONTAL_LINE_BELOW_DAY_HEADER = "horizontalLineBelowDayHeader";
private boolean horizontalLineBelowDayHeader = false;
static final String PREF_SHOW_DAYS_WITHOUT_EVENTS = "showDaysWithoutEvents";
private boolean showDaysWithoutEvents = false;
static final String PREF_EVENT_ENTRY_LAYOUT = "eventEntryLayout";
Expand Down Expand Up @@ -185,6 +187,9 @@ public static InstanceSettings fromJson(Context context, JSONObject json) throws
if (json.has(PREF_SHOW_DAY_HEADERS)) {
settings.showDayHeaders = json.getBoolean(PREF_SHOW_DAY_HEADERS);
}
if (json.has(PREF_HORIZONTAL_LINE_BELOW_DAY_HEADER)) {
settings.horizontalLineBelowDayHeader = json.getBoolean(PREF_HORIZONTAL_LINE_BELOW_DAY_HEADER);
}
if (json.has(PREF_SHOW_PAST_EVENTS_UNDER_ONE_HEADER)) {
settings.showPastEventsUnderOneHeader = json.getBoolean(PREF_SHOW_PAST_EVENTS_UNDER_ONE_HEADER);
}
Expand Down Expand Up @@ -263,6 +268,7 @@ static InstanceSettings fromApplicationPreferences(Context context, int widgetId
settings.eventsBackgroundColor = ApplicationPreferences.getEventsBackgroundColor(context);
settings.showDaysWithoutEvents = ApplicationPreferences.getShowDaysWithoutEvents(context);
settings.showDayHeaders = ApplicationPreferences.getShowDayHeaders(context);
settings.horizontalLineBelowDayHeader = ApplicationPreferences.getHorizontalLineBelowDayHeader(context);
settings.showPastEventsUnderOneHeader = ApplicationPreferences.getShowPastEventsUnderOneHeader(context);
settings.showPastEventsWithDefaultColor = ApplicationPreferences.getShowPastEventsWithDefaultColor(context);
settings.showEventIcon = ApplicationPreferences.getShowEventIcon(context);
Expand Down Expand Up @@ -333,6 +339,7 @@ public JSONObject toJson() {
json.put(PREF_EVENTS_BACKGROUND_COLOR, eventsBackgroundColor);
json.put(PREF_SHOW_DAYS_WITHOUT_EVENTS, showDaysWithoutEvents);
json.put(PREF_SHOW_DAY_HEADERS, showDayHeaders);
json.put(PREF_HORIZONTAL_LINE_BELOW_DAY_HEADER, horizontalLineBelowDayHeader);
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);
Expand Down Expand Up @@ -539,6 +546,10 @@ public String getDayHeaderAlignment() {
return dayHeaderAlignment;
}

public boolean getHorizontalLineBelowDayHeader() {
return horizontalLineBelowDayHeader;
}

public void logMe(Class tag, String message, int widgetId) {
Log.v(tag.getSimpleName(), message + ", widgetId:" + widgetId + "\n" + toJson());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,69 @@

public class DayHeaderVisualizer extends WidgetEntryVisualizer<DayHeader> {

private final Alignment alignment;
private final boolean horizontalLineBelowDayHeader;

public DayHeaderVisualizer(Context context, int widgetId) {
super(new EventProvider(EventProviderType.EMPTY, context, widgetId));
alignment = Alignment.valueOf(getSettings().getDayHeaderAlignment());
horizontalLineBelowDayHeader = getSettings().getHorizontalLineBelowDayHeader();
}

@Override
public RemoteViews getRemoteViews(WidgetEntry eventEntry, int position) {
if(!(eventEntry instanceof DayHeader)) return null;

DayHeader entry = (DayHeader) eventEntry;
String alignment = getSettings().getDayHeaderAlignment();
RemoteViews rv = new RemoteViews(getContext().getPackageName(), Alignment.valueOf(alignment).getLayoutId());
RemoteViews rv = new RemoteViews(getContext().getPackageName(), horizontalLineBelowDayHeader
? R.layout.day_header_separator_below : R.layout.day_header_separator_above);
rv.setInt(R.id.day_header_title_wrapper, "setGravity", alignment.gravity);

ContextThemeWrapper shadingContext = getSettings().getShadingContext(TextShadingPref.getDayHeader(entry));
setBackgroundColor(rv, R.id.day_header, getSettings().getEntryBackgroundColor(entry));
setDayHeaderTitle(position, entry, rv, shadingContext);
setDayHeaderSeparator(position, rv, shadingContext);
Intent intent = createOpenCalendarAtDayIntent(entry.getStartDate());
rv.setOnClickFillInIntent(R.id.day_header, intent);
return rv;
}

private void setDayHeaderTitle(int position, DayHeader entry, RemoteViews rv, ContextThemeWrapper shadingContext) {
String dateString = (entry.getStartDate().equals(DateUtil.DATETIME_MIN)
? getContext().getString(R.string.past_header)
: DateUtil.createDayHeaderTitle(getSettings(), entry.getStartDate()))
.toUpperCase(Locale.getDefault());
rv.setTextViewText(R.id.day_header_title, dateString);
setTextSize(getSettings(), rv, R.id.day_header_title, R.dimen.day_header_title);
setBackgroundColor(rv, R.id.day_header, getSettings().getEntryBackgroundColor(entry));
ContextThemeWrapper shadingContext = getSettings().getShadingContext(TextShadingPref.getDayHeader(entry));
setTextColorFromAttr(shadingContext, rv, R.id.day_header_title, R.attr.dayHeaderTitle);
if (position == 0) {
rv.setViewVisibility(R.id.day_header_separator, View.GONE);

int paddingTopId = horizontalLineBelowDayHeader
? R.dimen.day_header_padding_bottom
: (position == 0 ? R.dimen.day_header_padding_top_first : R.dimen.day_header_padding_top);
int paddingBottomId = horizontalLineBelowDayHeader
? R.dimen.day_header_padding_top
: R.dimen.day_header_padding_bottom;
setPadding(getSettings(), rv, R.id.day_header_title,
R.dimen.day_header_padding_left, paddingTopId, R.dimen.day_header_padding_right, paddingBottomId);
}

private void setDayHeaderSeparator(int position, RemoteViews rv, ContextThemeWrapper shadingContext) {
int viewId = R.id.day_header_separator;
if (horizontalLineBelowDayHeader) {
setBackgroundColorFromAttr(shadingContext, rv, viewId, R.attr.dayHeaderSeparator);
} else {
rv.setViewVisibility(R.id.day_header_separator, View.VISIBLE);
setBackgroundColorFromAttr(shadingContext, rv, R.id.day_header_separator, R.attr.dayHeaderSeparator);
if (position == 0) {
rv.setViewVisibility(viewId, View.GONE);
} else {
rv.setViewVisibility(viewId, View.VISIBLE);
setBackgroundColorFromAttr(shadingContext, rv, viewId, R.attr.dayHeaderSeparator);
}
}
setPadding(getSettings(), rv, R.id.day_header_title,
R.dimen.day_header_padding_left,
position == 0 ? R.dimen.day_header_padding_top_first : R.dimen.day_header_padding_top,
R.dimen.day_header_padding_right, R.dimen.day_header_padding_bottom);
Intent intent = createOpenCalendarAtDayIntent(entry.getStartDate());
rv.setOnClickFillInIntent(R.id.day_header, intent);
return rv;
}

@Override
public int getViewTypeCount() {
return 3; // we have 3 because of the "left", "right" and "center" day headers
return 2; // we have 2 because of top and botton separator placement
}

@Override
Expand Down
28 changes: 0 additions & 28 deletions app/src/main/res/layout/day_header_right.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,23 @@
<TextView
android:id="@+id/day_header_separator"
style="@style/DayHeaderSeparator"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="1dp"
tools:ignore="SelectableText" />

<TextView
android:id="@+id/day_header_title"
style="@style/DayHeaderTitle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
tools:ignore="SelectableText" />
<LinearLayout
android:id="@+id/day_header_title_wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/day_header_title"
style="@style/DayHeaderTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="SATURDAY, SEPTEMBER 28"
tools:ignore="SelectableText" />
</LinearLayout>

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,26 @@
android:paddingRight="@dimen/calender_padding"
android:paddingBottom="@dimen/entry_bottom_padding">

<LinearLayout
android:id="@+id/day_header_title_wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/day_header_title"
style="@style/DayHeaderTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="SATURDAY, SEPTEMBER 28"
tools:ignore="SelectableText" />
</LinearLayout>

<TextView
android:id="@+id/day_header_separator"
style="@style/DayHeaderSeparator"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="1dp"
tools:ignore="SelectableText" />

<TextView
android:id="@+id/day_header_title"
style="@style/DayHeaderTitle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="left"
tools:ignore="SelectableText" />

</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<string name="appearance_day_header_alignment_left">Left</string>
<string name="appearance_day_header_alignment_center">Center</string>
<string name="appearance_day_header_alignment_right">Right</string>
<string name="horizontalLineBelowDayHeader">Horizontal line below Day header</string>
<string name="appearance_multiline_title_title">Multiline title</string>
<string name="appearance_multiline_title_desc">Spread event title over multiple lines</string>
<string name="appearance_show_days_without_events_title">Show days without events</string>
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@

<style name="DayHeaderTitle" parent="android:Widget.Holo.TextView">
<item name="android:ellipsize">marquee</item>
<item name="android:gravity">right|top</item>
<item name="android:paddingBottom">@dimen/day_header_padding_bottom</item>
<item name="android:paddingRight">@dimen/day_header_padding_right</item>
<item name="android:paddingTop">@dimen/day_header_padding_top</item>
<item name="android:singleLine">true</item>
<item name="android:textColor">@color/day_header_title_black</item>
<item name="android:textStyle">bold</item>
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/xml/preferences_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@
android:summary="@string/appearance_day_header_alignment_desc"
android:title="@string/appearance_day_header_alignment_title" />

<CheckBoxPreference
android:key="horizontalLineBelowDayHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultValue="false"
android:title="@string/horizontalLineBelowDayHeader"
android:dependency="showDayHeaders">
</CheckBoxPreference>

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

0 comments on commit c8924b6

Please sign in to comment.