diff --git a/app/src/main/java/com/todoroo/astrid/service/Upgrader.java b/app/src/main/java/com/todoroo/astrid/service/Upgrader.java index cf04d2be4..092d3183d 100644 --- a/app/src/main/java/com/todoroo/astrid/service/Upgrader.java +++ b/app/src/main/java/com/todoroo/astrid/service/Upgrader.java @@ -46,6 +46,8 @@ import org.tasks.data.UserActivityDao; import org.tasks.injection.ForApplication; import org.tasks.preferences.DefaultFilterProvider; import org.tasks.preferences.Preferences; +import org.tasks.widget.AppWidgetManager; +import org.tasks.widget.WidgetPreferences; public class Upgrader { @@ -62,6 +64,7 @@ public class Upgrader { public static final int V8_2 = 675; private static final int V8_5 = 700; private static final int V8_8 = 717; + private static final int V8_10 = 735; private final Context context; private final Preferences preferences; private final Tracker tracker; @@ -76,6 +79,7 @@ public class Upgrader { private final TaskDao taskDao; private final LocationDao locationDao; private final iCalendar iCal; + private final AppWidgetManager widgetManager; @Inject public Upgrader( @@ -92,7 +96,8 @@ public class Upgrader { CaldavDao caldavDao, TaskDao taskDao, LocationDao locationDao, - iCalendar iCal) { + iCalendar iCal, + AppWidgetManager widgetManager) { this.context = context; this.preferences = preferences; this.tracker = tracker; @@ -107,6 +112,7 @@ public class Upgrader { this.taskDao = taskDao; this.locationDao = locationDao; this.iCal = iCal; + this.widgetManager = widgetManager; } public void upgrade(int from, int to) { @@ -127,6 +133,7 @@ public class Upgrader { preferences.setBoolean(R.string.p_linkify_task_edit, true); preferences.setBoolean(R.string.p_auto_dismiss_datetime_edit_screen, true); }); + run(from, V8_10, this::migrateWidgets); } preferences.setCurrentVersion(to); } @@ -138,6 +145,13 @@ public class Upgrader { } } + private void migrateWidgets() { + for (int widgetId : widgetManager.getWidgetIds()) { + WidgetPreferences widgetPreferences = new WidgetPreferences(context, preferences, widgetId); + widgetPreferences.maintainExistingConfiguration(); + } + } + private void migrateColors() { preferences.setInt( R.string.p_theme_color, getAndroidColor(preferences.getInt(R.string.p_theme_color, 7))); diff --git a/app/src/main/java/org/tasks/widget/WidgetPreferences.java b/app/src/main/java/org/tasks/widget/WidgetPreferences.java index b47885067..34c4cdba3 100644 --- a/app/src/main/java/org/tasks/widget/WidgetPreferences.java +++ b/app/src/main/java/org/tasks/widget/WidgetPreferences.java @@ -51,8 +51,7 @@ public class WidgetPreferences { } public int getDueDatePosition() { - int defaultValue = getBoolean(R.string.p_widget_show_due_date, true) ? 0 : 2; - return getIntegerFromString(R.string.p_widget_due_date_position, defaultValue); + return getIntegerFromString(R.string.p_widget_due_date_position, 0); } int getWidgetSpacing() { @@ -92,29 +91,23 @@ public class WidgetPreferences { } int getHeaderOpacity() { - int headerOpacity = getInt(R.string.p_widget_header_opacity, -1); - return headerOpacity >= 0 && headerOpacity <= 100 - ? getAlphaValue(headerOpacity) - : getRowOpacity(); + return getAlphaValue(R.string.p_widget_header_opacity); } int getFooterOpacity() { - int footerOpacity = getInt(R.string.p_widget_footer_opacity, -1); - return footerOpacity >= 0 && footerOpacity <= 100 - ? getAlphaValue(footerOpacity) - : getRowOpacity(); + return getAlphaValue(R.string.p_widget_footer_opacity); } int getRowOpacity() { - return getAlphaValue(getInt(R.string.p_widget_opacity, 100)); + return getAlphaValue(R.string.p_widget_opacity); } boolean openOnEmptySpaceClick() { return getIntegerFromString(R.string.p_widget_empty_space_click, 0) == 1; } - private int getAlphaValue(int percentage) { - return (int) (percentage / 100.0 * 255.0); + private int getAlphaValue(int resId) { + return (int) (getInt(resId, 100) / 100.0 * 255.0); } public void setTheme(int index) { @@ -148,4 +141,24 @@ public class WidgetPreferences { private void setInt(int resId, int value) { preferences.setInt(getKey(resId), value); } + + private void setBoolean(int resId, boolean value) { + preferences.setBoolean(getKey(resId), value); + } + + private void setString(int resId, String value) { + preferences.setString(getKey(resId), value); + } + + public void maintainExistingConfiguration() { + int rowOpacity = getInt(R.string.p_widget_opacity, 100); + setInt(R.string.p_widget_header_opacity, rowOpacity); + setInt(R.string.p_widget_footer_opacity, rowOpacity); + boolean showDueDate = getBoolean(R.string.p_widget_show_due_date, true); + setString(R.string.p_widget_due_date_position, showDueDate ? "1" : "2"); // below or hidden + setBoolean(R.string.p_widget_show_dividers, false); // no dividers + setBoolean(R.string.p_widget_show_menu, false); // no menu + setString(R.string.p_widget_spacing, "1"); // compact + setBoolean(R.string.p_widget_show_description, false); // no description + } } diff --git a/app/src/main/res/layout/scrollable_widget.xml b/app/src/main/res/layout/scrollable_widget.xml index 7cb831f9b..8c4ea5cbd 100644 --- a/app/src/main/res/layout/scrollable_widget.xml +++ b/app/src/main/res/layout/scrollable_widget.xml @@ -54,7 +54,7 @@ android:layout_toEndOf="@id/widget_change_list" android:layout_toStartOf="@id/widget_reconfigure" android:ellipsize="end" - tools:text="Today" + tools:text="@string/BFE_Active" android:gravity="start|center_vertical" android:maxLines="2" android:textAlignment="viewStart"