Search in sources :

Example 31 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider 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)

Example 32 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project collect by opendatakit.

the class SaveAnswerFileErrorDialogFragment method onAttach.

@Override
public void onAttach(@NonNull Context context) {
    super.onAttach(context);
    DaggerUtils.getComponent(context).inject(this);
    ViewModelProvider viewModelProvider = new ViewModelProvider(requireActivity(), formSaveViewModelFactoryFactory.create(requireActivity(), null));
    formSaveViewModel = viewModelProvider.get(FormSaveViewModel.class);
}
Also used : ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 33 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project collect by opendatakit.

the class FormMapActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    DaggerUtils.getComponent(this).inject(this);
    setContentView(R.layout.form_map_activity);
    Form form = loadForm();
    selectionMapViewModel = new ViewModelProvider(this).get(SelectionMapViewModel.class);
    selectionMapViewModel.setMapTitle(form.getDisplayName());
    FormNavigator formNavigator = new FormNavigator(currentProjectProvider, settingsProvider, instancesRepositoryProvider::get);
    getSupportFragmentManager().setFragmentResultListener(SelectionMapFragment.REQUEST_SELECT_ITEM, this, (requestKey, result) -> {
        if (result.containsKey(SelectionMapFragment.RESULT_SELECTED_ITEM)) {
            long instanceId = result.getLong(SelectionMapFragment.RESULT_SELECTED_ITEM);
            formNavigator.editInstance(this, instanceId);
        } else if (result.containsKey(SelectionMapFragment.RESULT_CREATE_NEW_ITEM)) {
            formNavigator.newInstance(this, form.getDbId());
        }
    });
}
Also used : SelectionMapViewModel(org.odk.collect.geo.SelectionMapViewModel) Form(org.odk.collect.forms.Form) FormNavigator(org.odk.collect.android.formmanagement.FormNavigator) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 34 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project collect by opendatakit.

the class FormMapActivity method loadForm.

@Nullable
private Form loadForm() {
    Form form = formsRepositoryProvider.get().get(getIntent().getLongExtra(EXTRA_FORM_ID, -1));
    FormMapViewModelFactory viewModelFactory = new FormMapViewModelFactory(form, instancesRepositoryProvider.get());
    formMapViewModel = new ViewModelProvider(this, viewModelFactory).get(FormMapViewModel.class);
    return form;
}
Also used : Form(org.odk.collect.forms.Form) FormMapViewModel(org.odk.collect.android.activities.viewmodels.FormMapViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider) Nullable(androidx.annotation.Nullable)

Example 35 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project collect by opendatakit.

the class BaseSelectListWidget method setUpSearchBox.

private void setUpSearchBox() {
    ComponentActivity activity = (ComponentActivity) getContext();
    SearchQueryViewModel searchQueryViewModel = new ViewModelProvider(activity).get(SearchQueryViewModel.class);
    binding.choicesSearchBox.setVisibility(View.VISIBLE);
    binding.choicesSearchBox.setTextSize(TypedValue.COMPLEX_UNIT_DIP, getAnswerFontSize());
    binding.choicesSearchBox.addTextChangedListener(new TextWatcher() {

        private String oldText = "";

        @Override
        public void afterTextChanged(Editable s) {
            if (!s.toString().equals(oldText)) {
                recyclerViewAdapter.getFilter().filter(s.toString());
                searchQueryViewModel.setQuery(getFormEntryPrompt().getIndex().toString(), s.toString());
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            oldText = s.toString();
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
    binding.choicesSearchBox.setText(searchQueryViewModel.getQuery(getFormEntryPrompt().getIndex().toString()));
}
Also used : ComponentActivity(androidx.activity.ComponentActivity) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) SearchQueryViewModel(org.odk.collect.android.widgets.utilities.SearchQueryViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

ViewModelProvider (androidx.lifecycle.ViewModelProvider)56 TextView (android.widget.TextView)13 Intent (android.content.Intent)12 View (android.view.View)11 FirebaseUiException (com.firebase.ui.auth.FirebaseUiException)8 IdpResponse (com.firebase.ui.auth.IdpResponse)8 Bundle (android.os.Bundle)7 Toolbar (androidx.appcompat.widget.Toolbar)7 FirebaseAuthAnonymousUpgradeException (com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException)7 Handler (android.os.Handler)6 HandlerThread (android.os.HandlerThread)5 SpannableStringBuilder (android.text.SpannableStringBuilder)5 Nullable (androidx.annotation.Nullable)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)5 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)4 Animator (android.animation.Animator)3 Bitmap (android.graphics.Bitmap)3 BitmapDrawable (android.graphics.drawable.BitmapDrawable)3 Uri (android.net.Uri)3 FragmentManager (androidx.fragment.app.FragmentManager)3