use of org.odk.collect.android.formentry.backgroundlocation.BackgroundLocationViewModel in project collect by opendatakit.
the class FormEntryMenuDelegateTest method setup.
@Before
public void setup() {
activity = RobolectricHelpers.createThemedActivity(AppCompatActivity.class, R.style.Theme_MaterialComponents);
FormController formController = mock(FormController.class);
answersProvider = mock(AnswersProvider.class);
formSaveViewModel = mock(FormSaveViewModel.class);
audioRecorder = mock(AudioRecorder.class);
when(audioRecorder.isRecording()).thenReturn(false);
formEntryViewModel = mock(FormEntryViewModel.class);
when(formEntryViewModel.hasBackgroundRecording()).thenReturn(new MutableNonNullLiveData<>(false));
BackgroundLocationViewModel backgroundLocationViewModel = mock(BackgroundLocationViewModel.class);
backgroundAudioViewModel = mock(BackgroundAudioViewModel.class);
when(backgroundAudioViewModel.isBackgroundRecordingEnabled()).thenReturn(new MutableNonNullLiveData<>(true));
formEntryMenuDelegate = new FormEntryMenuDelegate(activity, answersProvider, mock(FormIndexAnimationHandler.class), formSaveViewModel, formEntryViewModel, audioRecorder, backgroundLocationViewModel, backgroundAudioViewModel, TestSettingsProvider.getSettingsProvider());
formEntryMenuDelegate.formLoaded(formController);
}
use of org.odk.collect.android.formentry.backgroundlocation.BackgroundLocationViewModel 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.backgroundlocation.BackgroundLocationViewModel 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();
}
Aggregations