use of xyz.zedler.patrick.grocy.model.ProductDetails in project grocy-android by patzly.
the class ConsumeFragment method focusProductInputIfNecessary.
public void focusProductInputIfNecessary() {
if (!viewModel.isQuickModeEnabled() || viewModel.getFormData().isScannerVisible()) {
return;
}
ProductDetails productDetails = viewModel.getFormData().getProductDetailsLive().getValue();
String productNameInput = viewModel.getFormData().getProductNameLive().getValue();
if (productDetails == null && (productNameInput == null || productNameInput.isEmpty())) {
binding.autoCompleteConsumeProduct.requestFocus();
if (viewModel.getFormData().getExternalScannerEnabled()) {
activity.hideKeyboard();
} else {
activity.showKeyboard(binding.autoCompleteConsumeProduct);
}
}
}
use of xyz.zedler.patrick.grocy.model.ProductDetails in project grocy-android by patzly.
the class TransferFragment method focusProductInputIfNecessary.
public void focusProductInputIfNecessary() {
if (!viewModel.isQuickModeEnabled() || viewModel.getFormData().isScannerVisible()) {
return;
}
ProductDetails productDetails = viewModel.getFormData().getProductDetailsLive().getValue();
String productNameInput = viewModel.getFormData().getProductNameLive().getValue();
if (productDetails == null && (productNameInput == null || productNameInput.isEmpty())) {
binding.autoCompleteConsumeProduct.requestFocus();
if (viewModel.getFormData().getExternalScannerEnabled()) {
activity.hideKeyboard();
} else {
activity.showKeyboard(binding.autoCompleteConsumeProduct);
}
}
}
use of xyz.zedler.patrick.grocy.model.ProductDetails in project grocy-android by patzly.
the class ProductOverviewBottomSheet method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
activity = (MainActivity) requireActivity();
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
pluralUtil = new PluralUtil(activity);
ProductOverviewBottomSheetArgs args = ProductOverviewBottomSheetArgs.fromBundle(requireArguments());
boolean showActions = args.getShowActions();
if (args.getProductDetails() != null) {
productDetails = args.getProductDetails();
product = productDetails.getProduct();
stockItem = new StockItem(productDetails);
} else if (args.getStockItem() != null) {
stockItem = args.getStockItem();
quantityUnit = args.getQuantityUnit();
location = args.getLocation();
product = stockItem.getProduct();
}
// WEB REQUESTS
dlHelper = new DownloadHelper(activity, TAG);
// VIEWS
refreshItems();
binding.textName.setText(product.getName());
// TOOLBAR
boolean isInStock = stockItem.getAmountDouble() > 0;
MenuCompat.setGroupDividerEnabled(binding.toolbar.getMenu(), true);
// disable actions if necessary
binding.toolbar.getMenu().findItem(R.id.action_consume_all).setEnabled(isInStock);
binding.toolbar.getMenu().findItem(R.id.action_consume_spoiled).setEnabled(isInStock && product.getEnableTareWeightHandlingInt() == 0);
binding.toolbar.setOnMenuItemClickListener(item -> {
if (item.getItemId() == R.id.action_add_to_shopping_list) {
navigateDeepLink(R.string.deep_link_shoppingListItemEditFragment, new ShoppingListItemEditFragmentArgs.Builder(Constants.ACTION.CREATE).setProductId(String.valueOf(product.getId())).build().toBundle());
dismiss();
return true;
} else if (item.getItemId() == R.id.action_consume_all) {
activity.getCurrentFragment().performAction(Constants.ACTION.CONSUME_ALL, stockItem);
dismiss();
return true;
} else if (item.getItemId() == R.id.action_consume_spoiled) {
activity.getCurrentFragment().performAction(Constants.ACTION.CONSUME_SPOILED, stockItem);
dismiss();
return true;
} else if (item.getItemId() == R.id.action_edit_product) {
String productId = String.valueOf(product.getId());
navigateDeepLink(R.string.deep_link_masterProductFragment, new MasterProductFragmentArgs.Builder(Constants.ACTION.EDIT).setProductId(productId).build().toBundle());
dismiss();
return true;
}
return false;
});
Chip chipConsume = view.findViewById(R.id.chip_consume);
chipConsume.setVisibility(isInStock ? View.VISIBLE : View.GONE);
chipConsume.setOnClickListener(v -> {
NavHostFragment.findNavController(this).navigate(ProductOverviewBottomSheetDirections.actionProductOverviewBottomSheetDialogFragmentToConsumeFragment().setCloseWhenFinished(true).setProductId(String.valueOf(product.getId())));
dismiss();
});
Chip chipPurchase = view.findViewById(R.id.chip_purchase);
chipPurchase.setOnClickListener(v -> {
NavHostFragment.findNavController(this).navigate(ProductOverviewBottomSheetDirections.actionProductOverviewBottomSheetDialogFragmentToPurchaseFragment().setCloseWhenFinished(true).setProductId(String.valueOf(product.getId())));
dismiss();
});
Chip chipTransfer = view.findViewById(R.id.chip_transfer);
chipTransfer.setVisibility(isInStock && product.getEnableTareWeightHandlingInt() == 0 ? View.VISIBLE : View.GONE);
chipTransfer.setOnClickListener(v -> {
NavHostFragment.findNavController(this).navigate(ProductOverviewBottomSheetDirections.actionProductOverviewBottomSheetDialogFragmentToTransferFragment().setCloseWhenFinished(true).setProductId(String.valueOf(product.getId())));
dismiss();
});
Chip chipInventory = view.findViewById(R.id.chip_inventory);
chipInventory.setOnClickListener(v -> {
NavHostFragment.findNavController(this).navigate(ProductOverviewBottomSheetDirections.actionProductOverviewBottomSheetDialogFragmentToInventoryFragment().setCloseWhenFinished(true).setProductId(String.valueOf(product.getId())));
dismiss();
});
if (!showActions) {
view.findViewById(R.id.container_chips).setVisibility(View.GONE);
}
// DESCRIPTION
Spanned description = product.getDescription() != null ? Html.fromHtml(product.getDescription()) : null;
description = (Spanned) TextUtil.trimCharSequence(description);
if (description != null && !description.toString().isEmpty()) {
binding.cardDescription.setText(description.toString());
} else {
binding.cardDescription.setVisibility(View.GONE);
}
if (!showActions) {
// hide actions when set up with productDetails
binding.linearActionContainer.setVisibility(View.GONE);
// set info menu
binding.toolbar.getMenu().clear();
binding.toolbar.inflateMenu(R.menu.menu_actions_product_overview_info);
}
refreshButtonStates(false);
binding.buttonConsume.setOnClickListener(v -> {
disableActions();
activity.getCurrentFragment().performAction(Constants.ACTION.CONSUME, stockItem);
dismiss();
});
binding.buttonOpen.setOnClickListener(v -> {
disableActions();
activity.getCurrentFragment().performAction(Constants.ACTION.OPEN, stockItem);
dismiss();
});
// tooltips
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
binding.buttonConsume.setTooltipText(activity.getString(R.string.action_consume_one, quantityUnit.getName(), product.getName()));
binding.buttonOpen.setTooltipText(activity.getString(R.string.action_open_one, quantityUnit.getName(), product.getName()));
// TODO: tooltip colors
}
// no margin if description is != null
if (description != null) {
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(0, 0, 0, 0);
binding.linearAmount.setLayoutParams(layoutParams);
}
if (activity.isOnline() && !hasDetails()) {
dlHelper.getProductDetails(product.getId(), details -> {
productDetails = details;
stockItem = new StockItem(productDetails);
refreshButtonStates(true);
refreshItems();
loadPriceHistory();
}).perform(dlHelper.getUuid());
} else if (activity.isOnline() && hasDetails()) {
loadPriceHistory();
}
hideDisabledFeatures();
}
use of xyz.zedler.patrick.grocy.model.ProductDetails in project grocy-android by patzly.
the class ConsumeViewModel method checkProductInput.
public void checkProductInput() {
formData.isProductNameValid();
String input = formData.getProductNameLive().getValue();
if (input == null || input.isEmpty()) {
return;
}
Product product = Product.getProductFromName(products, input);
Grocycode grocycode = GrocycodeUtil.getGrocycode(input.trim());
if (grocycode != null && grocycode.isProduct()) {
product = Product.getProductFromId(products, grocycode.getObjectId());
if (product == null) {
showMessageAndContinueScanning(R.string.msg_not_found);
return;
}
} else if (grocycode != null) {
showMessageAndContinueScanning(R.string.error_wrong_grocycode_type);
return;
}
if (product == null) {
ProductBarcode productBarcode = null;
for (ProductBarcode code : barcodes) {
if (code.getBarcode().equals(input.trim())) {
productBarcode = code;
product = Product.getProductFromId(products, code.getProductId());
}
}
if (product != null) {
setProduct(product.getId(), productBarcode, null);
return;
}
}
ProductDetails currentProductDetails = formData.getProductDetailsLive().getValue();
Product currentProduct = currentProductDetails != null ? currentProductDetails.getProduct() : null;
if (currentProduct != null && product != null && currentProduct.getId() == product.getId()) {
return;
}
if (product != null) {
setProduct(product.getId(), null, null);
} else {
showInputProductBottomSheet(input);
}
}
use of xyz.zedler.patrick.grocy.model.ProductDetails in project grocy-android by patzly.
the class ConsumeViewModel method showStockLocationsBottomSheet.
public void showStockLocationsBottomSheet() {
if (!formData.isProductNameValid()) {
return;
}
ArrayList<StockLocation> stockLocations = formData.getStockLocations();
StockLocation currentStockLocation = formData.getStockLocationLive().getValue();
int selectedId = currentStockLocation != null ? currentStockLocation.getLocationId() : -1;
ProductDetails productDetails = formData.getProductDetailsLive().getValue();
QuantityUnit quantityUnitStock = formData.getQuantityUnitStockLive().getValue();
Bundle bundle = new Bundle();
bundle.putParcelableArrayList(Constants.ARGUMENT.STOCK_LOCATIONS, stockLocations);
bundle.putInt(Constants.ARGUMENT.SELECTED_ID, selectedId);
bundle.putParcelable(Constants.ARGUMENT.PRODUCT_DETAILS, productDetails);
bundle.putParcelable(Constants.ARGUMENT.QUANTITY_UNIT, quantityUnitStock);
showBottomSheet(new StockLocationsBottomSheet(), bundle);
}
Aggregations