You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
}
/**
* Generates the task sequence based on whether a task should be included or not.
*
* This determines the order of tasks to be presented to the user, taking into account any
* overrides specified by [taskValueOverride].
*
* @param taskValueOverride An optional pair where the first element is the task ID and the second
* element is the [TaskData] to override the default task data. If null, no override is applied.
* @return A [Sequence] of [Task] objects representing the ordered tasks.
*/
fun generateTaskSequence(taskValueOverride: Pair<String, TaskData?>? = null): Sequence<Task> =
tasks.filter { task -> shouldIncludeTask(task, taskValueOverride) }.asSequence()
fun getTaskSequence(): Sequence<Task> {
if (!isSequenceInitialized) {
taskSequence = generateTaskSequence()
isSequenceInitialized = true
}
return taskSequence
}
// TODO: Add a method to update the cached sequence whenever necessary.
// Issue URL: https://github.com/google/ground-android/issues/2993
/**
* Checks if the specified task is the first task in the displayed sequence.
*
The text was updated successfully, but these errors were encountered:
TaskSequence is generated from the list of all tasks. Tasks whose condition isn't satisfied are filtered out. For evaluating this condition, we use the data object in DataCollectionViewModel which stores taskdata corresponding to each task fragment.
So, we only need to update the sequence if data is mutated. Until then, the cached value can be used.
Proposal:
Rename current getTaskSequence() in TaskSequenceHandler to createTaskSequence()
Introduce a new method refreshSequence() in the same class which calls createTaskSequence() and saves the value in memory.
Create a new wrapper class for data called TaskDataHandler which exposes setData(k, v) and getData() for the DataCollectionViewModel for saving/fetching task data.
Only call refreshSequence() when setData() is called to ensure that the sequence is updated only when the data is mutated.
Refactor the existing code base to use getTaskSequence() instead of createTaskSequence() (This would be done when integrating these classes with DataCollectionViewModel
github-actionsbot
changed the title
Cache task sequence in TaskSequenceHandler
Add a method to update the cached sequence whenever necessary.
Jan 9, 2025
ground-android/ground/src/main/java/com/google/android/ground/ui/datacollection/TaskSequenceHandler.kt
Lines 76 to 77 in 1ada8df
The text was updated successfully, but these errors were encountered: