use of xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper in project grocy-android by patzly.
the class MasterProductCatConversionsEditFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
MasterProductCatConversionsEditFragmentArgs args = MasterProductCatConversionsEditFragmentArgs.fromBundle(requireArguments());
viewModel = new ViewModelProvider(this, new MasterProductCatConversionsEditViewModelFactory(activity.getApplication(), args)).get(MasterProductCatConversionsEditViewModel.class);
binding.setActivity(activity);
binding.setViewModel(viewModel);
binding.setFormData(viewModel.getFormData());
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);
}
});
viewModel.getOfflineLive().observe(getViewLifecycleOwner(), offline -> {
InfoFullscreen infoFullscreen = offline ? new InfoFullscreen(InfoFullscreen.ERROR_OFFLINE, () -> updateConnectivity(true)) : null;
viewModel.getInfoFullscreenLive().setValue(infoFullscreen);
});
// necessary because else getValue() doesn't give current value (?)
viewModel.getFormData().getQuantityUnitsLive().observe(getViewLifecycleOwner(), qUs -> {
});
if (savedInstanceState == null) {
viewModel.loadFromDatabase(true);
}
updateUI();
}
use of xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper in project grocy-android by patzly.
the class MasterProductCatDueDateFragment 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 MasterProductCatDueDateViewModel.MasterProductCatDueDateViewModelFactory(activity.getApplication(), args)).get(MasterProductCatDueDateViewModel.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.fillData();
}
updateUI(savedInstanceState == null);
}
use of xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper in project grocy-android by patzly.
the class MasterProductCatOptionalFragment 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 MasterProductCatOptionalViewModel.MasterProductCatOptionalViewModelFactory(activity.getApplication(), args)).get(MasterProductCatOptionalViewModel.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));
embeddedFragmentScanner.setScannerVisibilityLive(viewModel.getFormData().getScannerVisibilityLive());
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 PurchaseFragment method onViewCreated.
@Override
public void onViewCreated(@Nullable View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
args = PurchaseFragmentArgs.fromBundle(requireArguments());
viewModel = new ViewModelProvider(this, new PurchaseViewModel.PurchaseViewModelFactory(activity.getApplication(), args)).get(PurchaseViewModel.class);
binding.setActivity(activity);
binding.setViewModel(viewModel);
binding.setFragment(this);
binding.setFormData(viewModel.getFormData());
binding.setLifecycleOwner(getViewLifecycleOwner());
infoFullscreenHelper = new InfoFullscreenHelper(binding.container);
if (args.getShoppingListItems() != null) {
binding.containerBatchMode.setVisibility(View.VISIBLE);
binding.linearPurchaseShoppingListItem.containerRow.setBackground(ContextCompat.getDrawable(activity, R.drawable.bg_list_item_visible_ripple));
}
viewModel.getInfoFullscreenLive().observe(getViewLifecycleOwner(), infoFullscreen -> infoFullscreenHelper.setInfo(infoFullscreen));
viewModel.getIsLoadingLive().observe(getViewLifecycleOwner(), isDownloading -> binding.swipePurchase.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.TRANSACTION_SUCCESS) {
assert getArguments() != null;
if (args.getShoppingListItems() != null) {
clearInputFocus();
viewModel.getFormData().clearForm();
boolean nextItemValid = viewModel.batchModeNextItem();
if (!nextItemValid)
activity.navigateUp();
} else 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(PurchaseFragmentDirections.actionPurchaseFragmentToChooseProductFragment(barcode));
}
});
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 PurchaseFragmentArgs.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);
}
pluralUtil = new PluralUtil(activity);
viewModel.getFormData().getShoppingListItemLive().observe(getViewLifecycleOwner(), item -> {
if (args.getShoppingListItems() == null || item == null)
return;
ShoppingListItemAdapter.fillShoppingListItem(requireContext(), item, binding.linearPurchaseShoppingListItem, viewModel.getProductHashMap(), viewModel.getQuantityUnitHashMap(), viewModel.getShoppingListItemAmountsHashMap(), pluralUtil);
});
embeddedFragmentScanner.setScannerVisibilityLive(viewModel.getFormData().getScannerVisibilityLive());
// following lines are necessary because no observers are set in Views
viewModel.getFormData().getPriceStockLive().observe(getViewLifecycleOwner(), i -> {
});
viewModel.getFormData().getQuantityUnitStockLive().observe(getViewLifecycleOwner(), i -> {
});
if (savedInstanceState == null) {
viewModel.loadFromDatabase(true);
}
focusProductInputIfNecessary();
setHasOptionsMenu(true);
updateUI(args.getAnimateStart() && savedInstanceState == null);
}
use of xyz.zedler.patrick.grocy.helper.InfoFullscreenHelper in project grocy-android by patzly.
the class ShoppingListEditFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
activity = (MainActivity) requireActivity();
viewModel = new ViewModelProvider(this, new ShoppingListEditViewModel.ShoppingListEditViewModelFactory(activity.getApplication(), getStartupShoppingList())).get(ShoppingListEditViewModel.class);
binding.setFormData(viewModel.getFormData());
binding.setViewModel(viewModel);
binding.setActivity(activity);
binding.setLifecycleOwner(getViewLifecycleOwner());
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.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);
}
});
infoFullscreenHelper = new InfoFullscreenHelper(binding.container);
viewModel.getInfoFullscreenLive().observe(getViewLifecycleOwner(), infoFullscreen -> infoFullscreenHelper.setInfo(infoFullscreen));
viewModel.getIsLoadingLive().observe(getViewLifecycleOwner(), isLoading -> {
if (!isLoading) {
viewModel.setCurrentQueueLoading(null);
}
});
viewModel.getOfflineLive().observe(getViewLifecycleOwner(), offline -> {
InfoFullscreen infoFullscreen = offline ? new InfoFullscreen(InfoFullscreen.ERROR_OFFLINE, () -> updateConnectivity(true)) : null;
viewModel.getInfoFullscreenLive().setValue(infoFullscreen);
});
if (savedInstanceState == null) {
viewModel.loadFromDatabase(true);
}
updateUI(ShoppingListEditFragmentArgs.fromBundle(requireArguments()).getAnimateStart() && savedInstanceState == null);
}
Aggregations