Search in sources :

Example 1 with ShoppingListItemBottomSheet

use of xyz.zedler.patrick.grocy.fragment.bottomSheetDialog.ShoppingListItemBottomSheet in project grocy-android by patzly.

the class ShoppingListFragment method showItemBottomSheet.

private void showItemBottomSheet(ShoppingListItem item) {
    if (item == null) {
        return;
    }
    Bundle bundle = new Bundle();
    Double amountInQuUnit = viewModel.getShoppingListItemAmountsHashMap().get(item.getId());
    Product product = viewModel.getProductHashMap().get(item.getProductIdInt());
    String amountStr;
    if (product != null && amountInQuUnit != null) {
        bundle.putString(Constants.ARGUMENT.PRODUCT_NAME, product.getName());
        QuantityUnit quantityUnit = viewModel.getQuantityUnitHashMap().get(item.getQuIdInt());
        String quStr = pluralUtil.getQuantityUnitPlural(quantityUnit, amountInQuUnit);
        if (quStr != null) {
            amountStr = getString(R.string.subtitle_amount, NumUtil.trim(amountInQuUnit), quStr);
        } else {
            amountStr = NumUtil.trim(amountInQuUnit);
        }
    } else if (product != null) {
        bundle.putString(Constants.ARGUMENT.PRODUCT_NAME, product.getName());
        QuantityUnit quantityUnit = viewModel.getQuantityUnitHashMap().get(product.getQuIdStockInt());
        String quStr = pluralUtil.getQuantityUnitPlural(quantityUnit, item.getAmountDouble());
        if (quStr != null) {
            amountStr = getString(R.string.subtitle_amount, NumUtil.trim(item.getAmountDouble()), quStr);
        } else {
            amountStr = NumUtil.trim(item.getAmountDouble());
        }
    } else {
        amountStr = NumUtil.trim(item.getAmountDouble());
    }
    bundle.putString(ARGUMENT.AMOUNT, amountStr);
    bundle.putParcelable(Constants.ARGUMENT.SHOPPING_LIST_ITEM, item);
    bundle.putBoolean(Constants.ARGUMENT.SHOW_OFFLINE, viewModel.isOffline());
    activity.showBottomSheet(new ShoppingListItemBottomSheet(), bundle);
}
Also used : Bundle(android.os.Bundle) ShoppingListItemBottomSheet(xyz.zedler.patrick.grocy.fragment.bottomSheetDialog.ShoppingListItemBottomSheet) Product(xyz.zedler.patrick.grocy.model.Product) QuantityUnit(xyz.zedler.patrick.grocy.model.QuantityUnit)

Aggregations

Bundle (android.os.Bundle)1 ShoppingListItemBottomSheet (xyz.zedler.patrick.grocy.fragment.bottomSheetDialog.ShoppingListItemBottomSheet)1 Product (xyz.zedler.patrick.grocy.model.Product)1 QuantityUnit (xyz.zedler.patrick.grocy.model.QuantityUnit)1