Search in sources :

Example 1 with SettingsViewModel

use of xyz.zedler.patrick.grocy.viewmodel.SettingsViewModel in project grocy-android by patzly.

the class SettingsCatDebuggingFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    activity = (MainActivity) requireActivity();
    SettingsViewModel viewModel = new ViewModelProvider(this).get(SettingsViewModel.class);
    binding.setActivity(activity);
    binding.setFragment(this);
    binding.setViewModel(viewModel);
    binding.setSharedPrefs(PreferenceManager.getDefaultSharedPreferences(activity));
    binding.setClickUtil(new ClickUtil());
    binding.setLifecycleOwner(getViewLifecycleOwner());
    viewModel.getEventHandler().observe(getViewLifecycleOwner(), event -> {
        if (event.getType() == Event.SNACKBAR_MESSAGE) {
            activity.showSnackbar(((SnackbarMessage) event).getSnackbar(activity, activity.binding.frameMainContainer));
        } else if (event.getType() == Event.BOTTOM_SHEET) {
            BottomSheetEvent bottomSheetEvent = (BottomSheetEvent) event;
            activity.showBottomSheet(bottomSheetEvent.getBottomSheet(), event.getBundle());
        }
    });
    if (activity.binding.bottomAppBar.getVisibility() == View.VISIBLE) {
        activity.getScrollBehavior().setUpScroll(binding.scroll);
        activity.getScrollBehavior().setHideOnScroll(true);
        activity.updateBottomAppBar(Constants.FAB.POSITION.GONE, R.menu.menu_empty, false, () -> {
        });
        activity.binding.fabMain.hide();
    }
    setForPreviousDestination(Constants.ARGUMENT.ANIMATED, false);
}
Also used : BottomSheetEvent(xyz.zedler.patrick.grocy.model.BottomSheetEvent) ClickUtil(xyz.zedler.patrick.grocy.util.ClickUtil) SettingsViewModel(xyz.zedler.patrick.grocy.viewmodel.SettingsViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 2 with SettingsViewModel

use of xyz.zedler.patrick.grocy.viewmodel.SettingsViewModel in project grocy-android by patzly.

the class SettingsCatScannerFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    activity = (MainActivity) requireActivity();
    SettingsViewModel viewModel = new ViewModelProvider(this).get(SettingsViewModel.class);
    binding.setActivity(activity);
    binding.setFragment(this);
    binding.setViewModel(viewModel);
    binding.setSharedPrefs(PreferenceManager.getDefaultSharedPreferences(activity));
    binding.setClickUtil(new ClickUtil());
    binding.setLifecycleOwner(getViewLifecycleOwner());
    viewModel.getEventHandler().observe(getViewLifecycleOwner(), event -> {
        if (event.getType() == Event.SNACKBAR_MESSAGE) {
            activity.showSnackbar(((SnackbarMessage) event).getSnackbar(activity, activity.binding.frameMainContainer));
        } else if (event.getType() == Event.BOTTOM_SHEET) {
            BottomSheetEvent bottomSheetEvent = (BottomSheetEvent) event;
            activity.showBottomSheet(bottomSheetEvent.getBottomSheet(), event.getBundle());
        }
    });
    updateBarcodeFormats();
    if (activity.binding.bottomAppBar.getVisibility() == View.VISIBLE) {
        activity.getScrollBehavior().setUpScroll(binding.scroll);
        activity.getScrollBehavior().setHideOnScroll(true);
        activity.updateBottomAppBar(Constants.FAB.POSITION.GONE, R.menu.menu_empty, false, () -> {
        });
        activity.binding.fabMain.hide();
    }
    setForPreviousDestination(Constants.ARGUMENT.ANIMATED, false);
}
Also used : BottomSheetEvent(xyz.zedler.patrick.grocy.model.BottomSheetEvent) ClickUtil(xyz.zedler.patrick.grocy.util.ClickUtil) SettingsViewModel(xyz.zedler.patrick.grocy.viewmodel.SettingsViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

ViewModelProvider (androidx.lifecycle.ViewModelProvider)2 BottomSheetEvent (xyz.zedler.patrick.grocy.model.BottomSheetEvent)2 ClickUtil (xyz.zedler.patrick.grocy.util.ClickUtil)2 SettingsViewModel (xyz.zedler.patrick.grocy.viewmodel.SettingsViewModel)2