Fix widget crash

pull/2988/head
Alex Baker 4 days ago
parent c7392025af
commit 27eef75a94

@ -233,6 +233,7 @@ class WearService(
title = request.title,
filter = filter,
)
firebase.addTask("wearable")
return SaveTaskResponse.newBuilder().setTaskId(task.id).build()
} else {
taskDao.fetch(request.taskId)?.let { task ->

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

Loading…
Cancel
Save