Display list chips on widget

pull/1148/head
Alex Baker 5 years ago
parent 5e7bf41cfd
commit 0783b3d4da

@ -0,0 +1,77 @@
package org.tasks.widget
import android.content.Context
import android.widget.RemoteViews
import com.todoroo.astrid.api.CaldavFilter
import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.api.GtasksFilter
import dagger.hilt.android.qualifiers.ApplicationContext
import org.tasks.BuildConfig
import org.tasks.R
import org.tasks.data.TaskContainer
import org.tasks.themes.CustomIcons
import org.tasks.ui.ChipListCache
import javax.inject.Inject
class ChipProvider @Inject constructor(
@ApplicationContext private val context: Context,
private val chipListCache: ChipListCache,
) {
var isDark = false
fun getSubtaskChip(task: TaskContainer): RemoteViews {
val chip = newChip()
chip.setTextViewText(
R.id.chip_text,
context
.resources
.getQuantityString(R.plurals.subtask_count, task.children, task.children)
)
chip.setImageViewResource(
R.id.chip_icon,
if (task.isCollapsed) {
R.drawable.ic_keyboard_arrow_down_black_24dp
} else {
R.drawable.ic_keyboard_arrow_up_black_24dp
}
)
return chip
}
fun getListChip(filter: Filter?, task: TaskContainer): RemoteViews? {
task.googleTaskList
?.takeIf { filter !is GtasksFilter }
?.let { newChip(chipListCache.getGoogleTaskList(it), R.drawable.ic_list_24px) }
?.let { return it }
task.caldav
?.takeIf { filter !is CaldavFilter }
?.let { newChip(chipListCache.getCaldavList(it), R.drawable.ic_list_24px) }
?.let { return it }
return null
}
private fun newChip(filter: Filter?, defaultIcon: Int): RemoteViews? {
if (filter == null) {
return null
}
val chip = newChip()
chip.setTextViewText(R.id.chip_text, filter.listingTitle)
val icon = filter.icon
.takeIf { it >= 0 }
?.let { CustomIcons.getIconResId(it) }
?: defaultIcon
chip.setImageViewResource(R.id.chip_icon, icon)
if (filter.tint != 0) {
chip.setInt(R.id.chip_background, "setColorFilter", filter.tint)
chip.setTextColor(R.id.chip_text, filter.tint)
chip.setInt(R.id.chip_icon, "setColorFilter", filter.tint)
}
return chip
}
private fun newChip() = RemoteViews(
BuildConfig.APPLICATION_ID,
if (isDark) R.layout.widget_chip_dark else R.layout.widget_chip_light
)
}

@ -35,7 +35,9 @@ internal class ScrollableViewsFactory(
private val taskDao: TaskDao, private val taskDao: TaskDao,
private val defaultFilterProvider: DefaultFilterProvider, private val defaultFilterProvider: DefaultFilterProvider,
private val checkBoxProvider: CheckBoxProvider, private val checkBoxProvider: CheckBoxProvider,
private val locale: Locale) : RemoteViewsFactory { private val locale: Locale,
private val chipProvider: ChipProvider
) : RemoteViewsFactory {
private val indentPadding: Int private val indentPadding: Int
private var isDark = false private var isDark = false
private var showDueDates = false private var showDueDates = false
@ -54,6 +56,7 @@ internal class ScrollableViewsFactory(
private var handleDueDateClick = false private var handleDueDateClick = false
private var showDividers = false private var showDividers = false
private var showSubtasks = false private var showSubtasks = false
private var showLists = false
private var isRtl = false private var isRtl = false
private var tasks: List<TaskContainer> = ArrayList() private var tasks: List<TaskContainer> = ArrayList()
override fun onCreate() {} override fun onCreate() {}
@ -167,24 +170,21 @@ internal class ScrollableViewsFactory(
if (!showDividers) { if (!showDividers) {
row.setViewVisibility(R.id.divider, View.GONE) row.setViewVisibility(R.id.divider, View.GONE)
} }
row.removeAllViews(R.id.chips)
if (showSubtasks && taskContainer.hasChildren()) { if (showSubtasks && taskContainer.hasChildren()) {
val chip = chipProvider.getSubtaskChip(taskContainer)
row.addView(R.id.chips, chip)
row.setOnClickFillInIntent( row.setOnClickFillInIntent(
R.id.subtask_button, R.id.chip,
Intent(WidgetClickActivity.TOGGLE_SUBTASKS) Intent(WidgetClickActivity.TOGGLE_SUBTASKS)
.putExtra(WidgetClickActivity.EXTRA_TASK, task) .putExtra(WidgetClickActivity.EXTRA_TASK, task)
.putExtra(WidgetClickActivity.EXTRA_COLLAPSED, !taskContainer.isCollapsed)) .putExtra(WidgetClickActivity.EXTRA_COLLAPSED, !taskContainer.isCollapsed)
row.setTextViewText( )
R.id.subtask_text, }
context if (!taskContainer.hasParent() && showLists) {
.resources chipProvider
.getQuantityString( .getListChip(filter, taskContainer)
R.plurals.subtask_count, taskContainer.children, taskContainer.children)) ?.let { row.addView(R.id.chips, it) }
row.setImageViewResource(
R.id.subtask_icon,
if (taskContainer.isCollapsed) R.drawable.ic_keyboard_arrow_down_black_18dp else R.drawable.ic_keyboard_arrow_up_black_18dp)
row.setViewVisibility(R.id.subtask_button, View.VISIBLE)
} else {
row.setViewVisibility(R.id.subtask_button, View.GONE)
} }
row.setInt(R.id.widget_row, "setLayoutDirection", locale.directionality) row.setInt(R.id.widget_row, "setLayoutDirection", locale.directionality)
val startPad = taskContainer.getIndent() * indentPadding val startPad = taskContainer.getIndent() * indentPadding
@ -248,6 +248,7 @@ internal class ScrollableViewsFactory(
showDescription = widgetPreferences.showDescription() showDescription = widgetPreferences.showDescription()
showFullDescription = widgetPreferences.showFullDescription() showFullDescription = widgetPreferences.showFullDescription()
isDark = widgetPreferences.themeIndex > 0 isDark = widgetPreferences.themeIndex > 0
chipProvider.isDark = isDark
textColorPrimary = context.getColor(if (isDark) R.color.white_87 else R.color.black_87) textColorPrimary = context.getColor(if (isDark) R.color.white_87 else R.color.black_87)
textColorSecondary = context.getColor(if (isDark) R.color.white_60 else R.color.black_60) textColorSecondary = context.getColor(if (isDark) R.color.white_60 else R.color.black_60)
val dueDatePosition = widgetPreferences.dueDatePosition val dueDatePosition = widgetPreferences.dueDatePosition
@ -259,6 +260,7 @@ internal class ScrollableViewsFactory(
filter = defaultFilterProvider.getFilterFromPreference(widgetPreferences.filterId) filter = defaultFilterProvider.getFilterFromPreference(widgetPreferences.filterId)
showDividers = widgetPreferences.showDividers() showDividers = widgetPreferences.showDividers()
showSubtasks = widgetPreferences.showSubtasks() showSubtasks = widgetPreferences.showSubtasks()
showLists = widgetPreferences.showLists()
isRtl = locale.directionality == View.LAYOUT_DIRECTION_RTL isRtl = locale.directionality == View.LAYOUT_DIRECTION_RTL
} }

@ -23,6 +23,7 @@ public class ScrollableWidgetUpdateService extends RemoteViewsService {
@Inject SubtasksHelper subtasksHelper; @Inject SubtasksHelper subtasksHelper;
@Inject DefaultFilterProvider defaultFilterProvider; @Inject DefaultFilterProvider defaultFilterProvider;
@Inject Locale locale; @Inject Locale locale;
@Inject ChipProvider chipProvider;
@Override @Override
public void onStart(Intent intent, int startId) { public void onStart(Intent intent, int startId) {
@ -52,6 +53,7 @@ public class ScrollableWidgetUpdateService extends RemoteViewsService {
taskDao, taskDao,
defaultFilterProvider, defaultFilterProvider,
new CheckBoxProvider(context, new ColorProvider(context, preferences)), new CheckBoxProvider(context, new ColorProvider(context, preferences)),
locale); locale,
chipProvider);
} }
} }

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

@ -3,4 +3,5 @@
android:shape="rectangle"> android:shape="rectangle">
<corners android:radius="12dp" /> <corners android:radius="12dp" />
<stroke android:width="@dimen/chip_stroke" android:color="@color/white_60" /> <stroke android:width="@dimen/chip_stroke" android:color="@color/white_60" />
<solid android:color="@android:color/transparent"/>
</shape> </shape>

@ -3,4 +3,5 @@
android:shape="rectangle"> android:shape="rectangle">
<corners android:radius="12dp" /> <corners android:radius="12dp" />
<stroke android:width="@dimen/chip_stroke" android:color="@color/black_60" /> <stroke android:width="@dimen/chip_stroke" android:color="@color/black_60" />
<solid android:color="@android:color/transparent"/>
</shape> </shape>

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/chip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginEnd="2dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/chip_icon"
android:layout_width="20dp"
android:layout_height="20dp"
android:paddingTop="2dp"
android:paddingStart="5dp"
android:paddingEnd="0dp"
android:layout_gravity="center_vertical"
android:tint="@color/icon_tint_dark_alpha"
tools:src="@drawable/ic_keyboard_arrow_up_black_24dp"
tools:ignore="UseAppTint" />
<TextView
android:id="@+id/chip_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_toEndOf="@id/chip_icon"
android:textSize="14sp"
android:maxLines="1"
android:ellipsize="end"
android:paddingBottom="2dp"
android:paddingStart="2dp"
android:paddingEnd="8dp"
android:textColor="@color/white_60"
tools:text="4 subtasks"/>
<ImageView
android:id="@+id/chip_background"
android:src="@drawable/widget_chip_dark_bg"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignBottom="@id/chip_text"
android:layout_alignEnd="@id/chip_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/chip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginEnd="2dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/chip_icon"
android:layout_width="20dp"
android:layout_height="20dp"
android:paddingTop="2dp"
android:paddingStart="5dp"
android:paddingEnd="0dp"
android:layout_gravity="center_vertical"
android:tint="@color/icon_tint_light_alpha"
tools:src="@drawable/ic_keyboard_arrow_up_black_24dp"
tools:ignore="UseAppTint" />
<TextView
android:id="@+id/chip_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_toEndOf="@id/chip_icon"
android:textSize="14sp"
android:maxLines="1"
android:ellipsize="end"
android:paddingBottom="2dp"
android:paddingStart="2dp"
android:paddingEnd="8dp"
android:textColor="@color/black_60"
tools:text="4 subtasks"/>
<ImageView
android:id="@+id/chip_background"
android:src="@drawable/widget_chip_light_bg"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignBottom="@id/chip_text"
android:layout_alignEnd="@id/chip_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>

@ -105,49 +105,17 @@
tools:text="Tomorrow" tools:text="Tomorrow"
tools:textColor="@color/white_60"/> tools:textColor="@color/white_60"/>
<LinearLayout <GridLayout
android:id="@+id/subtask_button" android:id="@+id/chips"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/widget_due_bottom" android:layout_below="@id/widget_due_bottom"
android:layout_marginTop="2dp"
android:layout_toEndOf="@id/widget_complete_box" android:layout_toEndOf="@id/widget_complete_box"
android:background="@drawable/widget_chip_dark" android:orientation="horizontal" />
android:orientation="horizontal"
android:visibility="gone"
tools:visibility="visible">
<ImageView
android:id="@+id/subtask_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="5dp"
android:paddingEnd="0dp"
android:layout_gravity="center_vertical"
android:tint="@color/icon_tint_dark_alpha"
tools:src="@drawable/ic_keyboard_arrow_up_black_18dp"
tools:ignore="UseAppTint" />
<TextView
android:id="@+id/subtask_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textSize="14sp"
android:maxLines="1"
android:ellipsize="end"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:paddingStart="0dp"
android:paddingEnd="8dp"
android:textColor="@color/white_60"
tools:text="4 subtasks"/>
</LinearLayout>
<ImageView <ImageView
android:id="@+id/bottom_padding" android:id="@+id/bottom_padding"
android:layout_below="@id/subtask_button" android:layout_below="@id/chips"
android:layout_alignStart="@id/widget_text" android:layout_alignStart="@id/widget_text"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

@ -104,48 +104,17 @@
tools:text="Tomorrow" tools:text="Tomorrow"
tools:textColor="@color/black_60"/> tools:textColor="@color/black_60"/>
<LinearLayout <GridLayout
android:id="@+id/subtask_button" android:id="@+id/chips"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/widget_due_bottom" android:layout_below="@id/widget_due_bottom"
android:layout_marginTop="2dp"
android:layout_toEndOf="@id/widget_complete_box" android:layout_toEndOf="@id/widget_complete_box"
android:background="@drawable/widget_chip_light" android:orientation="horizontal" />
android:orientation="horizontal"
android:visibility="gone"
tools:visibility="visible">
<ImageView
android:id="@+id/subtask_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="5dp"
android:paddingEnd="0dp"
android:layout_gravity="center_vertical"
android:alpha="@dimen/alpha_disabled"
tools:src="@drawable/ic_keyboard_arrow_up_black_18dp" />
<TextView
android:id="@+id/subtask_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textSize="14sp"
android:maxLines="1"
android:ellipsize="end"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:paddingStart="0dp"
android:paddingEnd="8dp"
android:textColor="@color/black_60"
tools:text="4 subtasks"/>
</LinearLayout>
<ImageView <ImageView
android:id="@+id/bottom_padding" android:id="@+id/bottom_padding"
android:layout_below="@id/subtask_button" android:layout_below="@id/chips"
android:layout_alignStart="@id/widget_text" android:layout_alignStart="@id/widget_text"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

@ -306,6 +306,7 @@
<string name="p_widget_show_full_task_title">widget-show-full-task-title-</string> <string name="p_widget_show_full_task_title">widget-show-full-task-title-</string>
<string name="p_widget_show_dividers">widget-show-dividers-</string> <string name="p_widget_show_dividers">widget-show-dividers-</string>
<string name="p_widget_show_subtasks">widget-show-subtasks-</string> <string name="p_widget_show_subtasks">widget-show-subtasks-</string>
<string name="p_widget_show_lists">widget-show-lists-</string>
<string name="p_widget_show_description">widget-show-description-</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_full_description">widget-show-full-description-</string>
<string name="p_widget_show_checkboxes">widget-show-checkboxes-</string> <string name="p_widget_show_checkboxes">widget-show-checkboxes-</string>

Loading…
Cancel
Save