Skip to content

Commit

Permalink
Merge pull request #5653 from seadowg/background-audio-view
Browse files Browse the repository at this point in the history
Don't start background recording when viewing forms
  • Loading branch information
grzesiek2010 authored Jul 3, 2023
2 parents b326808 + a07ce59 commit c896146
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 10 deletions.
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

0 comments on commit c896146

Please sign in to comment.