Esempio n. 1
0
  private double findTotalPrice(ArrayList<OrderItemDetail> orderItemDetails) {
    double totalPrice = 0;
    for (OrderItemDetail orderItemDetail : orderItemDetails) {
      totalPrice += (orderItemDetail.getPrice() * orderItemDetail.getQuantity());
    }

    return totalPrice;
  }
Esempio n. 2
0
  private void showDialogEditSummary(final int itemPosition) {
    final OrderItemDetail orderItemDetail = preOrderItemDetails.get(itemPosition);

    final Dialog dialogEditSummary = new Dialog(SummaryActivity.this);
    dialogEditSummary.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialogEditSummary.setCancelable(true);
    dialogEditSummary.setContentView(R.layout.dialog_edit_summary);
    // show detail of food by menu code
    MenuItem menuItem = databaseDao.getMenuByCode(orderItemDetail.getMenuCode());

    TextView tvName = (TextView) dialogEditSummary.findViewById(R.id.tvName);
    AppPreference appPreference = new AppPreference(SummaryActivity.this);
    if (appPreference.getAppLanguage().equals("th")) {
      tvName.setText(menuItem.getNameThai());
    } else {
      tvName.setText(menuItem.getNameEng());
    }

    TextView tvPrice = (TextView) dialogEditSummary.findViewById(R.id.tvPrice);
    tvPrice.setText(Double.toString(menuItem.getPrice()));

    final EditText etOption = (EditText) dialogEditSummary.findViewById(R.id.editTextOption);
    etOption.setText(orderItemDetail.getOption());

    ImageView ivImgFood = (ImageView) dialogEditSummary.findViewById(R.id.ivImgFood);
    Picture picture = databaseDao.getMenuPicture(menuItem.getPictureId());
    ivImgFood.setImageBitmap(picture.getBitmapPicture());

    dialogEditSummary.show();

    final EditText etAmount = (EditText) dialogEditSummary.findViewById(R.id.etAmount);
    etAmount.setText(String.valueOf(orderItemDetail.getQuantity()));
    Button btnOK = (Button) dialogEditSummary.findViewById(R.id.btnOK);
    btnOK.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            int amount = Integer.parseInt(etAmount.getText().toString());
            String option = etOption.getText().toString();
            // In case the user entering zero or negative, skip updating.
            if (amount > 0) {
              orderItemDetail.setQuantity(amount);
              orderItemDetail.setOption(option);
              // update data in database
              ContentValues values = new ContentValues();
              values.put(PreOrderTable.Columns._QUANTITY, amount);
              values.put(PreOrderTable.Columns._OPTION, option);
              databaseDao.updatePreOrderByValues(orderItemDetail.getPreOderId(), values);
            }
            // Remove from item list. However, it will add back later.
            preOrderItemDetails.remove(itemPosition);
            // Re-add to item list.
            preOrderItemDetails.add(itemPosition, orderItemDetail);
            dialogEditSummary.dismiss();
            orderItemListAdapter.notifyDataSetChanged();
            // calculate new total price.
            tvTotalPrice.setText(String.valueOf(findTotalPrice(preOrderItemDetails)));
          }
        });

    dialogEditSummary.setOnCancelListener(
        new DialogInterface.OnCancelListener() {
          @Override
          public void onCancel(DialogInterface dialog) {
            // do not anything.
          }
        });
  }