public String getCartPrice(Context context) { float price = 0; for (Map.Entry<String, JsonElement> item : cartJson.entrySet()) { try { ProductCart product = getProductCart(dataWorker.getProduct(Integer.valueOf(item.getKey()))); price += product.getPrice() * product.getCount(); } catch (Exception e) { Log.e(TAG, e.toString()); cartJson.remove(item.getKey()); setCartJson(); } } price = price / 100 * (100 - SharedPreferencesHelper.getDiscount(context)); int mod = Math.round(price * 100) % 100; return (int) price + "." + (mod > 9 ? mod : "0" + mod); }
public ArrayList<Product> getCartList() { ArrayList<Product> products = new ArrayList<>(); for (Map.Entry<String, JsonElement> item : cartJson.entrySet()) { try { products.add(dataWorker.getProduct(Integer.valueOf(item.getKey()))); } catch (Exception e) { Log.e(TAG, e.toString()); cartJson.remove(item.getKey()); setCartJson(); } } Collections.sort( products, new Comparator<Product>() { @Override public int compare(Product product1, Product product2) { return product1.getTitle().compareTo(product2.getTitle()); } }); return products; }