|
|
@ -29,6 +29,7 @@ import org.tasks.kmp.org.tasks.time.DateStyle
|
|
|
|
import org.tasks.kmp.org.tasks.time.getRelativeDateTime
|
|
|
|
import org.tasks.kmp.org.tasks.time.getRelativeDateTime
|
|
|
|
import org.tasks.kmp.org.tasks.time.getTimeString
|
|
|
|
import org.tasks.kmp.org.tasks.time.getTimeString
|
|
|
|
import org.tasks.markdown.Markdown
|
|
|
|
import org.tasks.markdown.Markdown
|
|
|
|
|
|
|
|
import org.tasks.tasklist.AdapterSection
|
|
|
|
import org.tasks.tasklist.HeaderFormatter
|
|
|
|
import org.tasks.tasklist.HeaderFormatter
|
|
|
|
import org.tasks.tasklist.SectionedDataSource
|
|
|
|
import org.tasks.tasklist.SectionedDataSource
|
|
|
|
import org.tasks.tasklist.headerColor
|
|
|
|
import org.tasks.tasklist.headerColor
|
|
|
@ -88,22 +89,31 @@ internal class TasksWidgetViewFactory(
|
|
|
|
|
|
|
|
|
|
|
|
override fun getCount() = tasks.size
|
|
|
|
override fun getCount() = tasks.size
|
|
|
|
|
|
|
|
|
|
|
|
override fun getViewAt(position: Int): RemoteViews? =
|
|
|
|
override fun getViewAt(position: Int): RemoteViews? = tasks.let {
|
|
|
|
if (tasks.isHeader(position)) buildHeader(position) else buildUpdate(position)
|
|
|
|
when {
|
|
|
|
|
|
|
|
it.isHeader(position) -> buildHeader(it.getSection(position))
|
|
|
|
|
|
|
|
position < it.size -> buildUpdate(it.getItem(position))
|
|
|
|
|
|
|
|
else -> null
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun getLoadingView(): RemoteViews = newRemoteView()
|
|
|
|
override fun getLoadingView(): RemoteViews = newRemoteView()
|
|
|
|
|
|
|
|
|
|
|
|
override fun getViewTypeCount(): Int = 2
|
|
|
|
override fun getViewTypeCount(): Int = 2
|
|
|
|
|
|
|
|
|
|
|
|
override fun getItemId(position: Int) =
|
|
|
|
override fun getItemId(position: Int) = tasks.let {
|
|
|
|
if (tasks.isHeader(position)) tasks.getSection(position).value else getTask(position).id
|
|
|
|
when {
|
|
|
|
|
|
|
|
it.isHeader(position) -> it.getSection(position).value
|
|
|
|
|
|
|
|
position < it.size -> it.getItem(position).id
|
|
|
|
|
|
|
|
else -> 0
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun hasStableIds(): Boolean = true
|
|
|
|
override fun hasStableIds(): Boolean = true
|
|
|
|
|
|
|
|
|
|
|
|
private fun newRemoteView() = RemoteViews(BuildConfig.APPLICATION_ID, R.layout.widget_row)
|
|
|
|
private fun newRemoteView() = RemoteViews(BuildConfig.APPLICATION_ID, R.layout.widget_row)
|
|
|
|
|
|
|
|
|
|
|
|
private fun buildHeader(position: Int): RemoteViews {
|
|
|
|
private fun buildHeader(section: AdapterSection): RemoteViews {
|
|
|
|
val section = tasks.getSection(position)
|
|
|
|
|
|
|
|
val sortGroup = section.value
|
|
|
|
val sortGroup = section.value
|
|
|
|
val header: String? = if (filter.supportsSorting()) {
|
|
|
|
val header: String? = if (filter.supportsSorting()) {
|
|
|
|
headerFormatter.headerStringBlocking(
|
|
|
|
headerFormatter.headerStringBlocking(
|
|
|
@ -147,9 +157,8 @@ internal class TasksWidgetViewFactory(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun buildUpdate(position: Int): RemoteViews? {
|
|
|
|
private fun buildUpdate(taskContainer: TaskContainer): RemoteViews? {
|
|
|
|
return try {
|
|
|
|
return try {
|
|
|
|
val taskContainer = getTask(position)
|
|
|
|
|
|
|
|
val task = taskContainer.task
|
|
|
|
val task = taskContainer.task
|
|
|
|
val textColorTitle = when {
|
|
|
|
val textColorTitle = when {
|
|
|
|
task.isHidden -> onSurfaceVariant
|
|
|
|
task.isHidden -> onSurfaceVariant
|
|
|
@ -262,8 +271,6 @@ internal class TasksWidgetViewFactory(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun getTask(position: Int): TaskContainer = tasks.getItem(position)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private suspend fun getQuery(filter: Filter): List<String> {
|
|
|
|
private suspend fun getQuery(filter: Filter): List<String> {
|
|
|
|
subtasksHelper.applySubtasksToWidgetFilter(filter, widgetPreferences)
|
|
|
|
subtasksHelper.applySubtasksToWidgetFilter(filter, widgetPreferences)
|
|
|
|
return getQuery(widgetPreferences, filter)
|
|
|
|
return getQuery(widgetPreferences, filter)
|
|
|
|