use of org.odk.collect.android.audio.M4AAppender 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();
}
});
}
});
}
Aggregations