Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Data collection] Restore position to last active task when restoring from draft #2871

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ground/src/main/java/com/google/android/ground/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object Config {
const val SHARED_PREFS_MODE = Context.MODE_PRIVATE

// Local db settings.
const val DB_VERSION = 120
const val DB_VERSION = 121
shobhitagarwal1612 marked this conversation as resolved.
Show resolved Hide resolved
const val DB_NAME = "ground.db"

// Firebase Cloud Firestore settings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
val loiName: String?,
val surveyId: String,
val deltas: List<ValueDelta>,
val currentTaskId: String?,

Check warning on line 26 in ground/src/main/java/com/google/android/ground/model/submission/DraftSubmission.kt

View check run for this annotation

Codecov / codecov/patch

ground/src/main/java/com/google/android/ground/model/submission/DraftSubmission.kt#L26

Added line #L26 was not covered by tests
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.android.ground.persistence.local.room

import androidx.room.AutoMigration
import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
Expand Down Expand Up @@ -89,6 +90,7 @@ import com.google.android.ground.persistence.local.room.fields.TileSetEntityStat
],
version = Config.DB_VERSION,
exportSchema = true,
autoMigrations = [AutoMigration(from = 120, to = 121)],
)
@TypeConverters(
TaskEntityType::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@
loiName = loiName,
surveyId = surveyId,
deltas = SubmissionDeltasConverter.fromString(job, deltas),
currentTaskId = currentTaskId,

Check warning on line 490 in ground/src/main/java/com/google/android/ground/persistence/local/room/converter/ConverterExt.kt

View check run for this annotation

Codecov / codecov/patch

ground/src/main/java/com/google/android/ground/persistence/local/room/converter/ConverterExt.kt#L490

Added line #L490 was not covered by tests
)
}

Expand All @@ -498,4 +499,5 @@
loiName = loiName,
surveyId = surveyId,
deltas = SubmissionDeltasConverter.toString(deltas),
currentTaskId = currentTaskId,

Check warning on line 502 in ground/src/main/java/com/google/android/ground/persistence/local/room/converter/ConverterExt.kt

View check run for this annotation

Codecov / codecov/patch

ground/src/main/java/com/google/android/ground/persistence/local/room/converter/ConverterExt.kt#L502

Added line #L502 was not covered by tests
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
@ColumnInfo(name = "survey_id") val surveyId: String,
@ColumnInfo(name = "deltas") val deltas: String?,
@ColumnInfo(name = "loi_name") val loiName: String?,
@ColumnInfo(name = "current_task_id") val currentTaskId: String?,

Check warning on line 33 in ground/src/main/java/com/google/android/ground/persistence/local/room/entity/DraftSubmissionEntity.kt

View check run for this annotation

Codecov / codecov/patch

ground/src/main/java/com/google/android/ground/persistence/local/room/entity/DraftSubmissionEntity.kt#L33

Added line #L33 was not covered by tests
)
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@
surveyId: String,
deltas: List<ValueDelta>,
loiName: String?,
currentTaskId: String,
) {
val newId = uuidGenerator.generateUuid()
val draft = DraftSubmission(newId, jobId, loiId, loiName, surveyId, deltas)
val draft = DraftSubmission(newId, jobId, loiId, loiName, surveyId, deltas, currentTaskId)

Check warning on line 89 in ground/src/main/java/com/google/android/ground/repository/SubmissionRepository.kt

View check run for this annotation

Codecov / codecov/patch

ground/src/main/java/com/google/android/ground/repository/SubmissionRepository.kt#L89

Added line #L89 was not covered by tests
localSubmissionStore.saveDraftSubmission(draftSubmission = draft)
localValueStore.draftSubmissionId = newId
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class DataCollectionFragment : AbstractFragment(), BackPressListener {
if (currentAdapter == null || currentAdapter.tasks != tasks) {
viewPager.adapter = viewPagerAdapterFactory.create(this, tasks)
}
updateProgressBar(taskPosition, false)
viewPager.doOnLayout { onTaskChanged(taskPosition) }
}

private fun onTaskChanged(taskPosition: TaskPosition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ internal constructor(

/** Moves back to the previous task in the sequence if the current value is valid or empty. */
suspend fun onPreviousClicked(taskViewModel: AbstractTaskViewModel) {
check(getPositionInTaskSequence().first != 0)

val task = taskViewModel.task
val taskValue = taskViewModel.taskTaskData.firstOrNull()

Expand Down Expand Up @@ -287,6 +285,7 @@ internal constructor(
surveyId = surveyId,
deltas = getDeltas(),
loiName = customLoiName,
currentTaskId = currentTaskId.value,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class HomeScreenFragment :
draft.jobId,
true,
SubmissionDeltasConverter.toString(draft.deltas),
draft.currentTaskId ?: "",
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
cardUiData.loi.job.id,
false,
null,
"",

Check warning on line 305 in ground/src/main/java/com/google/android/ground/ui/home/mapcontainer/HomeScreenMapContainerFragment.kt

View check run for this annotation

Codecov / codecov/patch

ground/src/main/java/com/google/android/ground/ui/home/mapcontainer/HomeScreenMapContainerFragment.kt#L305

Added line #L305 was not covered by tests
)
)
is MapCardUiData.AddLoiCardUiData ->
Expand All @@ -312,6 +313,7 @@
cardUiData.job.id,
false,
null,
"",

Check warning on line 316 in ground/src/main/java/com/google/android/ground/ui/home/mapcontainer/HomeScreenMapContainerFragment.kt

View check run for this annotation

Codecov / codecov/patch

ground/src/main/java/com/google/android/ground/ui/home/mapcontainer/HomeScreenMapContainerFragment.kt#L316

Added line #L316 was not covered by tests
)
)
}
Expand Down
8 changes: 8 additions & 0 deletions ground/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@
android:name="draftValues"
type="string"
app:nullable="true" />
<argument
android:name="currentTaskId"
type="string"
app:nullable="true" />

<fragment
android:id="@+id/data_collection_fragment"
Expand All @@ -130,6 +134,10 @@
android:name="draftValues"
type="string"
app:nullable="true" />
<argument
android:name="currentTaskId"
type="string"
app:nullable="true" />
</fragment>

<fragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class DataCollectionFragmentTest : BaseHiltTest() {
eq(SURVEY.id),
capture(deltaCaptor),
eq(LOCATION_OF_INTEREST_NAME),
eq(TASK_ID_2),
)

listOf(TASK_1_VALUE_DELTA).forEach { value -> assertThat(deltaCaptor.value).contains(value) }
Expand All @@ -149,13 +150,23 @@ class DataCollectionFragmentTest : BaseHiltTest() {

// Both deletion and creating happens twice as we do it on every previous/next step
verify(submissionRepository, times(2)).deleteDraftSubmission()
verify(submissionRepository, times(2))
verify(submissionRepository, times(1))
.saveDraftSubmission(
eq(JOB.id),
eq(LOCATION_OF_INTEREST.id),
eq(SURVEY.id),
capture(deltaCaptor),
eq(LOCATION_OF_INTEREST_NAME),
eq(TASK_ID_2),
)
verify(submissionRepository, times(1))
.saveDraftSubmission(
eq(JOB.id),
eq(LOCATION_OF_INTEREST.id),
eq(SURVEY.id),
capture(deltaCaptor),
eq(LOCATION_OF_INTEREST_NAME),
eq(TASK_ID_1),
)

listOf(TASK_1_VALUE_DELTA, TASK_2_VALUE_DELTA).forEach { value ->
Expand Down Expand Up @@ -189,6 +200,7 @@ class DataCollectionFragmentTest : BaseHiltTest() {
JOB.id,
true,
SubmissionDeltasConverter.toString(expectedDeltas),
"",
)
.build()
.toBundle()
Expand Down Expand Up @@ -309,6 +321,7 @@ class DataCollectionFragmentTest : BaseHiltTest() {
JOB.id,
false,
null,
"",
)
.build()
.toBundle()
Expand Down