diff --git a/app/src/main/java/com/todoroo/astrid/adapter/TaskAdapter.kt b/app/src/main/java/com/todoroo/astrid/adapter/TaskAdapter.kt index b86bbde4d..e9f48a8c2 100644 --- a/app/src/main/java/com/todoroo/astrid/adapter/TaskAdapter.kt +++ b/app/src/main/java/com/todoroo/astrid/adapter/TaskAdapter.kt @@ -11,12 +11,17 @@ import com.todoroo.astrid.data.Task import com.todoroo.astrid.data.Task.Companion.HIDE_UNTIL_SPECIFIC_DAY import org.tasks.BuildConfig 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.toDateTime +import org.tasks.tasklist.SectionedDataSource.Companion.HEADER_COMPLETED import org.tasks.time.DateTimeUtils.millisOfDay -import java.util.* -import kotlin.collections.HashSet open class TaskAdapter( private val newTasksOnTop: Boolean, @@ -26,7 +31,7 @@ open class TaskAdapter( private val localBroadcastManager: LocalBroadcastManager) { private val selected = HashSet() - private val collapsed = HashSet() + private val collapsed = mutableSetOf(HEADER_COMPLETED) private lateinit var dataSource: TaskAdapterDataSource val count: Int @@ -48,14 +53,14 @@ open class TaskAdapter( fun clearSelections() = selected.clear() - fun getCollapsed(): MutableSet = HashSet(collapsed) + fun getCollapsed() = HashSet(collapsed) fun setCollapsed(groups: LongArray?) { clearCollapsed() groups?.toList()?.let(collapsed::addAll) } - fun clearCollapsed() = collapsed.clear() + fun clearCollapsed() = collapsed.retainAll(listOf(HEADER_COMPLETED)) open fun getIndent(task: TaskContainer): Int = task.getIndent() diff --git a/app/src/main/java/org/tasks/tasklist/SectionedDataSource.kt b/app/src/main/java/org/tasks/tasklist/SectionedDataSource.kt index ad58f6712..2a2c2ff76 100644 --- a/app/src/main/java/org/tasks/tasklist/SectionedDataSource.kt +++ b/app/src/main/java/org/tasks/tasklist/SectionedDataSource.kt @@ -6,13 +6,12 @@ import com.todoroo.andlib.utility.DateUtilities.now import com.todoroo.astrid.core.SortHelper import org.tasks.data.TaskContainer import org.tasks.time.DateTimeUtils.startOfDay -import java.util.* class SectionedDataSource constructor( tasks: List, disableHeaders: Boolean, val sortMode: Int, - private val collapsed: MutableSet + private val collapsed: Set ) { private val tasks = tasks.toMutableList() diff --git a/app/src/main/java/org/tasks/widget/ScrollableViewsFactory.kt b/app/src/main/java/org/tasks/widget/ScrollableViewsFactory.kt index d1426fdf6..fee2a07a0 100644 --- a/app/src/main/java/org/tasks/widget/ScrollableViewsFactory.kt +++ b/app/src/main/java/org/tasks/widget/ScrollableViewsFactory.kt @@ -28,6 +28,7 @@ import org.tasks.markdown.Markdown import org.tasks.preferences.DefaultFilterProvider import org.tasks.preferences.Preferences import org.tasks.tasklist.SectionedDataSource +import org.tasks.tasklist.SectionedDataSource.Companion.HEADER_COMPLETED import org.tasks.time.DateTimeUtils.startOfDay import org.tasks.ui.CheckBoxProvider import timber.log.Timber @@ -70,7 +71,7 @@ internal class ScrollableViewsFactory( private var showLists = false private var showTags = false private var isRtl = false - private var collapsed = HashSet() + private var collapsed = mutableSetOf(HEADER_COMPLETED) private var sortMode = -1 private var tasks = SectionedDataSource(emptyList(), false, 0, collapsed) private val widgetPreferences = WidgetPreferences(context, preferences, widgetId) @@ -97,7 +98,7 @@ internal class ScrollableViewsFactory( collapsed ) if (collapsed.retainAll(tasks.getSectionValues())) { - widgetPreferences.collapsed = collapsed + widgetPreferences.setCollapsed(collapsed) } } } @@ -368,7 +369,7 @@ internal class ScrollableViewsFactory( widgetPreferences.sortMode.takeIf { it != sortMode } ?.let { if (sortMode >= 0) { - widgetPreferences.collapsed = HashSet() + widgetPreferences.setCollapsed(mutableSetOf(HEADER_COMPLETED)) } sortMode = it } diff --git a/app/src/main/java/org/tasks/widget/WidgetClickActivity.kt b/app/src/main/java/org/tasks/widget/WidgetClickActivity.kt index ada7c79b3..328017ae3 100644 --- a/app/src/main/java/org/tasks/widget/WidgetClickActivity.kt +++ b/app/src/main/java/org/tasks/widget/WidgetClickActivity.kt @@ -75,7 +75,7 @@ class WidgetClickActivity : InjectingAppCompatActivity(), OnDismissHandler { } else { collapsed.remove(group) } - widgetPreferences.collapsed = collapsed + widgetPreferences.setCollapsed(collapsed) localBroadcastManager.broadcastRefresh() finish() } diff --git a/app/src/main/java/org/tasks/widget/WidgetPreferences.java b/app/src/main/java/org/tasks/widget/WidgetPreferences.java index 5afda284e..cd4576b8e 100644 --- a/app/src/main/java/org/tasks/widget/WidgetPreferences.java +++ b/app/src/main/java/org/tasks/widget/WidgetPreferences.java @@ -92,7 +92,7 @@ public class WidgetPreferences implements QueryPreferences { return getIntegerFromString(R.string.p_widget_due_date_position, 0); } - public void setCollapsed(HashSet collapsed) { + public void setCollapsed(Iterable collapsed) { setString(R.string.p_widget_collapsed, Joiner.on(",").join(collapsed)); }