Skip to content

Commit

Permalink
#15 Add "Compact layout" option. When it's turned on, most of spaces …
Browse files Browse the repository at this point in the history
…between Widget parts are removed.
  • Loading branch information
yvolk committed Aug 31, 2020
1 parent d88cc64 commit 4ac1c4a
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 16 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ If the problem is still present:
In a case the widget doesn't work properly even after this, please
[search, read and follow up on similar issues here](https://github.com/andstatus/todoagenda/issues?q=is%3Aissue+sort%3Aupdated-desc).

### 2020-08-29 <a id="v4.2"/> v4.2.0 Integration with "Tasks: Astrid To-Do List Clone" and with Google Tasks via it.
### 2020-08-31 <a id="v4.2"/> v4.2.1 Integration with "Tasks: Astrid To-Do List Clone" and with Google Tasks via it.
* Support of "[Tasks: Astrid To-Do List Clone v.10+](https://github.com/tasks/tasks#readme)"
not only gives us another app to manage tasks, but also allows to see Google tasks in our widget and manage them via the Tasks app.
Please note that this works only with "[Tasks app v.10+](https://github.com/tasks/tasks/blob/main/CHANGELOG.md)"
[#2](https://github.com/andstatus/todoagenda/issues/2).
* [Compact layout](https://github.com/andstatus/todoagenda/issues/15) option added.
When it's turned on, most of spaces between widget parts are removed.

### 2020-03-01 <a id="v4.0"/> v4.0.8 Three powerful date format preferences.
* This version is for Android 7+ only. Versions for older devices are still available e.g.
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
useLibrary 'android.test.mock'

defaultConfig {
versionCode 683
versionName '4.2.0'
versionCode 684
versionName '4.2.1'
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Map;

import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_ACTIVE_SOURCES;
import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_COMPACT_LAYOUT;
import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_DAY_HEADER_ALIGNMENT;
import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_DAY_HEADER_DATE_FORMAT;
import static org.andstatus.todoagenda.prefs.InstanceSettings.PREF_DAY_HEADER_DATE_FORMAT_DEFAULT;
Expand Down Expand Up @@ -119,6 +120,7 @@ public static void fromInstanceSettings(Context context, Integer widgetId) {
for (Map.Entry<TextShadingPref, TextShading> entry: settings.shadings.entrySet()) {
setString(context, entry.getKey().preferenceName, entry.getValue().name());
}
setBoolean(context, PREF_COMPACT_LAYOUT, settings.isCompactLayout());
setString(context, PREF_WIDGET_HEADER_LAYOUT, settings.getWidgetHeaderLayout().value);
setString(context, PREF_TEXT_SIZE_SCALE, settings.getTextSizeScale().preferenceValue);
setString(context, PREF_DAY_HEADER_ALIGNMENT, settings.getDayHeaderAlignment());
Expand Down Expand Up @@ -408,6 +410,10 @@ public static String getWidgetInstanceName(Context context) {
return getString(context, PREF_WIDGET_INSTANCE_NAME, "");
}

public static boolean isCompactLayout(Context context) {
return getBoolean(context, PREF_COMPACT_LAYOUT, false);
}

public static WidgetHeaderLayout getWidgetHeaderLayout(Context context) {
return WidgetHeaderLayout.fromValue(getString(context, PREF_WIDGET_HEADER_LAYOUT, ""));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class InstanceSettings {

// ----------------------------------------------------------------------------------
// Layout
static final String PREF_COMPACT_LAYOUT = "compactLayout";
private boolean compactLayout = false;
static final String PREF_WIDGET_HEADER_LAYOUT = "widgetHeaderLayout";
private WidgetHeaderLayout widgetHeaderLayout = WidgetHeaderLayout.defaultValue;
private static final String PREF_SHOW_DATE_ON_WIDGET_HEADER = "showDateOnWidgetHeader"; // till v 4.0
Expand Down Expand Up @@ -313,6 +315,9 @@ private InstanceSettings setFromJson(JSONObject json) {
TextShading.fromName(json.getString(pref.preferenceName), pref.defaultShading));
}
}
if (json.has(PREF_COMPACT_LAYOUT)) {
compactLayout = json.getBoolean(PREF_COMPACT_LAYOUT);
}
if (json.has(PREF_WIDGET_HEADER_LAYOUT)) {
widgetHeaderLayout = WidgetHeaderLayout.fromValue(json.getString(PREF_WIDGET_HEADER_LAYOUT));
}
Expand Down Expand Up @@ -371,6 +376,7 @@ static InstanceSettings fromApplicationPreferences(Context context, int widgetId
settings.filterMode = ApplicationPreferences.getFilterMode(context);
settings.indicateAlerts = ApplicationPreferences.getBoolean(context, PREF_INDICATE_ALERTS, true);
settings.indicateRecurring = ApplicationPreferences.getBoolean(context, PREF_INDICATE_RECURRING, false);
settings.compactLayout = ApplicationPreferences.isCompactLayout(context);
settings.widgetHeaderLayout = ApplicationPreferences.getWidgetHeaderLayout(context);
for (TextShadingPref pref: TextShadingPref.values()) {
String themeName = ApplicationPreferences.getString(context, pref.preferenceName,
Expand Down Expand Up @@ -462,6 +468,7 @@ public JSONObject toJson() {
json.put(PREF_FILTER_MODE, filterMode.value);
json.put(PREF_INDICATE_ALERTS, indicateAlerts);
json.put(PREF_INDICATE_RECURRING, indicateRecurring);
json.put(PREF_COMPACT_LAYOUT, compactLayout);
json.put(PREF_WIDGET_HEADER_LAYOUT, widgetHeaderLayout.value);
for (TextShadingPref pref: TextShadingPref.values()) {
json.put(pref.preferenceName, getShading(pref).name());
Expand Down Expand Up @@ -718,6 +725,10 @@ public ContextThemeWrapper getShadingContext(TextShadingPref pref) {
return new ContextThemeWrapper(context, getShading(pref).themeResId);
}

public boolean isCompactLayout() {
return compactLayout;
}

public WidgetHeaderLayout getWidgetHeaderLayout() {
return widgetHeaderLayout;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.andstatus.todoagenda.provider.EventProvider;
import org.andstatus.todoagenda.provider.EventProviderType;
import org.andstatus.todoagenda.util.MyClock;
import org.andstatus.todoagenda.util.RemoteViewsUtil;

import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -47,6 +48,11 @@ public RemoteViews getRemoteViews(WidgetEntry eventEntry, int position) {

ContextThemeWrapper shadingContext = getSettings().getShadingContext(TextShadingPref.forDayHeader(entry));
setBackgroundColor(rv, R.id.event_entry, getSettings().getEntryBackgroundColor(entry));
if (getSettings().isCompactLayout()) {
RemoteViewsUtil.setPadding(getSettings(), rv, R.id.event_entry, R.dimen.zero, R.dimen.zero, R.dimen.zero, R.dimen.zero);
} else {
RemoteViewsUtil.setPadding(getSettings(), rv, R.id.event_entry, R.dimen.calender_padding, R.dimen.zero, R.dimen.calender_padding, R.dimen.entry_bottom_padding);
}
setDayHeaderTitle(position, entry, rv, shadingContext);
setDayHeaderSeparator(position, rv, shadingContext);
return rv;
Expand All @@ -64,14 +70,19 @@ private void setDayHeaderTitle(int position, DayHeader entry, RemoteViews rv, Co
setTextSize(getSettings(), rv, R.id.day_header_title, R.dimen.day_header_title);
setTextColorFromAttr(shadingContext, rv, R.id.day_header_title, R.attr.dayHeaderTitle);

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);
if (getSettings().isCompactLayout()) {
setPadding(getSettings(), rv, R.id.day_header_title,
R.dimen.zero, R.dimen.zero, R.dimen.zero, R.dimen.zero);
} else {
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);
}
}

protected CharSequence getTitleString(DayHeader entry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public RemoteViews getRemoteViews(WidgetEntry entry, int position) {
setTime(entry, rv);

setIndicators(entry, rv);
if (getSettings().isCompactLayout()) {
RemoteViewsUtil.setPadding(getSettings(), rv, R.id.event_entry, R.dimen.zero, R.dimen.zero, R.dimen.zero, R.dimen.zero);
} else {
RemoteViewsUtil.setPadding(getSettings(), rv, R.id.event_entry, R.dimen.calender_padding, R.dimen.zero, R.dimen.calender_padding, R.dimen.entry_bottom_padding);
}
setBackgroundColor(rv, R.id.event_entry, getSettings().getEntryBackgroundColor(entry));
return rv;
}
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/layout/event_entry_one_line.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@
layout="@layout/event_entry_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/text_container"
android:layout_alignParentEnd="true"
android:layout_alignTop="@id/text_container"
/>
android:layout_alignTop="@id/text_container" />
</RelativeLayout>

</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<dimen name="zero">0dp</dimen>
<dimen name="widget_padding">0dp</dimen>
<dimen name="widget_header_title">14dp</dimen>
<dimen name="calender_padding">8dp</dimen>
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@
<string name="app_description_4000_chars_max_part14">Android 7+ supported. Supports Android tablets.</string>

<!-- Preference frame: Layout -->
<string name="layout_prefs_desc">Place, show and hide widget elements</string>
<string name="compact_layout_title">Compact layout</string>
<string name="compact_layout_off_desc">Normal space between widget parts</string>
<string name="compact_layout_on_desc">Minimum space between widget parts, thin borders</string>
<string name="layout_prefs_desc">Place, show and hide widget parts</string>
<string name="layout_prefs_title">Layout</string>
<string name="widget_header_layout">Widget header layout</string>
<string name="pref_event_entry_layout_title">Event entry layout</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/appwidget_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
android:initialLayout="@layout/widget_initial"
android:minWidth="250dp"
android:minHeight="110dp"
android:minResizeWidth="110dp"
android:minResizeWidth="40dp"
android:minResizeHeight="40dp"
android:previewImage="@drawable/calendar_widget_preview"
android:resizeMode="horizontal|vertical"
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
@@ -1,6 +1,15 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<org.andstatus.todoagenda.prefs.MultilineCheckBoxPreference
android:key="compactLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultValue="false"
android:summaryOn="@string/compact_layout_on_desc"
android:summaryOff="@string/compact_layout_off_desc"
android:title="@string/compact_layout_title" />

<PreferenceCategory app:title="@string/widget_header">
<ListPreference
android:key="widgetHeaderLayout"
Expand Down

0 comments on commit 4ac1c4a

Please sign in to comment.