Search in sources :

Example 11 with ClickUtil

use of xyz.zedler.patrick.grocy.util.ClickUtil 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)

Example 12 with ClickUtil

use of xyz.zedler.patrick.grocy.util.ClickUtil 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);
}
Also used : ClickUtil(xyz.zedler.patrick.grocy.util.ClickUtil) Drawable(android.graphics.drawable.Drawable) SettingsViewModel(xyz.zedler.patrick.grocy.viewmodel.SettingsViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 13 with ClickUtil

use of xyz.zedler.patrick.grocy.util.ClickUtil 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 14 with ClickUtil

use of xyz.zedler.patrick.grocy.util.ClickUtil 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)

Example 15 with ClickUtil

use of xyz.zedler.patrick.grocy.util.ClickUtil 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);
}
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

ClickUtil (xyz.zedler.patrick.grocy.util.ClickUtil)23 ViewModelProvider (androidx.lifecycle.ViewModelProvider)20 BottomSheetEvent (xyz.zedler.patrick.grocy.model.BottomSheetEvent)12 SettingsViewModel (xyz.zedler.patrick.grocy.viewmodel.SettingsViewModel)9 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)8 InfoFullscreenHelper (xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper)8 SnackbarMessage (xyz.zedler.patrick.grocy.model.SnackbarMessage)7 Snackbar (com.google.android.material.snackbar.Snackbar)6 MasterPlaceholderAdapter (xyz.zedler.patrick.grocy.adapter.MasterPlaceholderAdapter)5 InfoFullscreen (xyz.zedler.patrick.grocy.model.InfoFullscreen)5 Bundle (android.os.Bundle)4 DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)4 ArrayList (java.util.ArrayList)4 AppBarBehavior (xyz.zedler.patrick.grocy.behavior.AppBarBehavior)4 LayoutInflater (android.view.LayoutInflater)3 MenuItem (android.view.MenuItem)3 View (android.view.View)3 ViewGroup (android.view.ViewGroup)3 NonNull (androidx.annotation.NonNull)3 Nullable (androidx.annotation.Nullable)3