Improve widget sort header when width constrained

pull/1322/head
Alex Baker 4 years ago
parent a6a77ef06c
commit dfe621d10a

@ -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()
}
}

@ -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 {

@ -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

@ -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);
}

@ -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" />

@ -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" />

@ -339,6 +339,7 @@
<string name="p_widget_sort_astrid">widget-sort-astrid-</string>
<string name="p_widget_show_hidden">widget-hidden-</string>
<string name="p_widget_show_completed">widget-completed-</string>
<string name="p_widget_compact">widget-compact-</string>
<string name="p_widget_color">widget-color-</string>
<string name="p_widget_color_v2">widget-color-v2</string>
<string name="p_widget_opacity">widget-opacity-v3-</string>

Loading…
Cancel
Save