Search in sources :

Example 6 with RecordingSession

use of org.odk.collect.audiorecorder.recording.RecordingSession in project collect by opendatakit.

the class AudioRecorderRecordingStatusHandlerTest method whenViewModelSessionUpdates_forDifferentSession_callsInProgressListenerWithNull.

@Test
public void whenViewModelSessionUpdates_forDifferentSession_callsInProgressListenerWithNull() {
    FormEntryPrompt prompt = promptWithAnswer(null);
    MutableLiveData<RecordingSession> sessionLiveData = new MutableLiveData<>(null);
    when(audioRecorder.getCurrentSession()).thenReturn(sessionLiveData);
    Consumer<Pair<Long, Integer>> listener = mock(Consumer.class);
    provider.onRecordingStatusChange(prompt, listener);
    verify(listener).accept(null);
    sessionLiveData.setValue(new RecordingSession("something else", null, 1200L, 0, false));
    verify(listener, times(2)).accept(null);
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) MutableLiveData(androidx.lifecycle.MutableLiveData) RecordingSession(org.odk.collect.audiorecorder.recording.RecordingSession) Pair(android.util.Pair) Test(org.junit.Test)

Example 7 with RecordingSession

use of org.odk.collect.audiorecorder.recording.RecordingSession in project collect by opendatakit.

the class AudioRecordingControllerFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    zip4(formEntryViewModel.hasBackgroundRecording(), backgroundAudioViewModel.isBackgroundRecordingEnabled(), audioRecorder.getCurrentSession(), audioRecorder.failedToStart()).observe(getViewLifecycleOwner(), quad -> {
        boolean hasBackgroundRecording = quad.first;
        boolean isBackgroundRecordingEnabled = quad.second;
        RecordingSession session = quad.third;
        Consumable<Exception> failedToStart = quad.fourth;
        update(hasBackgroundRecording, isBackgroundRecordingEnabled, session, failedToStart);
    });
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
        binding.pauseRecording.setVisibility(GONE);
    }
    binding.stopRecording.setOnClickListener(v -> audioRecorder.stop());
    binding.help.setOnClickListener(v -> {
        showIfNotShowing(BackgroundAudioHelpDialogFragment.class, getParentFragmentManager());
    });
}
Also used : RecordingSession(org.odk.collect.audiorecorder.recording.RecordingSession)

Example 8 with RecordingSession

use of org.odk.collect.audiorecorder.recording.RecordingSession in project collect by opendatakit.

the class BackgroundAudioViewModel method handleRecordAction.

private void handleRecordAction(TreeReference treeReference, String quality) {
    if (isBackgroundRecordingEnabled.getValue()) {
        if (permissionsChecker.isPermissionGranted(Manifest.permission.RECORD_AUDIO)) {
            if (isBackgroundRecording()) {
                RecordingSession session = audioRecorder.getCurrentSession().getValue();
                HashSet<TreeReference> treeReferences = (HashSet<TreeReference>) session.getId();
                treeReferences.add(treeReference);
            } else {
                HashSet<TreeReference> treeReferences = new HashSet<>();
                treeReferences.add(treeReference);
                startBackgroundRecording(quality, treeReferences);
            }
        } else {
            isPermissionRequired.setValue(true);
            tempTreeReferences.add(treeReference);
            if (tempQuality == null) {
                tempQuality = quality;
            }
        }
    }
}
Also used : TreeReference(org.javarosa.core.model.instance.TreeReference) RecordingSession(org.odk.collect.audiorecorder.recording.RecordingSession) HashSet(java.util.HashSet)

Aggregations

RecordingSession (org.odk.collect.audiorecorder.recording.RecordingSession)8 Test (org.junit.Test)6 TreeReference (org.javarosa.core.model.instance.TreeReference)4 MutableLiveData (androidx.lifecycle.MutableLiveData)3 File (java.io.File)3 StringData (org.javarosa.core.model.data.StringData)3 Pair (android.util.Pair)2 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)2 HashSet (java.util.HashSet)1