use of org.odk.collect.android.formentry.BackgroundAudioViewModel 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();
}
});
}
});
}
use of org.odk.collect.android.formentry.BackgroundAudioViewModel in project collect by opendatakit.
the class FormEntryActivity method onCreate.
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
// this issue by including WebViews
if (Build.VERSION.SDK_INT >= 24) {
try {
new WebView(this);
} catch (Exception | Error e) {
// Don't crash if WebView not available
}
}
super.onCreate(savedInstanceState);
Collect.getInstance().getComponent().inject(this);
formsRepository = formsRepositoryProvider.get();
setContentView(R.layout.form_entry);
setupViewModels();
swipeHandler = new SwipeHandler(this, settingsProvider.getUnprotectedSettings());
compositeDisposable.add(eventBus.register(ReadPhoneStatePermissionRxEvent.class).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(event -> {
readPhoneStatePermissionRequestNeeded = true;
}));
errorMessage = null;
questionHolder = findViewById(R.id.questionholder);
initToolbar();
formIndexAnimationHandler = new FormIndexAnimationHandler(this);
menuDelegate = new FormEntryMenuDelegate(this, () -> getAnswers(), formIndexAnimationHandler, formSaveViewModel, formEntryViewModel, audioRecorder, backgroundLocationViewModel, backgroundAudioViewModel, settingsProvider);
nextButton = findViewById(R.id.form_forward_button);
nextButton.setOnClickListener(v -> {
swipeHandler.setBeenSwiped(true);
onSwipeForward();
});
backButton = findViewById(R.id.form_back_button);
backButton.setOnClickListener(v -> {
swipeHandler.setBeenSwiped(true);
onSwipeBackward();
});
if (savedInstanceState == null) {
mediaLoadingFragment = new MediaLoadingFragment();
getSupportFragmentManager().beginTransaction().add(mediaLoadingFragment, TAG_MEDIA_LOADING_FRAGMENT).commit();
} else {
mediaLoadingFragment = (MediaLoadingFragment) getSupportFragmentManager().findFragmentByTag(TAG_MEDIA_LOADING_FRAGMENT);
}
setupFields(savedInstanceState);
loadForm();
}
use of org.odk.collect.android.formentry.BackgroundAudioViewModel in project collect by opendatakit.
the class AudioRecordingControllerFragmentTest method setup.
@Before
public void setup() throws IOException {
File stubRecording = File.createTempFile("test", ".m4a");
stubRecording.deleteOnExit();
audioRecorder = new StubAudioRecorder(stubRecording.getAbsolutePath());
backgroundAudioViewModel = mock(BackgroundAudioViewModel.class);
formEntryViewModel = mock(FormEntryViewModel.class);
hasBackgroundRecording = new MutableNonNullLiveData<>(false);
when(formEntryViewModel.hasBackgroundRecording()).thenReturn(hasBackgroundRecording);
isBackgroundRecordingEnabled = new MutableNonNullLiveData<>(false);
when(backgroundAudioViewModel.isBackgroundRecordingEnabled()).thenReturn(isBackgroundRecordingEnabled);
externalWebPageHelper = mock(ExternalWebPageHelper.class);
CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {
@Override
public BackgroundAudioViewModel.Factory providesBackgroundAudioViewModelFactory(AudioRecorder audioRecorder, SettingsProvider settingsProvider, PermissionsChecker permissionsChecker, Analytics analytics) {
return new BackgroundAudioViewModel.Factory(audioRecorder, settingsProvider.getUnprotectedSettings(), permissionsChecker, System::currentTimeMillis) {
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
return (T) backgroundAudioViewModel;
}
};
}
@Override
public FormEntryViewModel.Factory providesFormEntryViewModelFactory(Analytics analytics) {
return new FormEntryViewModel.Factory(System::currentTimeMillis) {
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
return (T) formEntryViewModel;
}
};
}
@Override
public AudioRecorder providesAudioRecorder(Application application) {
return audioRecorder;
}
@Override
public ExternalWebPageHelper providesExternalWebPageHelper() {
return externalWebPageHelper;
}
});
}
Aggregations