use of xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper in project grocy-android by patzly.
the class TasksFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
viewModel = new ViewModelProvider(this).get(TasksViewModel.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();
// APP BAR BEHAVIOR
appBarBehavior = new AppBarBehavior(activity, binding.appBarDefault, binding.appBarSearch, savedInstanceState);
binding.recycler.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
binding.recycler.setAdapter(new MasterPlaceholderAdapter());
if (savedInstanceState == null) {
binding.recycler.scrollToPosition(0);
viewModel.resetSearch();
}
viewModel.getIsLoadingLive().observe(getViewLifecycleOwner(), state -> {
if (!state) {
viewModel.setCurrentQueueLoading(null);
}
});
viewModel.getInfoFullscreenLive().observe(getViewLifecycleOwner(), infoFullscreen -> infoFullscreenHelper.setInfo(infoFullscreen));
viewModel.getFilteredTasksLive().observe(getViewLifecycleOwner(), items -> {
if (items == null) {
return;
}
if (items.isEmpty()) {
InfoFullscreen info;
if (viewModel.isSearchActive()) {
info = new InfoFullscreen(InfoFullscreen.INFO_NO_SEARCH_RESULTS);
} else {
info = new InfoFullscreen(InfoFullscreen.INFO_EMPTY_TASKS);
}
viewModel.getInfoFullscreenLive().setValue(info);
} else {
viewModel.getInfoFullscreenLive().setValue(null);
}
if (binding.recycler.getAdapter() instanceof TasksItemAdapter) {
((TasksItemAdapter) binding.recycler.getAdapter()).updateData(items, viewModel.getSortMode());
} else {
binding.recycler.setAdapter(new TasksItemAdapter(requireContext(), items, this, viewModel.getSortMode()));
}
});
viewModel.getEventHandler().observeEvent(getViewLifecycleOwner(), event -> {
if (event.getType() == Event.SNACKBAR_MESSAGE) {
activity.showSnackbar(((SnackbarMessage) event).getSnackbar(activity, activity.binding.frameMainContainer));
}
});
if (swipeBehavior == null) {
swipeBehavior = new SwipeBehavior(activity, swipeStarted -> binding.swipe.setEnabled(!swipeStarted)) {
@Override
public void instantiateUnderlayButton(RecyclerView.ViewHolder viewHolder, List<UnderlayButton> underlayButtons) {
int position = viewHolder.getAdapterPosition();
ArrayList<Task> displayedItems = viewModel.getFilteredTasksLive().getValue();
if (displayedItems == null || position < 0 || position >= displayedItems.size()) {
return;
}
Task task = displayedItems.get(position);
underlayButtons.add(new UnderlayButton(R.drawable.ic_round_done, pos -> {
if (pos >= displayedItems.size()) {
return;
}
swipeBehavior.recoverLatestSwipedItem();
viewModel.performAction(ACTION.UNDO, displayedItems.get(pos));
}));
}
};
}
swipeBehavior.attachToRecyclerView(binding.recycler);
hideDisabledFeatures();
if (savedInstanceState == null) {
viewModel.loadFromDatabase(true);
}
updateUI(savedInstanceState == null);
}
use of xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper in project grocy-android by patzly.
the class ConsumeFragment method onViewCreated.
@Override
public void onViewCreated(@Nullable View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
ConsumeFragmentArgs args = ConsumeFragmentArgs.fromBundle(requireArguments());
viewModel = new ViewModelProvider(this, new ConsumeViewModel.ConsumeViewModelFactory(activity.getApplication(), args)).get(ConsumeViewModel.class);
binding.setActivity(activity);
binding.setViewModel(viewModel);
binding.setFragment(this);
binding.setFormData(viewModel.getFormData());
binding.setLifecycleOwner(getViewLifecycleOwner());
infoFullscreenHelper = new InfoFullscreenHelper(binding.container);
viewModel.getInfoFullscreenLive().observe(getViewLifecycleOwner(), infoFullscreen -> infoFullscreenHelper.setInfo(infoFullscreen));
viewModel.getIsLoadingLive().observe(getViewLifecycleOwner(), isDownloading -> binding.swipe.setRefreshing(isDownloading));
viewModel.getEventHandler().observeEvent(getViewLifecycleOwner(), event -> {
if (event.getType() == Event.SNACKBAR_MESSAGE) {
activity.showSnackbar(((SnackbarMessage) event).getSnackbar(activity, activity.binding.frameMainContainer));
} else if (event.getType() == Event.CONSUME_SUCCESS) {
assert getArguments() != null;
if (PurchaseFragmentArgs.fromBundle(getArguments()).getCloseWhenFinished()) {
activity.navigateUp();
} else {
viewModel.getFormData().clearForm();
focusProductInputIfNecessary();
embeddedFragmentScanner.startScannerIfVisible();
}
} else if (event.getType() == Event.BOTTOM_SHEET) {
BottomSheetEvent bottomSheetEvent = (BottomSheetEvent) event;
activity.showBottomSheet(bottomSheetEvent.getBottomSheet(), event.getBundle());
} else if (event.getType() == Event.FOCUS_INVALID_VIEWS) {
focusNextInvalidView();
} else if (event.getType() == Event.QUICK_MODE_ENABLED) {
focusProductInputIfNecessary();
} else if (event.getType() == Event.QUICK_MODE_DISABLED) {
clearInputFocus();
} else if (event.getType() == Event.CONTINUE_SCANNING) {
embeddedFragmentScanner.startScannerIfVisible();
} else if (event.getType() == Event.CHOOSE_PRODUCT) {
String barcode = event.getBundle().getString(ARGUMENT.BARCODE);
navigate(ConsumeFragmentDirections.actionConsumeFragmentToChooseProductFragment(barcode).setForbidCreateProduct(true));
}
});
Integer productIdSavedSate = (Integer) getFromThisDestinationNow(Constants.ARGUMENT.PRODUCT_ID);
if (productIdSavedSate != null) {
removeForThisDestination(Constants.ARGUMENT.PRODUCT_ID);
viewModel.setQueueEmptyAction(() -> viewModel.setProduct(productIdSavedSate, null, null));
} else if (NumUtil.isStringInt(args.getProductId())) {
int productId = Integer.parseInt(args.getProductId());
setArguments(new ConsumeFragmentArgs.Builder(args).setProductId(null).build().toBundle());
viewModel.setQueueEmptyAction(() -> viewModel.setProduct(productId, null, null));
}
String barcode = (String) getFromThisDestinationNow(ARGUMENT.BARCODE);
if (barcode != null) {
removeForThisDestination(Constants.ARGUMENT.BARCODE);
viewModel.addBarcodeToExistingProduct(barcode);
}
embeddedFragmentScanner.setScannerVisibilityLive(viewModel.getFormData().getScannerVisibilityLive());
// following line is necessary because no observers are set in Views
viewModel.getFormData().getQuantityUnitStockLive().observe(getViewLifecycleOwner(), i -> {
});
viewModel.getFormData().getProductDetailsLive().observe(getViewLifecycleOwner(), productDetails -> {
MenuItem menuItem = activity.getBottomMenu().findItem(R.id.action_open);
if (productDetails != null && productDetails.getProduct().getEnableTareWeightHandlingBoolean() || menuItem == null || !viewModel.isFeatureEnabled(PREF.FEATURE_STOCK_OPENED_TRACKING)) {
return;
}
menuItem.setVisible(productDetails != null);
});
if (savedInstanceState == null) {
viewModel.loadFromDatabase(true);
}
focusProductInputIfNecessary();
updateUI(args.getAnimateStart() && savedInstanceState == null);
}
use of xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper in project grocy-android by patzly.
the class MasterDataOverviewFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
viewModel = new ViewModelProvider(this).get(MasterDataOverviewViewModel.class);
viewModel.setOfflineLive(!activity.isOnline());
binding.back.setOnClickListener(v -> activity.navigateUp());
binding.linearProducts.setOnClickListener(v -> navigate(MasterDataOverviewFragmentDirections.actionMasterDataOverviewFragmentToMasterObjectListFragment(GrocyApi.ENTITY.PRODUCTS)));
binding.linearQuantityUnits.setOnClickListener(v -> navigate(MasterDataOverviewFragmentDirections.actionMasterDataOverviewFragmentToMasterObjectListFragment(GrocyApi.ENTITY.QUANTITY_UNITS)));
binding.linearLocations.setOnClickListener(v -> navigate(MasterDataOverviewFragmentDirections.actionMasterDataOverviewFragmentToMasterObjectListFragment(GrocyApi.ENTITY.LOCATIONS)));
binding.linearProductGroups.setOnClickListener(v -> navigate(MasterDataOverviewFragmentDirections.actionMasterDataOverviewFragmentToMasterObjectListFragment(GrocyApi.ENTITY.PRODUCT_GROUPS)));
binding.linearStores.setOnClickListener(v -> navigate(MasterDataOverviewFragmentDirections.actionMasterDataOverviewFragmentToMasterObjectListFragment(GrocyApi.ENTITY.STORES)));
binding.linearTaskCategories.setOnClickListener(v -> navigate(MasterDataOverviewFragmentDirections.actionMasterDataOverviewFragmentToMasterObjectListFragment(GrocyApi.ENTITY.TASK_CATEGORIES)));
viewModel.getIsLoadingLive().observe(getViewLifecycleOwner(), state -> {
binding.swipe.setRefreshing(state);
if (!state) {
viewModel.setCurrentQueueLoading(null);
}
});
binding.swipe.setOnRefreshListener(() -> viewModel.downloadDataForceUpdate());
binding.swipe.setProgressBackgroundColorSchemeColor(ContextCompat.getColor(activity, R.color.surface));
binding.swipe.setColorSchemeColors(ContextCompat.getColor(activity, R.color.secondary));
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);
viewModel.getProductsLive().observe(getViewLifecycleOwner(), products -> binding.countProducts.setText(products != null ? String.valueOf(products.size()) : getString(R.string.subtitle_unknown)));
viewModel.getLocationsLive().observe(getViewLifecycleOwner(), locations -> binding.countLocations.setText(locations != null ? String.valueOf(locations.size()) : getString(R.string.subtitle_unknown)));
viewModel.getStoresLive().observe(getViewLifecycleOwner(), stores -> binding.countStores.setText(stores != null ? String.valueOf(stores.size()) : getString(R.string.subtitle_unknown)));
viewModel.getQuantityUnitsLive().observe(getViewLifecycleOwner(), quantityUnits -> binding.countQuantityUnits.setText(quantityUnits != null ? String.valueOf(quantityUnits.size()) : getString(R.string.subtitle_unknown)));
viewModel.getProductGroupsLive().observe(getViewLifecycleOwner(), productGroups -> binding.countProductGroups.setText(productGroups != null ? String.valueOf(productGroups.size()) : getString(R.string.subtitle_unknown)));
viewModel.getTaskCategoriesLive().observe(getViewLifecycleOwner(), taskCategories -> binding.countTaskCategories.setText(taskCategories != null ? String.valueOf(taskCategories.size()) : getString(R.string.subtitle_unknown)));
// for offline info in app bar
binding.swipe.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
if (savedInstanceState == null) {
viewModel.loadFromDatabase(true);
}
hideDisabledFeatures();
// UPDATE UI
updateUI((getArguments() == null || getArguments().getBoolean(Constants.ARGUMENT.ANIMATED, true)) && savedInstanceState == null);
}
use of xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper in project grocy-android by patzly.
the class MasterProductCatLocationFragment method onViewCreated.
@Override
public void onViewCreated(@Nullable View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
MasterProductFragmentArgs args = MasterProductFragmentArgs.fromBundle(requireArguments());
viewModel = new ViewModelProvider(this, new MasterProductCatLocationViewModel.MasterProductCatLocationViewModelFactory(activity.getApplication(), args)).get(MasterProductCatLocationViewModel.class);
binding.setActivity(activity);
binding.setFormData(viewModel.getFormData());
binding.setViewModel(viewModel);
binding.setFragment(this);
binding.setLifecycleOwner(getViewLifecycleOwner());
viewModel.getEventHandler().observeEvent(getViewLifecycleOwner(), event -> {
if (event.getType() == Event.SNACKBAR_MESSAGE) {
SnackbarMessage message = (SnackbarMessage) event;
Snackbar snack = message.getSnackbar(activity, activity.binding.frameMainContainer);
activity.showSnackbar(snack);
} else if (event.getType() == Event.NAVIGATE_UP) {
activity.navigateUp();
} else if (event.getType() == Event.SET_SHOPPING_LIST_ID) {
int id = event.getBundle().getInt(Constants.ARGUMENT.SELECTED_ID);
setForDestination(R.id.shoppingListFragment, Constants.ARGUMENT.SELECTED_ID, id);
} else if (event.getType() == Event.BOTTOM_SHEET) {
BottomSheetEvent bottomSheetEvent = (BottomSheetEvent) event;
activity.showBottomSheet(bottomSheetEvent.getBottomSheet(), event.getBundle());
}
});
infoFullscreenHelper = new InfoFullscreenHelper(binding.container);
viewModel.getInfoFullscreenLive().observe(getViewLifecycleOwner(), infoFullscreen -> infoFullscreenHelper.setInfo(infoFullscreen));
viewModel.getIsLoadingLive().observe(getViewLifecycleOwner(), isLoading -> {
if (!isLoading) {
viewModel.setCurrentQueueLoading(null);
}
});
if (savedInstanceState == null) {
viewModel.loadFromDatabase(true);
}
updateUI(savedInstanceState == null);
}
use of xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper in project grocy-android by patzly.
the class MasterProductCatQuantityUnitFragment method onViewCreated.
@Override
public void onViewCreated(@Nullable View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
MasterProductFragmentArgs args = MasterProductFragmentArgs.fromBundle(requireArguments());
viewModel = new ViewModelProvider(this, new MasterProductCatQuantityUnitViewModel.MasterProductCatQuantityUnitViewModelFactory(activity.getApplication(), args)).get(MasterProductCatQuantityUnitViewModel.class);
binding.setActivity(activity);
binding.setFormData(viewModel.getFormData());
binding.setViewModel(viewModel);
binding.setFragment(this);
binding.setLifecycleOwner(getViewLifecycleOwner());
viewModel.getEventHandler().observeEvent(getViewLifecycleOwner(), event -> {
if (event.getType() == Event.SNACKBAR_MESSAGE) {
SnackbarMessage message = (SnackbarMessage) event;
Snackbar snack = message.getSnackbar(activity, activity.binding.frameMainContainer);
activity.showSnackbar(snack);
} else if (event.getType() == Event.NAVIGATE_UP) {
activity.navigateUp();
} else if (event.getType() == Event.SET_SHOPPING_LIST_ID) {
int id = event.getBundle().getInt(Constants.ARGUMENT.SELECTED_ID);
setForDestination(R.id.shoppingListFragment, Constants.ARGUMENT.SELECTED_ID, id);
} else if (event.getType() == Event.BOTTOM_SHEET) {
BottomSheetEvent bottomSheetEvent = (BottomSheetEvent) event;
activity.showBottomSheet(bottomSheetEvent.getBottomSheet(), event.getBundle());
}
});
infoFullscreenHelper = new InfoFullscreenHelper(binding.container);
viewModel.getInfoFullscreenLive().observe(getViewLifecycleOwner(), infoFullscreen -> infoFullscreenHelper.setInfo(infoFullscreen));
viewModel.getIsLoadingLive().observe(getViewLifecycleOwner(), isLoading -> {
if (!isLoading) {
viewModel.setCurrentQueueLoading(null);
}
});
if (savedInstanceState == null) {
viewModel.loadFromDatabase(true);
}
updateUI(savedInstanceState == null);
}
Aggregations