Display tag chips on widget

pull/1148/head
Alex Baker 5 years ago
parent 1f8a20c745
commit f1119d22a3

@ -81,6 +81,7 @@ class ScrollableWidget : InjectingPreferenceFragment() {
setupCheckbox(R.string.p_widget_show_subtasks)
setupCheckbox(R.string.p_widget_show_places)
setupCheckbox(R.string.p_widget_show_lists)
setupCheckbox(R.string.p_widget_show_tags)
setupCheckbox(R.string.p_widget_show_full_task_title, false)
val showDescription = setupCheckbox(R.string.p_widget_show_description, true)
setupCheckbox(R.string.p_widget_show_full_description, false).dependency = showDescription.key

@ -5,6 +5,7 @@ import android.widget.RemoteViews
import com.todoroo.astrid.api.CaldavFilter
import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.api.GtasksFilter
import com.todoroo.astrid.api.TagFilter
import dagger.hilt.android.qualifiers.ApplicationContext
import org.tasks.BuildConfig
import org.tasks.R
@ -59,6 +60,17 @@ class ChipProvider @Inject constructor(
return null
}
fun getTagChips(filter: Filter?, task: TaskContainer): List<RemoteViews> {
val tags = task.tags?.split(",")?.toHashSet() ?: return emptyList()
if (filter is TagFilter) {
tags.remove(filter.uuid)
}
return tags
.mapNotNull(chipListCache::getTag)
.sortedBy(TagFilter::listingTitle)
.mapNotNull { newChip(it, R.drawable.ic_outline_label_24px) }
}
private fun newChip(filter: Filter?, defaultIcon: Int): RemoteViews? {
if (filter == null) {
return null

@ -58,6 +58,7 @@ internal class ScrollableViewsFactory(
private var showSubtasks = false
private var showPlaces = false
private var showLists = false
private var showTags = false
private var isRtl = false
private var tasks: List<TaskContainer> = ArrayList()
override fun onCreate() {}
@ -192,6 +193,11 @@ internal class ScrollableViewsFactory(
.getListChip(filter, taskContainer)
?.let { row.addView(R.id.chips, it) }
}
if (showTags && taskContainer.tags?.isNotBlank() == true) {
chipProvider
.getTagChips(filter, taskContainer)
.forEach { row.addView(R.id.chips, it) }
}
row.setInt(R.id.widget_row, "setLayoutDirection", locale.directionality)
val startPad = taskContainer.getIndent() * indentPadding
row.setViewPadding(R.id.widget_row, if (isRtl) 0 else startPad, 0, if (isRtl) startPad else 0, 0)
@ -268,6 +274,7 @@ internal class ScrollableViewsFactory(
showPlaces = widgetPreferences.showPlaces()
showSubtasks = widgetPreferences.showSubtasks()
showLists = widgetPreferences.showLists()
showTags = widgetPreferences.showTags()
isRtl = locale.directionality == View.LAYOUT_DIRECTION_RTL
}

@ -61,6 +61,10 @@ public class WidgetPreferences {
return getBoolean(R.string.p_widget_show_lists, true);
}
boolean showTags() {
return getBoolean(R.string.p_widget_show_tags, true);
}
public int getDueDatePosition() {
return getIntegerFromString(R.string.p_widget_due_date_position, 0);
}

@ -105,12 +105,14 @@
tools:text="Tomorrow"
tools:textColor="@color/white_60"/>
<GridLayout
<LinearLayout
android:id="@+id/chips"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/widget_due_bottom"
android:layout_toEndOf="@id/widget_complete_box"
android:paddingStart="0dp"
android:paddingEnd="@dimen/widget_padding"
android:orientation="horizontal" />
<ImageView

@ -104,12 +104,14 @@
tools:text="Tomorrow"
tools:textColor="@color/black_60"/>
<GridLayout
<LinearLayout
android:id="@+id/chips"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/widget_due_bottom"
android:layout_toEndOf="@id/widget_complete_box"
android:paddingStart="0dp"
android:paddingEnd="@dimen/widget_padding"
android:orientation="horizontal" />
<ImageView

@ -308,6 +308,7 @@
<string name="p_widget_show_subtasks">widget-show-subtasks-</string>
<string name="p_widget_show_places">widget-show-places-</string>
<string name="p_widget_show_lists">widget-show-lists-</string>
<string name="p_widget_show_tags">widget-show-tags-</string>
<string name="p_widget_show_description">widget-show-description-</string>
<string name="p_widget_show_full_description">widget-show-full-description-</string>
<string name="p_widget_show_checkboxes">widget-show-checkboxes-</string>

@ -143,6 +143,11 @@
android:key="@string/p_widget_show_lists"
android:title="@string/lists" />
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="@string/p_widget_show_tags"
android:title="@string/tags" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/widget_on_click">

Loading…
Cancel
Save