diff --git a/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/BackgroundAudioRecordingTest.java b/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/BackgroundAudioRecordingTest.java index 1c4ab3b4533..50eadf436c5 100644 --- a/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/BackgroundAudioRecordingTest.java +++ b/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/BackgroundAudioRecordingTest.java @@ -174,6 +174,18 @@ public void whenRecordAudioPermissionNotGranted_openingForm_andDenyingPermission new MainMenuPage().assertOnPage(); } + @Test + public void viewForm_doesNotRecordAudio() { + rule.startAtMainMenu() + .copyForm("one-question-background-audio.xml") + .startBlankForm("One Question") + .fillOutAndFinalize(new FormEntryPage.QuestionAndAnswer("what is your age", "17")) + .clickSendFinalizedForm(1) + .clickOnForm("One Question"); + + assertThat(stubAudioRecorderViewModel.isRecording(), is(false)); + } + private static class RevokeableRecordAudioPermissionsChecker extends ContextCompatPermissionChecker { private boolean revoked; diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormEntryViewModelFactory.kt b/collect_app/src/main/java/org/odk/collect/android/activities/FormEntryViewModelFactory.kt index 610cc711583..d8405e0ba16 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormEntryViewModelFactory.kt +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormEntryViewModelFactory.kt @@ -20,6 +20,7 @@ import org.odk.collect.android.formentry.saving.DiskFormSaver import org.odk.collect.android.formentry.saving.FormSaveViewModel import org.odk.collect.android.instancemanagement.autosend.AutoSendSettingsProvider import org.odk.collect.android.projects.CurrentProjectProvider +import org.odk.collect.android.utilities.ApplicationConstants import org.odk.collect.android.utilities.InstancesRepositoryProvider import org.odk.collect.android.utilities.MediaUtils import org.odk.collect.async.Scheduler @@ -32,6 +33,7 @@ import java.util.function.BiConsumer class FormEntryViewModelFactory( owner: SavedStateRegistryOwner, + private val mode: String?, private val sessionId: String, private val scheduler: Scheduler, private val formSessionRepository: FormSessionRepository, @@ -78,17 +80,25 @@ class FormEntryViewModelFactory( } BackgroundAudioViewModel::class.java -> { - val recordAudioActionRegistry = object : RecordAudioActionRegistry { - override fun register(listener: BiConsumer) { - RecordAudioActions.setRecordAudioListener { absoluteTargetRef: TreeReference, quality: String? -> - listener.accept(absoluteTargetRef, quality) + val recordAudioActionRegistry = + if (mode == ApplicationConstants.FormModes.VIEW_SENT) { + object : RecordAudioActionRegistry { + override fun register(listener: BiConsumer) {} + override fun unregister() {} } - } + } else { + object : RecordAudioActionRegistry { + override fun register(listener: BiConsumer) { + RecordAudioActions.setRecordAudioListener { absoluteTargetRef: TreeReference, quality: String? -> + listener.accept(absoluteTargetRef, quality) + } + } - override fun unregister() { - RecordAudioActions.setRecordAudioListener(null) + override fun unregister() { + RecordAudioActions.setRecordAudioListener(null) + } + } } - } BackgroundAudioViewModel( audioRecorder, diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormFillingActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormFillingActivity.java index c1c9434b053..da1fb0dbb92 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormFillingActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormFillingActivity.java @@ -413,7 +413,22 @@ public void onCreate(Bundle savedInstanceState) { sessionId = savedInstanceState.getString(KEY_SESSION_ID); } - viewModelFactory = new FormEntryViewModelFactory(this, sessionId, scheduler, formSessionRepository, mediaUtils, audioRecorder, currentProjectProvider, entitiesRepositoryProvider, settingsProvider, permissionsChecker, fusedLocatonClient, permissionsProvider, autoSendSettingsProvider, instancesRepositoryProvider); + viewModelFactory = new FormEntryViewModelFactory(this, + getIntent().getStringExtra(ApplicationConstants.BundleKeys.FORM_MODE), + sessionId, + scheduler, + formSessionRepository, + mediaUtils, + audioRecorder, + currentProjectProvider, + entitiesRepositoryProvider, + settingsProvider, + permissionsChecker, + fusedLocatonClient, + permissionsProvider, + autoSendSettingsProvider, + instancesRepositoryProvider + ); this.getSupportFragmentManager().setFragmentFactory(new FragmentFactoryBuilder() .forClass(AudioRecordingControllerFragment.class, () -> new AudioRecordingControllerFragment(viewModelFactory)) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java index 8367ad86ec4..0de38bec55b 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java @@ -57,6 +57,7 @@ import org.odk.collect.android.javarosawrapper.JavaRosaFormController; import org.odk.collect.android.logic.HierarchyElement; import org.odk.collect.android.projects.CurrentProjectProvider; +import org.odk.collect.android.utilities.ApplicationConstants; import org.odk.collect.android.utilities.FormEntryPromptUtils; import org.odk.collect.android.utilities.HtmlUtils; import org.odk.collect.android.utilities.InstancesRepositoryProvider; @@ -181,7 +182,22 @@ public void onCreate(Bundle savedInstanceState) { DaggerUtils.getComponent(this).inject(this); String sessionId = getIntent().getStringExtra(EXTRA_SESSION_ID); - FormEntryViewModelFactory viewModelFactory = new FormEntryViewModelFactory(this, sessionId, scheduler, formSessionRepository, mediaUtils, audioRecorder, currentProjectProvider, entitiesRepositoryProvider, settingsProvider, permissionsChecker, fusedLocationClient, permissionsProvider, autoSendSettingsProvider, instancesRepositoryProvider); + FormEntryViewModelFactory viewModelFactory = new FormEntryViewModelFactory(this, + ApplicationConstants.FormModes.EDIT_SAVED, + sessionId, + scheduler, + formSessionRepository, + mediaUtils, + audioRecorder, + currentProjectProvider, + entitiesRepositoryProvider, + settingsProvider, + permissionsChecker, + fusedLocationClient, + permissionsProvider, + autoSendSettingsProvider, + instancesRepositoryProvider + ); this.getSupportFragmentManager().setFragmentFactory(new FragmentFactoryBuilder() .forClass(DeleteRepeatDialogFragment.class, () -> new DeleteRepeatDialogFragment(viewModelFactory))