diff --git a/app/src/main/java/org/tasks/tasklist/AdapterSection.kt b/app/src/main/java/org/tasks/tasklist/AdapterSection.kt index 343017e5c..b4776a7b7 100644 --- a/app/src/main/java/org/tasks/tasklist/AdapterSection.kt +++ b/app/src/main/java/org/tasks/tasklist/AdapterSection.kt @@ -30,7 +30,8 @@ data class AdapterSection( locale: Locale, sortMode: Int, alwaysDisplayFullDate: Boolean, - style: FormatStyle = FormatStyle.FULL + style: FormatStyle = FormatStyle.FULL, + compact: Boolean = false ): String = when { sortMode == SORT_IMPORTANCE -> context.getString(priorityToString()) @@ -41,13 +42,18 @@ data class AdapterSection( }) else -> { val dateString = DateUtilities.getRelativeDay( - context, value, locale, style, alwaysDisplayFullDate, true + context, value, locale, style, alwaysDisplayFullDate, !compact ) - when (sortMode) { - SORT_DUE -> context.getString(R.string.sort_due_group, dateString) - SORT_START -> context.getString(R.string.sort_start_group, dateString) - SORT_CREATED -> context.getString(R.string.sort_created_group, dateString) - SORT_MODIFIED -> context.getString(R.string.sort_modified_group, dateString) + when { + compact -> dateString + sortMode == SORT_DUE -> + context.getString(R.string.sort_due_group, dateString) + sortMode == SORT_START -> + context.getString(R.string.sort_start_group, dateString) + sortMode == SORT_CREATED -> + context.getString(R.string.sort_created_group, dateString) + sortMode == SORT_MODIFIED -> + context.getString(R.string.sort_modified_group, dateString) else -> throw IllegalArgumentException() } } diff --git a/app/src/main/java/org/tasks/widget/ScrollableViewsFactory.kt b/app/src/main/java/org/tasks/widget/ScrollableViewsFactory.kt index 684ccbbd8..42fbca5fa 100644 --- a/app/src/main/java/org/tasks/widget/ScrollableViewsFactory.kt +++ b/app/src/main/java/org/tasks/widget/ScrollableViewsFactory.kt @@ -74,6 +74,7 @@ internal class ScrollableViewsFactory( private val widgetPreferences = WidgetPreferences(context, preferences, widgetId) private var isDark = checkIfDark private var showFullDate = false + private var compact = false private val checkIfDark: Boolean get() = when (widgetPreferences.themeIndex) { @@ -135,7 +136,14 @@ internal class ScrollableViewsFactory( val section = tasks.getSection(position) val sortGroup = section.value val header: String? = if (filter?.supportsSorting() == true) { - section.headerString(context, locale.locale, sortMode, showFullDate, FormatStyle.MEDIUM) + section.headerString( + context, + locale.locale, + sortMode, + showFullDate, + FormatStyle.MEDIUM, + compact + ) } else { null } @@ -350,6 +358,7 @@ internal class ScrollableViewsFactory( } collapsed = widgetPreferences.collapsed isRtl = locale.directionality == View.LAYOUT_DIRECTION_RTL + compact = widgetPreferences.compact } init { diff --git a/app/src/main/java/org/tasks/widget/TasksWidget.kt b/app/src/main/java/org/tasks/widget/TasksWidget.kt index 46100ae6a..c984bd23e 100644 --- a/app/src/main/java/org/tasks/widget/TasksWidget.kt +++ b/app/src/main/java/org/tasks/widget/TasksWidget.kt @@ -6,6 +6,7 @@ import android.appwidget.AppWidgetProvider import android.content.Context import android.content.Intent import android.net.Uri +import android.os.Bundle import android.view.View import android.widget.RemoteViews import androidx.annotation.ColorInt @@ -35,15 +36,30 @@ class TasksWidget : AppWidgetProvider() { override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) { for (id in appWidgetIds) { try { - appWidgetManager.updateAppWidget(id, createScrollableWidget(context, id)) + val options = appWidgetManager.getAppWidgetOptions(id) + appWidgetManager.updateAppWidget(id, createScrollableWidget(context, id, options)) } catch (e: Exception) { Timber.e(e) } } } - private fun createScrollableWidget(context: Context, id: Int): RemoteViews { + override fun onAppWidgetOptionsChanged( + context: Context, + appWidgetManager: AppWidgetManager, + appWidgetId: Int, + newOptions: Bundle? + ) { + newOptions?.let { + appWidgetManager + .updateAppWidget(appWidgetId, createScrollableWidget(context, appWidgetId, it)) + } + } + + private fun createScrollableWidget(context: Context, id: Int, options: Bundle): RemoteViews { val widgetPreferences = WidgetPreferences(context, preferences, id) + widgetPreferences.compact = + options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH) < COMPACT_MAX val filterId = widgetPreferences.filterId val color = ThemeColor(context, widgetPreferences.color) val remoteViews = RemoteViews(context.packageName, R.layout.scrollable_widget) @@ -168,6 +184,7 @@ class TasksWidget : AppWidgetProvider() { } companion object { + private const val COMPACT_MAX = 275 private const val flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP private val buttons = intArrayOf( R.id.widget_change_list, R.id.widget_button, R.id.widget_reconfigure diff --git a/app/src/main/java/org/tasks/widget/WidgetPreferences.java b/app/src/main/java/org/tasks/widget/WidgetPreferences.java index bac3721e9..6799d4a12 100644 --- a/app/src/main/java/org/tasks/widget/WidgetPreferences.java +++ b/app/src/main/java/org/tasks/widget/WidgetPreferences.java @@ -199,6 +199,14 @@ public class WidgetPreferences implements QueryPreferences { preferences.setString(getKey(R.string.p_widget_filter), filterPreferenceValue); } + public boolean getCompact() { + return getBoolean(R.string.p_widget_compact, false); + } + + public void setCompact(boolean value) { + setBoolean(R.string.p_widget_compact, value); + } + private int getInt(int resId, int defValue) { return preferences.getInt(getKey(resId), defValue); } diff --git a/app/src/main/res/layout/widget_header_dark.xml b/app/src/main/res/layout/widget_header_dark.xml index 2656853d1..5b6d1dea5 100644 --- a/app/src/main/res/layout/widget_header_dark.xml +++ b/app/src/main/res/layout/widget_header_dark.xml @@ -13,7 +13,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="@dimen/half_keyline_first" - android:paddingStart="@dimen/keyline_first" + android:paddingStart="0dp" android:paddingEnd="@dimen/keyline_first" android:paddingBottom="@dimen/half_keyline_first" tools:src="@drawable/ic_keyboard_arrow_down_black_18dp" @@ -30,9 +30,11 @@ android:layout_height="wrap_content" android:layout_toStartOf="@id/arrow" android:paddingStart="@dimen/keyline_first" - android:paddingEnd="@dimen/keyline_first" + android:paddingEnd="0dp" android:gravity="start|center_vertical" android:textSize="@dimen/sku_details_row_text_size" + android:maxLines="1" + android:ellipsize="end" tools:textColor="@color/white_60" tools:text="Today" app:fontFamily="sans-serif-medium" /> diff --git a/app/src/main/res/layout/widget_header_light.xml b/app/src/main/res/layout/widget_header_light.xml index 73da3eaf4..cf31c022f 100644 --- a/app/src/main/res/layout/widget_header_light.xml +++ b/app/src/main/res/layout/widget_header_light.xml @@ -12,7 +12,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="@dimen/half_keyline_first" - android:paddingStart="@dimen/keyline_first" + android:paddingStart="0dp" android:paddingEnd="@dimen/keyline_first" android:paddingBottom="@dimen/half_keyline_first" tools:src="@drawable/ic_keyboard_arrow_down_black_18dp" @@ -29,9 +29,11 @@ android:layout_height="wrap_content" android:layout_toStartOf="@id/arrow" android:paddingStart="@dimen/keyline_first" - android:paddingEnd="@dimen/keyline_first" + android:paddingEnd="0dp" android:gravity="start|center_vertical" android:textSize="@dimen/sku_details_row_text_size" + android:maxLines="1" + android:ellipsize="end" tools:textColor="@color/black_60" tools:text="Today" app:fontFamily="sans-serif-medium" /> diff --git a/app/src/main/res/values/keys.xml b/app/src/main/res/values/keys.xml index 3f18eef33..96367fbf7 100644 --- a/app/src/main/res/values/keys.xml +++ b/app/src/main/res/values/keys.xml @@ -339,6 +339,7 @@ widget-sort-astrid- widget-hidden- widget-completed- + widget-compact- widget-color- widget-color-v2 widget-opacity-v3-