Search in sources :

Example 1 with ExternalAppRecordingRequester

use of org.odk.collect.android.widgets.utilities.ExternalAppRecordingRequester in project collect by opendatakit.

the class FormEntryActivity method setupViewModels.

private void setupViewModels() {
    backgroundLocationViewModel = ViewModelProviders.of(this, new BackgroundLocationViewModel.Factory(permissionsProvider, settingsProvider.getUnprotectedSettings())).get(BackgroundLocationViewModel.class);
    backgroundAudioViewModel = new ViewModelProvider(this, backgroundAudioViewModelFactory).get(BackgroundAudioViewModel.class);
    backgroundAudioViewModel.isPermissionRequired().observe(this, isPermissionRequired -> {
        if (isPermissionRequired) {
            showIfNotShowing(BackgroundAudioPermissionDialogFragment.class, getSupportFragmentManager());
        }
    });
    identityPromptViewModel = ViewModelProviders.of(this).get(IdentityPromptViewModel.class);
    identityPromptViewModel.requiresIdentityToContinue().observe(this, requiresIdentity -> {
        if (requiresIdentity) {
            showIfNotShowing(IdentifyUserPromptDialogFragment.class, getSupportFragmentManager());
        }
    });
    identityPromptViewModel.isFormEntryCancelled().observe(this, isFormEntryCancelled -> {
        if (isFormEntryCancelled) {
            finish();
        }
    });
    formEntryViewModel = ViewModelProviders.of(this, formEntryViewModelFactory).get(FormEntryViewModel.class);
    formEntryViewModel.getError().observe(this, error -> {
        if (error instanceof FormEntryViewModel.NonFatal) {
            createErrorDialog(((FormEntryViewModel.NonFatal) error).getMessage(), false);
            formEntryViewModel.errorDisplayed();
        }
    });
    formSaveViewModel = new ViewModelProvider(this, formSaveViewModelFactoryFactory.create(this, null)).get(FormSaveViewModel.class);
    formSaveViewModel.getSaveResult().observe(this, this::handleSaveResult);
    formSaveViewModel.isSavingAnswerFile().observe(this, isSavingAnswerFile -> {
        if (isSavingAnswerFile) {
            DialogFragmentUtils.showIfNotShowing(SaveAnswerFileProgressDialogFragment.class, getSupportFragmentManager());
        } else {
            DialogFragmentUtils.dismissDialog(SaveAnswerFileProgressDialogFragment.class, getSupportFragmentManager());
        }
    });
    formSaveViewModel.getAnswerFileError().observe(this, file -> {
        if (file != null) {
            DialogFragmentUtils.showIfNotShowing(SaveAnswerFileErrorDialogFragment.class, getSupportFragmentManager());
        }
    });
    internalRecordingRequester = new InternalRecordingRequester(this, audioRecorder, permissionsProvider, formEntryViewModel);
    waitingForDataRegistry = new FormControllerWaitingForDataRegistry();
    externalAppRecordingRequester = new ExternalAppRecordingRequester(this, intentLauncher, waitingForDataRegistry, permissionsProvider, formEntryViewModel);
    RecordingHandler recordingHandler = new RecordingHandler(formSaveViewModel, this, audioRecorder, new AMRAppender(), new M4AAppender());
    audioRecorder.getCurrentSession().observe(this, session -> {
        if (session != null && session.getFile() != null) {
            recordingHandler.handle(getFormController(), session, success -> {
                if (success) {
                    onScreenRefresh();
                    formSaveViewModel.resumeSave();
                } else {
                    String path = session.getFile().getAbsolutePath();
                    String message = getString(R.string.answer_file_copy_failed_message, path);
                    Toast.makeText(this, message, Toast.LENGTH_LONG).show();
                }
            });
        }
    });
}
Also used : BackgroundLocationViewModel(org.odk.collect.android.formentry.backgroundlocation.BackgroundLocationViewModel) IdentityPromptViewModel(org.odk.collect.android.formentry.audit.IdentityPromptViewModel) ExternalAppRecordingRequester(org.odk.collect.android.widgets.utilities.ExternalAppRecordingRequester) FormEntryViewModel(org.odk.collect.android.formentry.FormEntryViewModel) RecordingHandler(org.odk.collect.android.formentry.RecordingHandler) AMRAppender(org.odk.collect.android.audio.AMRAppender) FormSaveViewModel(org.odk.collect.android.formentry.saving.FormSaveViewModel) BackgroundAudioViewModel(org.odk.collect.android.formentry.BackgroundAudioViewModel) InternalRecordingRequester(org.odk.collect.android.widgets.utilities.InternalRecordingRequester) FormControllerWaitingForDataRegistry(org.odk.collect.android.widgets.utilities.FormControllerWaitingForDataRegistry) M4AAppender(org.odk.collect.android.audio.M4AAppender) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 AMRAppender (org.odk.collect.android.audio.AMRAppender)1 M4AAppender (org.odk.collect.android.audio.M4AAppender)1 BackgroundAudioViewModel (org.odk.collect.android.formentry.BackgroundAudioViewModel)1 FormEntryViewModel (org.odk.collect.android.formentry.FormEntryViewModel)1 RecordingHandler (org.odk.collect.android.formentry.RecordingHandler)1 IdentityPromptViewModel (org.odk.collect.android.formentry.audit.IdentityPromptViewModel)1 BackgroundLocationViewModel (org.odk.collect.android.formentry.backgroundlocation.BackgroundLocationViewModel)1 FormSaveViewModel (org.odk.collect.android.formentry.saving.FormSaveViewModel)1 ExternalAppRecordingRequester (org.odk.collect.android.widgets.utilities.ExternalAppRecordingRequester)1 FormControllerWaitingForDataRegistry (org.odk.collect.android.widgets.utilities.FormControllerWaitingForDataRegistry)1 InternalRecordingRequester (org.odk.collect.android.widgets.utilities.InternalRecordingRequester)1