add to cart
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
package ch.pizzalink.android.helper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import ch.pizzalink.android.R;
|
||||
import ch.pizzalink.android.activity.BaseActivity;
|
||||
import ch.pizzalink.android.model.menu.MenuProductModel;
|
||||
import ch.pizzalink.android.model.menu.MenuProductOptionValueModel;
|
||||
|
||||
/**
|
||||
* Created by cimenmus on 12/10/2017.
|
||||
*/
|
||||
|
||||
public class PriceHelper {
|
||||
|
||||
public static String getPriceWithCurreny(String price){
|
||||
return BaseActivity.currentActivity.getString(R.string.chf) + " " + price;
|
||||
}
|
||||
|
||||
public static String getPriceWithCurreny(Double price){
|
||||
return BaseActivity.currentActivity.getString(R.string.chf) + " " + price;
|
||||
}
|
||||
|
||||
public static String removeCurrencyFromPrice(String priceWithCurreny){
|
||||
try {
|
||||
String currencyText = BaseActivity.currentActivity.getString(R.string.chf);
|
||||
return priceWithCurreny.replace(currencyText, "").trim();
|
||||
}catch (Exception e){
|
||||
return priceWithCurreny.trim();
|
||||
}
|
||||
}
|
||||
|
||||
public static String calculatePriceAfterCountChanged(String oldPriceString, int oldCount, int newCount){
|
||||
Double oldPrice = Double.valueOf(removeCurrencyFromPrice(oldPriceString));
|
||||
Double productOldPrice = oldPrice / oldCount;
|
||||
Double productNewPrice = productOldPrice * newCount;
|
||||
return getPriceWithCurreny(productNewPrice);
|
||||
}
|
||||
|
||||
public static String calculatePriceAfterRadioOptionValueChanged(int count,
|
||||
MenuProductModel menuProductModel,
|
||||
MenuProductOptionValueModel menuProductOptionValueModel){
|
||||
|
||||
Double productPrice = Double.valueOf(menuProductModel.getPrice());
|
||||
|
||||
switch (menuProductOptionValueModel.getPrice_prefix()){
|
||||
case "+":
|
||||
productPrice += Double.valueOf(menuProductOptionValueModel.getPrice());
|
||||
break;
|
||||
case "-":
|
||||
productPrice -= Double.valueOf(menuProductOptionValueModel.getPrice());
|
||||
break;
|
||||
}
|
||||
|
||||
return getPriceWithCurreny(productPrice * count);
|
||||
|
||||
}
|
||||
|
||||
public static String calculatePriceAfterCheckboxOptionValueChanged(int count,
|
||||
MenuProductModel menuProductModel,
|
||||
ArrayList<MenuProductOptionValueModel> menuProductOptionValueModelList){
|
||||
|
||||
Double productPrice = Double.valueOf(menuProductModel.getPrice());
|
||||
|
||||
for(MenuProductOptionValueModel menuProductOptionValueModel : menuProductOptionValueModelList){
|
||||
if(menuProductOptionValueModel.isSelected()){
|
||||
switch (menuProductOptionValueModel.getPrice_prefix()){
|
||||
case "+":
|
||||
productPrice += Double.valueOf(menuProductOptionValueModel.getPrice());
|
||||
break;
|
||||
case "-":
|
||||
productPrice -= Double.valueOf(menuProductOptionValueModel.getPrice());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return getPriceWithCurreny(productPrice * count);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user