use of androidx.lifecycle.ViewModelProvider in project grocy-android by patzly.
the class OverviewStartFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
viewModel = new ViewModelProvider(this).get(OverviewStartViewModel.class);
viewModel.setOfflineLive(!activity.isOnline());
binding.setViewModel(viewModel);
binding.setFragment(this);
binding.setActivity(activity);
binding.setLifecycleOwner(getViewLifecycleOwner());
clickUtil = new ClickUtil(1000);
viewModel.getIsLoadingLive().observe(getViewLifecycleOwner(), state -> {
if (!state) {
viewModel.setCurrentQueueLoading(null);
}
});
viewModel.getEventHandler().observeEvent(getViewLifecycleOwner(), event -> {
if (event.getType() == Event.SNACKBAR_MESSAGE) {
activity.showSnackbar(((SnackbarMessage) event).getSnackbar(activity, activity.binding.frameMainContainer));
}
});
infoFullscreenHelper = new InfoFullscreenHelper(binding.frameContainer);
viewModel.getInfoFullscreenLive().observe(getViewLifecycleOwner(), infoFullscreen -> infoFullscreenHelper.setInfo(infoFullscreen));
viewModel.getOfflineLive().observe(getViewLifecycleOwner(), this::appBarOfflineInfo);
binding.toolbar.setOnMenuItemClickListener(item -> {
int id = item.getItemId();
if (id == R.id.action_settings) {
navigateDeepLink(getString(R.string.deep_link_settingsFragment));
} else if (id == R.id.action_about) {
navigateDeepLink(getString(R.string.deep_link_aboutFragment));
} else if (id == R.id.action_feedback) {
activity.showBottomSheet(new FeedbackBottomSheet());
} else if (id == R.id.action_changelog) {
activity.showBottomSheet(new ChangelogBottomSheet());
}
return false;
});
// for offline info in app bar
binding.swipe.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
if (savedInstanceState == null) {
viewModel.loadFromDatabase(true);
}
// UPDATE UI
updateUI((getArguments() == null || getArguments().getBoolean(Constants.ARGUMENT.ANIMATED, true)) && savedInstanceState == null);
}
use of androidx.lifecycle.ViewModelProvider in project grocy-android by patzly.
the class SettingsCatAppearanceFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
viewModel = new ViewModelProvider(this).get(SettingsViewModel.class);
binding.setActivity(activity);
binding.setFragment(this);
binding.setViewModel(viewModel);
binding.setClickUtil(new ClickUtil());
binding.setLifecycleOwner(getViewLifecycleOwner());
int theme = viewModel.getTheme();
boolean currentlyDark = isSystemThemeDark();
Drawable imageLightToDark = ContextCompat.getDrawable(requireContext(), R.drawable.ic_round_light_to_dark_anim);
Drawable imageDarkToLight = ContextCompat.getDrawable(requireContext(), R.drawable.ic_round_dark_to_light_anim);
if (theme == SettingsViewModel.THEME_SYSTEM) {
binding.imageTheme.setImageDrawable(currentlyDark ? imageDarkToLight : imageLightToDark);
} else if (theme == SettingsViewModel.THEME_LIGHT) {
binding.imageTheme.setImageDrawable(imageLightToDark);
} else {
// dark
binding.imageTheme.setImageDrawable(imageDarkToLight);
}
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);
}
use of androidx.lifecycle.ViewModelProvider 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);
}
use of androidx.lifecycle.ViewModelProvider 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);
}
use of androidx.lifecycle.ViewModelProvider in project grocy-android by patzly.
the class SettingsCatShoppingModeFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
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);
}
Aggregations