Search in sources :

Example 1 with FeedbackBottomSheet

use of xyz.zedler.patrick.grocy.fragment.bottomSheetDialog.FeedbackBottomSheet 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);
}
Also used : ChangelogBottomSheet(xyz.zedler.patrick.grocy.fragment.bottomSheetDialog.ChangelogBottomSheet) OverviewStartViewModel(xyz.zedler.patrick.grocy.viewmodel.OverviewStartViewModel) ClickUtil(xyz.zedler.patrick.grocy.util.ClickUtil) FeedbackBottomSheet(xyz.zedler.patrick.grocy.fragment.bottomSheetDialog.FeedbackBottomSheet) InfoFullscreenHelper(xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 ChangelogBottomSheet (xyz.zedler.patrick.grocy.fragment.bottomSheetDialog.ChangelogBottomSheet)1 FeedbackBottomSheet (xyz.zedler.patrick.grocy.fragment.bottomSheetDialog.FeedbackBottomSheet)1 InfoFullscreenHelper (xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper)1 ClickUtil (xyz.zedler.patrick.grocy.util.ClickUtil)1 OverviewStartViewModel (xyz.zedler.patrick.grocy.viewmodel.OverviewStartViewModel)1