Collapse completed section by default

pull/1760/head
Alex Baker 3 years ago
parent aadf4968cf
commit 95b34d2a21

@ -11,12 +11,17 @@ import com.todoroo.astrid.data.Task
import com.todoroo.astrid.data.Task.Companion.HIDE_UNTIL_SPECIFIC_DAY import com.todoroo.astrid.data.Task.Companion.HIDE_UNTIL_SPECIFIC_DAY
import org.tasks.BuildConfig import org.tasks.BuildConfig
import org.tasks.LocalBroadcastManager import org.tasks.LocalBroadcastManager
import org.tasks.data.* import org.tasks.data.CaldavDao
import org.tasks.data.CaldavTask
import org.tasks.data.GoogleTask
import org.tasks.data.GoogleTaskDao
import org.tasks.data.SubsetCaldav
import org.tasks.data.SubsetGoogleTask
import org.tasks.data.TaskContainer
import org.tasks.date.DateTimeUtils.toAppleEpoch import org.tasks.date.DateTimeUtils.toAppleEpoch
import org.tasks.date.DateTimeUtils.toDateTime import org.tasks.date.DateTimeUtils.toDateTime
import org.tasks.tasklist.SectionedDataSource.Companion.HEADER_COMPLETED
import org.tasks.time.DateTimeUtils.millisOfDay import org.tasks.time.DateTimeUtils.millisOfDay
import java.util.*
import kotlin.collections.HashSet
open class TaskAdapter( open class TaskAdapter(
private val newTasksOnTop: Boolean, private val newTasksOnTop: Boolean,
@ -26,7 +31,7 @@ open class TaskAdapter(
private val localBroadcastManager: LocalBroadcastManager) { private val localBroadcastManager: LocalBroadcastManager) {
private val selected = HashSet<Long>() private val selected = HashSet<Long>()
private val collapsed = HashSet<Long>() private val collapsed = mutableSetOf(HEADER_COMPLETED)
private lateinit var dataSource: TaskAdapterDataSource private lateinit var dataSource: TaskAdapterDataSource
val count: Int val count: Int
@ -48,14 +53,14 @@ open class TaskAdapter(
fun clearSelections() = selected.clear() fun clearSelections() = selected.clear()
fun getCollapsed(): MutableSet<Long> = HashSet(collapsed) fun getCollapsed() = HashSet(collapsed)
fun setCollapsed(groups: LongArray?) { fun setCollapsed(groups: LongArray?) {
clearCollapsed() clearCollapsed()
groups?.toList()?.let(collapsed::addAll) groups?.toList()?.let(collapsed::addAll)
} }
fun clearCollapsed() = collapsed.clear() fun clearCollapsed() = collapsed.retainAll(listOf(HEADER_COMPLETED))
open fun getIndent(task: TaskContainer): Int = task.getIndent() open fun getIndent(task: TaskContainer): Int = task.getIndent()

@ -6,13 +6,12 @@ import com.todoroo.andlib.utility.DateUtilities.now
import com.todoroo.astrid.core.SortHelper import com.todoroo.astrid.core.SortHelper
import org.tasks.data.TaskContainer import org.tasks.data.TaskContainer
import org.tasks.time.DateTimeUtils.startOfDay import org.tasks.time.DateTimeUtils.startOfDay
import java.util.*
class SectionedDataSource constructor( class SectionedDataSource constructor(
tasks: List<TaskContainer>, tasks: List<TaskContainer>,
disableHeaders: Boolean, disableHeaders: Boolean,
val sortMode: Int, val sortMode: Int,
private val collapsed: MutableSet<Long> private val collapsed: Set<Long>
) { ) {
private val tasks = tasks.toMutableList() private val tasks = tasks.toMutableList()

@ -28,6 +28,7 @@ import org.tasks.markdown.Markdown
import org.tasks.preferences.DefaultFilterProvider import org.tasks.preferences.DefaultFilterProvider
import org.tasks.preferences.Preferences import org.tasks.preferences.Preferences
import org.tasks.tasklist.SectionedDataSource import org.tasks.tasklist.SectionedDataSource
import org.tasks.tasklist.SectionedDataSource.Companion.HEADER_COMPLETED
import org.tasks.time.DateTimeUtils.startOfDay import org.tasks.time.DateTimeUtils.startOfDay
import org.tasks.ui.CheckBoxProvider import org.tasks.ui.CheckBoxProvider
import timber.log.Timber import timber.log.Timber
@ -70,7 +71,7 @@ internal class ScrollableViewsFactory(
private var showLists = false private var showLists = false
private var showTags = false private var showTags = false
private var isRtl = false private var isRtl = false
private var collapsed = HashSet<Long>() private var collapsed = mutableSetOf(HEADER_COMPLETED)
private var sortMode = -1 private var sortMode = -1
private var tasks = SectionedDataSource(emptyList(), false, 0, collapsed) private var tasks = SectionedDataSource(emptyList(), false, 0, collapsed)
private val widgetPreferences = WidgetPreferences(context, preferences, widgetId) private val widgetPreferences = WidgetPreferences(context, preferences, widgetId)
@ -97,7 +98,7 @@ internal class ScrollableViewsFactory(
collapsed collapsed
) )
if (collapsed.retainAll(tasks.getSectionValues())) { if (collapsed.retainAll(tasks.getSectionValues())) {
widgetPreferences.collapsed = collapsed widgetPreferences.setCollapsed(collapsed)
} }
} }
} }
@ -368,7 +369,7 @@ internal class ScrollableViewsFactory(
widgetPreferences.sortMode.takeIf { it != sortMode } widgetPreferences.sortMode.takeIf { it != sortMode }
?.let { ?.let {
if (sortMode >= 0) { if (sortMode >= 0) {
widgetPreferences.collapsed = HashSet() widgetPreferences.setCollapsed(mutableSetOf(HEADER_COMPLETED))
} }
sortMode = it sortMode = it
} }

@ -75,7 +75,7 @@ class WidgetClickActivity : InjectingAppCompatActivity(), OnDismissHandler {
} else { } else {
collapsed.remove(group) collapsed.remove(group)
} }
widgetPreferences.collapsed = collapsed widgetPreferences.setCollapsed(collapsed)
localBroadcastManager.broadcastRefresh() localBroadcastManager.broadcastRefresh()
finish() finish()
} }

@ -92,7 +92,7 @@ public class WidgetPreferences implements QueryPreferences {
return getIntegerFromString(R.string.p_widget_due_date_position, 0); return getIntegerFromString(R.string.p_widget_due_date_position, 0);
} }
public void setCollapsed(HashSet<Long> collapsed) { public void setCollapsed(Iterable<Long> collapsed) {
setString(R.string.p_widget_collapsed, Joiner.on(",").join(collapsed)); setString(R.string.p_widget_collapsed, Joiner.on(",").join(collapsed));
} }

Loading…
Cancel
Save