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

Don't start background recording when viewing forms #5653

Merged
merged 2 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -78,17 +80,25 @@ class FormEntryViewModelFactory(
}

BackgroundAudioViewModel::class.java -> {
val recordAudioActionRegistry = object : RecordAudioActionRegistry {
override fun register(listener: BiConsumer<TreeReference, String?>) {
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<TreeReference, String?>) {}
override fun unregister() {}
}
}
} else {
object : RecordAudioActionRegistry {
override fun register(listener: BiConsumer<TreeReference, String?>) {
RecordAudioActions.setRecordAudioListener { absoluteTargetRef: TreeReference, quality: String? ->
listener.accept(absoluteTargetRef, quality)
}
}

override fun unregister() {
RecordAudioActions.setRecordAudioListener(null)
override fun unregister() {
RecordAudioActions.setRecordAudioListener(null)
}
}
}
}

BackgroundAudioViewModel(
audioRecorder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down