Search in sources :

Example 61 with ViewModelProvider

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

the class AndroidShortcutsActivity method onCreate.

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    DaggerUtils.getComponent(this).inject(this);
    BlankFormsListViewModel blankFormsListViewModel = new ViewModelProvider(this, blankFormsListViewModelFactory).get(BlankFormsListViewModel.class);
    List<BlankForm> forms = blankFormsListViewModel.getForms();
    showFormListDialog(forms);
}
Also used : BlankForm(org.odk.collect.android.formmanagement.BlankFormsListViewModel.BlankForm) BlankFormsListViewModel(org.odk.collect.android.formmanagement.BlankFormsListViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 62 with ViewModelProvider

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

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 63 with ViewModelProvider

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

the class FixedDatePickerDialog method onAttach.

@Override
public void onAttach(@NonNull Context context) {
    super.onAttach(context);
    themeUtils = new ThemeUtils(context);
    if (context instanceof CustomDatePickerDialog.DateChangeListener) {
        dateChangeListener = (CustomDatePickerDialog.DateChangeListener) context;
    }
    viewModel = new ViewModelProvider(this).get(DateTimeViewModel.class);
    viewModel.setDialogTheme(getArguments().getInt(DateTimeWidgetUtils.DIALOG_THEME));
    viewModel.setLocalDateTime((LocalDateTime) getArguments().getSerializable(DateTimeWidgetUtils.DATE));
    viewModel.setDatePickerDetails((DatePickerDetails) getArguments().getSerializable(DateTimeWidgetUtils.DATE_PICKER_DETAILS));
    viewModel.getSelectedDate().observe(this, localDateTime -> {
        if (localDateTime != null) {
            dateChangeListener.onDateChanged(localDateTime);
        }
    });
}
Also used : ThemeUtils(org.odk.collect.android.utilities.ThemeUtils) DateTimeViewModel(org.odk.collect.android.widgets.viewmodels.DateTimeViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 64 with ViewModelProvider

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

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)

Example 65 with ViewModelProvider

use of androidx.lifecycle.ViewModelProvider in project grocy-android by patzly.

the class InventoryFragment method onViewCreated.

@Override
public void onViewCreated(@Nullable View view, @Nullable Bundle savedInstanceState) {
    activity = (MainActivity) requireActivity();
    InventoryFragmentArgs args = InventoryFragmentArgs.fromBundle(requireArguments());
    viewModel = new ViewModelProvider(this, new InventoryViewModelFactory(activity.getApplication(), args)).get(InventoryViewModel.class);
    binding.setActivity(activity);
    binding.setViewModel(viewModel);
    binding.setFragment(this);
    binding.setFormData(viewModel.getFormData());
    binding.setLifecycleOwner(getViewLifecycleOwner());
    infoFullscreenHelper = new InfoFullscreenHelper(binding.container);
    // INITIALIZE VIEWS
    viewModel.getInfoFullscreenLive().observe(getViewLifecycleOwner(), infoFullscreen -> infoFullscreenHelper.setInfo(infoFullscreen));
    viewModel.getIsLoadingLive().observe(getViewLifecycleOwner(), isDownloading -> binding.swipe.setRefreshing(isDownloading));
    viewModel.getEventHandler().observeEvent(getViewLifecycleOwner(), event -> {
        if (event.getType() == Event.SNACKBAR_MESSAGE) {
            activity.showSnackbar(((SnackbarMessage) event).getSnackbar(activity, activity.binding.frameMainContainer));
        } else if (event.getType() == Event.TRANSACTION_SUCCESS) {
            assert getArguments() != null;
            if (InventoryFragmentArgs.fromBundle(getArguments()).getCloseWhenFinished()) {
                activity.navigateUp();
            } else {
                clearFormAndFocusProductInput();
            }
        } else if (event.getType() == Event.BOTTOM_SHEET) {
            BottomSheetEvent bottomSheetEvent = (BottomSheetEvent) event;
            activity.showBottomSheet(bottomSheetEvent.getBottomSheet(), event.getBundle());
        } else if (event.getType() == Event.FOCUS_INVALID_VIEWS) {
            focusNextInvalidView();
        } else if (event.getType() == Event.QUICK_MODE_ENABLED) {
            focusProductInputIfNecessary();
        } else if (event.getType() == Event.QUICK_MODE_DISABLED) {
            clearInputFocus();
        } else if (event.getType() == Event.CONTINUE_SCANNING) {
            embeddedFragmentScanner.startScannerIfVisible();
        } else if (event.getType() == Event.CHOOSE_PRODUCT) {
            String barcode = event.getBundle().getString(ARGUMENT.BARCODE);
            navigate(InventoryFragmentDirections.actionInventoryFragmentToChooseProductFragment(barcode));
        }
    });
    Integer productIdSavedSate = (Integer) getFromThisDestinationNow(Constants.ARGUMENT.PRODUCT_ID);
    if (productIdSavedSate != null) {
        removeForThisDestination(Constants.ARGUMENT.PRODUCT_ID);
        viewModel.setQueueEmptyAction(() -> viewModel.setProduct(productIdSavedSate));
    } else if (NumUtil.isStringInt(args.getProductId())) {
        int productId = Integer.parseInt(args.getProductId());
        setArguments(new InventoryFragmentArgs.Builder(args).setProductId(null).build().toBundle());
        viewModel.setQueueEmptyAction(() -> viewModel.setProduct(productId));
    }
    String barcode = (String) getFromThisDestinationNow(ARGUMENT.BARCODE);
    if (barcode != null) {
        removeForThisDestination(Constants.ARGUMENT.BARCODE);
        viewModel.addBarcodeToExistingProduct(barcode);
    }
    embeddedFragmentScanner.setScannerVisibilityLive(viewModel.getFormData().getScannerVisibilityLive());
    // following lines are necessary because no observers are set in Views
    viewModel.getFormData().getQuantityUnitStockLive().observe(getViewLifecycleOwner(), i -> {
    });
    if (savedInstanceState == null) {
        viewModel.loadFromDatabase(true);
    }
    focusProductInputIfNecessary();
    setHasOptionsMenu(true);
    updateUI(args.getAnimateStart() && savedInstanceState == null);
}
Also used : InventoryViewModelFactory(xyz.zedler.patrick.grocy.viewmodel.InventoryViewModel.InventoryViewModelFactory) BottomSheetEvent(xyz.zedler.patrick.grocy.model.BottomSheetEvent) InventoryViewModel(xyz.zedler.patrick.grocy.viewmodel.InventoryViewModel) InfoFullscreenHelper(xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

ViewModelProvider (androidx.lifecycle.ViewModelProvider)159 View (android.view.View)38 TextView (android.widget.TextView)28 BottomSheetEvent (xyz.zedler.patrick.grocy.model.BottomSheetEvent)25 Intent (android.content.Intent)24 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)24 InfoFullscreenHelper (xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper)23 Nullable (androidx.annotation.Nullable)21 Snackbar (com.google.android.material.snackbar.Snackbar)20 ClickUtil (xyz.zedler.patrick.grocy.util.ClickUtil)20 Bundle (android.os.Bundle)18 RecyclerView (androidx.recyclerview.widget.RecyclerView)18 Toolbar (androidx.appcompat.widget.Toolbar)16 SnackbarMessage (xyz.zedler.patrick.grocy.model.SnackbarMessage)16 Uri (android.net.Uri)10 ViewGroup (android.view.ViewGroup)10 NonNull (androidx.annotation.NonNull)10 Handler (android.os.Handler)9 FirebaseUiException (com.firebase.ui.auth.FirebaseUiException)8 IdpResponse (com.firebase.ui.auth.IdpResponse)8