Search in sources :

Example 1 with ProductDetails

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);
        }
    }
}
Also used : ProductDetails(xyz.zedler.patrick.grocy.model.ProductDetails)

Example 2 with ProductDetails

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);
        }
    }
}
Also used : ProductDetails(xyz.zedler.patrick.grocy.model.ProductDetails)

Example 3 with ProductDetails

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();
}
Also used : BottomSheetDialog(com.google.android.material.bottomsheet.BottomSheetDialog) Chip(com.google.android.material.chip.Chip) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) Spanned(android.text.Spanned) TypeToken(com.google.gson.reflect.TypeToken) FragmentBottomsheetProductOverviewBinding(xyz.zedler.patrick.grocy.databinding.FragmentBottomsheetProductOverviewBinding) NonNull(androidx.annotation.NonNull) PriceHistoryEntry(xyz.zedler.patrick.grocy.model.PriceHistoryEntry) NumUtil(xyz.zedler.patrick.grocy.util.NumUtil) MainActivity(xyz.zedler.patrick.grocy.activity.MainActivity) Dialog(android.app.Dialog) HashMap(java.util.HashMap) TextUtil(xyz.zedler.patrick.grocy.util.TextUtil) MasterProductFragmentArgs(xyz.zedler.patrick.grocy.fragment.MasterProductFragmentArgs) ProductDetails(xyz.zedler.patrick.grocy.model.ProductDetails) DownloadHelper(xyz.zedler.patrick.grocy.helper.DownloadHelper) ArrayList(java.util.ArrayList) AmountUtil(xyz.zedler.patrick.grocy.util.AmountUtil) QuantityUnit(xyz.zedler.patrick.grocy.model.QuantityUnit) R(xyz.zedler.patrick.grocy.R) Gson(com.google.gson.Gson) View(android.view.View) Build(android.os.Build) StockItem(xyz.zedler.patrick.grocy.model.StockItem) MenuCompat(androidx.core.view.MenuCompat) NavHostFragment(androidx.navigation.fragment.NavHostFragment) PREF(xyz.zedler.patrick.grocy.util.Constants.PREF) PluralUtil(xyz.zedler.patrick.grocy.util.PluralUtil) BezierCurveChart(xyz.zedler.patrick.grocy.view.BezierCurveChart) LayoutInflater(android.view.LayoutInflater) Constants(xyz.zedler.patrick.grocy.util.Constants) Location(xyz.zedler.patrick.grocy.model.Location) ViewGroup(android.view.ViewGroup) Nullable(androidx.annotation.Nullable) SharedPreferences(android.content.SharedPreferences) Product(xyz.zedler.patrick.grocy.model.Product) Type(java.lang.reflect.Type) DateUtil(xyz.zedler.patrick.grocy.util.DateUtil) Html(android.text.Html) ViewTreeObserver(android.view.ViewTreeObserver) PreferenceManager(androidx.preference.PreferenceManager) ShoppingListItemEditFragmentArgs(xyz.zedler.patrick.grocy.fragment.ShoppingListItemEditFragmentArgs) Store(xyz.zedler.patrick.grocy.model.Store) Collections(java.util.Collections) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ValueAnimator(android.animation.ValueAnimator) PluralUtil(xyz.zedler.patrick.grocy.util.PluralUtil) MasterProductFragmentArgs(xyz.zedler.patrick.grocy.fragment.MasterProductFragmentArgs) StockItem(xyz.zedler.patrick.grocy.model.StockItem) DownloadHelper(xyz.zedler.patrick.grocy.helper.DownloadHelper) Chip(com.google.android.material.chip.Chip) Spanned(android.text.Spanned) LinearLayout(android.widget.LinearLayout)

Example 4 with ProductDetails

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);
    }
}
Also used : ProductDetails(xyz.zedler.patrick.grocy.model.ProductDetails) Product(xyz.zedler.patrick.grocy.model.Product) Grocycode(xyz.zedler.patrick.grocy.util.GrocycodeUtil.Grocycode) ProductBarcode(xyz.zedler.patrick.grocy.model.ProductBarcode)

Example 5 with ProductDetails

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);
}
Also used : StockLocation(xyz.zedler.patrick.grocy.model.StockLocation) ProductDetails(xyz.zedler.patrick.grocy.model.ProductDetails) Bundle(android.os.Bundle) QuantityUnit(xyz.zedler.patrick.grocy.model.QuantityUnit) StockLocationsBottomSheet(xyz.zedler.patrick.grocy.fragment.bottomSheetDialog.StockLocationsBottomSheet)

Aggregations

ProductDetails (xyz.zedler.patrick.grocy.model.ProductDetails)14 Bundle (android.os.Bundle)5 Product (xyz.zedler.patrick.grocy.model.Product)5 ProductBarcode (xyz.zedler.patrick.grocy.model.ProductBarcode)4 QuantityUnit (xyz.zedler.patrick.grocy.model.QuantityUnit)4 Grocycode (xyz.zedler.patrick.grocy.util.GrocycodeUtil.Grocycode)4 View (android.view.View)2 Nullable (androidx.annotation.Nullable)2 Gson (com.google.gson.Gson)2 Type (java.lang.reflect.Type)2 StockLocationsBottomSheet (xyz.zedler.patrick.grocy.fragment.bottomSheetDialog.StockLocationsBottomSheet)2 StockLocation (xyz.zedler.patrick.grocy.model.StockLocation)2 ValueAnimator (android.animation.ValueAnimator)1 Dialog (android.app.Dialog)1 SharedPreferences (android.content.SharedPreferences)1 Build (android.os.Build)1 Html (android.text.Html)1 Spanned (android.text.Spanned)1 LayoutInflater (android.view.LayoutInflater)1 ViewGroup (android.view.ViewGroup)1