|
|
|
|
@ -5,7 +5,6 @@ import android.content.Intent
|
|
|
|
|
import android.view.View
|
|
|
|
|
import android.widget.RemoteViews
|
|
|
|
|
import android.widget.RemoteViewsService.RemoteViewsFactory
|
|
|
|
|
import com.todoroo.andlib.utility.AndroidUtilities.atLeastAndroid16
|
|
|
|
|
import com.todoroo.astrid.core.SortHelper
|
|
|
|
|
import com.todoroo.astrid.subtasks.SubtasksHelper
|
|
|
|
|
import kotlinx.coroutines.runBlocking
|
|
|
|
|
@ -51,7 +50,6 @@ internal class TasksWidgetViewFactory(
|
|
|
|
|
private val markdown: Markdown,
|
|
|
|
|
private val headerFormatter: HeaderFormatter,
|
|
|
|
|
) : RemoteViewsFactory {
|
|
|
|
|
private val taskLimit = if (atLeastAndroid16()) 25 + 1 else Int.MAX_VALUE
|
|
|
|
|
private val indentPadding = (20 * context.resources.displayMetrics.density).toInt()
|
|
|
|
|
private val settings = widgetPreferences.getWidgetListSettings()
|
|
|
|
|
private val hPad = context.resources.getDimension(R.dimen.widget_padding).toInt()
|
|
|
|
|
@ -94,11 +92,10 @@ internal class TasksWidgetViewFactory(
|
|
|
|
|
Timber.d("onDestroy widgetId:$widgetId")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun getCount() = tasks.size.coerceAtMost(taskLimit)
|
|
|
|
|
override fun getCount() = tasks.size
|
|
|
|
|
|
|
|
|
|
override fun getViewAt(position: Int): RemoteViews? = tasks.let {
|
|
|
|
|
when {
|
|
|
|
|
position == taskLimit - 1 && it.size > taskLimit -> buildFooter()
|
|
|
|
|
it.isHeader(position) -> buildHeader(it.getSection(position))
|
|
|
|
|
position < it.size -> buildUpdate(it.getItem(position))
|
|
|
|
|
else -> null
|
|
|
|
|
@ -111,7 +108,6 @@ internal class TasksWidgetViewFactory(
|
|
|
|
|
|
|
|
|
|
override fun getItemId(position: Int) = tasks.let {
|
|
|
|
|
when {
|
|
|
|
|
position == taskLimit - 1 && it.size > taskLimit -> 0
|
|
|
|
|
it.isHeader(position) -> it.getSection(position).value
|
|
|
|
|
position < it.size -> it.getItem(position).id
|
|
|
|
|
else -> 0
|
|
|
|
|
@ -122,18 +118,6 @@ internal class TasksWidgetViewFactory(
|
|
|
|
|
|
|
|
|
|
private fun newRemoteView() = RemoteViews(BuildConfig.APPLICATION_ID, R.layout.widget_row)
|
|
|
|
|
|
|
|
|
|
private fun buildFooter(): RemoteViews {
|
|
|
|
|
return RemoteViews(BuildConfig.APPLICATION_ID, R.layout.widget_footer).apply {
|
|
|
|
|
setTextSize(R.id.widget_view_more, settings.textSize)
|
|
|
|
|
setTextColor(R.id.widget_view_more, onSurface)
|
|
|
|
|
setOnClickFillInIntent(
|
|
|
|
|
R.id.widget_view_more,
|
|
|
|
|
Intent(WidgetClickActivity.OPEN_TASK_LIST)
|
|
|
|
|
.putExtra(WidgetClickActivity.EXTRA_FILTER, filter)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun buildHeader(section: AdapterSection): RemoteViews {
|
|
|
|
|
val sortGroup = section.value
|
|
|
|
|
val header: String? = if (filter.supportsSorting()) {
|
|
|
|
|
|