use of xyz.zedler.patrick.grocy.adapter.ShoppingModeItemAdapter in project grocy-android by patzly.
the class ShoppingModeFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
viewModel = new ViewModelProvider(this).get(ShoppingModeViewModel.class);
viewModel.setOfflineLive(!activity.isOnline());
binding.setViewModel(viewModel);
binding.setActivity(activity);
binding.setFragment(this);
binding.setLifecycleOwner(getViewLifecycleOwner());
infoFullscreenHelper = new InfoFullscreenHelper(binding.frame);
clickUtil = new ClickUtil();
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
debug = PrefsUtil.isDebuggingEnabled(sharedPrefs);
handler = new Handler();
if (savedInstanceState == null) {
binding.recycler.scrollTo(0, 0);
}
binding.recycler.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
binding.recycler.setAdapter(new ShoppingPlaceholderAdapter());
viewModel.getIsLoadingLive().observe(getViewLifecycleOwner(), state -> {
if (!state) {
viewModel.setCurrentQueueLoading(null);
}
});
viewModel.getInfoFullscreenLive().observe(getViewLifecycleOwner(), infoFullscreen -> infoFullscreenHelper.setInfo(infoFullscreen));
viewModel.getSelectedShoppingListIdLive().observe(getViewLifecycleOwner(), this::changeAppBarTitle);
viewModel.getFilteredGroupedListItemsLive().observe(getViewLifecycleOwner(), items -> {
if (items == null) {
return;
}
if (items.isEmpty()) {
InfoFullscreen info = new InfoFullscreen(InfoFullscreen.INFO_EMPTY_SHOPPING_LIST);
viewModel.getInfoFullscreenLive().setValue(info);
} else {
viewModel.getInfoFullscreenLive().setValue(null);
}
if (binding.recycler.getAdapter() instanceof ShoppingModeItemAdapter) {
((ShoppingModeItemAdapter) binding.recycler.getAdapter()).updateData(items, viewModel.getProductHashMap(), viewModel.getQuantityUnitHashMap(), viewModel.getShoppingListItemAmountsHashMap(), viewModel.getMissingProductIds());
} else {
binding.recycler.setAdapter(new ShoppingModeItemAdapter(activity, (LinearLayoutManager) binding.recycler.getLayoutManager(), items, viewModel.getProductHashMap(), viewModel.getQuantityUnitHashMap(), viewModel.getShoppingListItemAmountsHashMap(), viewModel.getMissingProductIds(), this, sharedPrefs.getBoolean(SHOPPING_MODE.USE_SMALLER_FONT, SETTINGS_DEFAULT.SHOPPING_MODE.USE_SMALLER_FONT), sharedPrefs.getBoolean(SHOPPING_MODE.SHOW_PRODUCT_DESCRIPTION, SETTINGS_DEFAULT.SHOPPING_MODE.SHOW_PRODUCT_DESCRIPTION)));
binding.recycler.scheduleLayoutAnimation();
}
});
viewModel.getEventHandler().observeEvent(getViewLifecycleOwner(), event -> {
if (event.getType() == Event.SNACKBAR_MESSAGE) {
activity.showSnackbar(((SnackbarMessage) event).getSnackbar(activity, activity.binding.frameMainContainer));
}
});
hideDisabledFeatures();
if (savedInstanceState == null) {
viewModel.loadFromDatabase(true);
}
updateUI(ShoppingModeFragmentArgs.fromBundle(requireArguments()).getAnimateStart() && savedInstanceState == null);
}
Aggregations