예제 #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_modify_item);
    Bundle extras = getIntent().getExtras();
    this.identifier = extras.getInt("foodItem");
    this.tableNum = extras.getInt("tableNumber");
    this.seatNum = extras.getInt("seatNumber");
    EzServe ezServe = (EzServe) getApplication();
    FoodItem realItem = ezServe.getItem(identifier);

    TextView textView = (TextView) findViewById(R.id.modmod);
    textView.setText("Table " + tableNum + " - " + "Seat " + seatNum + " - " + realItem.toString());
    if (((EzServe) getApplication()).getItem(identifier).getDescription().contains("/")) {
      setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, splitItems));
    } else setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, listItems));
  }
예제 #2
0
  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    EzServe ezServe = (EzServe) getApplication();
    FoodItem realItem = ezServe.getItem(identifier);

    if (!((EzServe) getApplication()).getItem(identifier).getDescription().contains("/")) {

      super.onListItemClick(l, v, position, id);
      String selectedOption = getListView().getItemAtPosition(position).toString();

      Table table = ezServe.getTable(this.tableNum);
      Seat seat = table.getSeats().get(this.seatNum);
      if (StringUtils.equals(selectedOption, listItems[0])) {
        FoodItem itemToDelete = null;
        for (FoodItem item : seat.getAllItems()) {
          if (identifier == item.identifier) {
            itemToDelete = item;
          }
        }
        if (itemToDelete != null) {
          if (itemToDelete.type == FOOD_ITEM_TYPE.BEVERAGE) {
            seat.getBeverages().remove(itemToDelete);
          }
          if (itemToDelete.type == FOOD_ITEM_TYPE.SALAD) {
            seat.getSalads().remove(itemToDelete);
          }
          if (itemToDelete.type == FOOD_ITEM_TYPE.ENTREE) {
            seat.getEntrees().remove(itemToDelete);
          }
          if (itemToDelete.type == FOOD_ITEM_TYPE.DESSERT) {
            seat.getDesserts().remove(itemToDelete);
          }
          if (itemToDelete.type == FOOD_ITEM_TYPE.KID) {
            seat.getKidsmeals().remove(itemToDelete);
          }
          if (itemToDelete.type == FOOD_ITEM_TYPE.APPETIZER) {
            seat.getAppetizers().remove(itemToDelete);
          }
        }

        Intent intent = new Intent(this, SeatListActivity.class);
        intent.putExtra("seatNumber", this.seatNum);
        intent.putExtra("tableNumber", this.tableNum);
        startActivity(intent);
      }
      if (StringUtils.equals(selectedOption, listItems[1])) {
        Intent intent = new Intent(this, SplitItemActivity.class);
        intent.putExtra("tableNumber", this.tableNum);
        intent.putExtra("seatNumber", this.seatNum);
        intent.putExtra("foodItem", this.identifier);
        startActivity(intent);
      }
      if (StringUtils.equals(selectedOption, listItems[3])) {
        Intent intent = new Intent(this, RemoveActivity.class);
        intent.putExtra("tableNumber", this.tableNum);
        intent.putExtra("seatNumber", this.seatNum);
        intent.putExtra("foodItem", this.identifier);
        startActivity(intent);
      }
      if (StringUtils.equals(selectedOption, listItems[2])) {
        Intent intent = new Intent(this, AddActivity.class);
        intent.putExtra("tableNumber", this.tableNum);
        intent.putExtra("seatNumber", this.seatNum);
        intent.putExtra("foodItem", this.identifier);
        startActivity(intent);
      }
      if (StringUtils.equals(selectedOption, listItems[4])) {
        /*
         * Intent intent = new Intent(this, MsgActivity.class);
         * intent.putExtra("tableNumber", this.tableNum);
         * intent.putExtra("seatNumber", this.seatNum);
         * intent.putExtra("foodItem", this.selectedItem);
         * startActivity(intent);
         */
        AlertDialog.Builder alert = new AlertDialog.Builder(this);

        alert.setTitle("Attach Message");

        // Set an EditText view to get user input
        final EditText input = new EditText(this);
        input.setText(ezServe.getItem(identifier).customMsg);
        InputFilter[] filters = new InputFilter[1];
        filters[0] = new InputFilter.LengthFilter(200);
        input.setFilters(filters);
        alert.setView(input);

        alert.setPositiveButton(
            "Ok",
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int whichButton) {
                Editable value = input.getText();
                EzServe ezServe = (EzServe) getApplication();
                ezServe.getItem(identifier).customMsg = value.toString();
              }
            });

        alert.setNegativeButton(
            "Cancel",
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int whichButton) {
                // Canceled.
              }
            });

        alert.show();
      }
    } else {

      super.onListItemClick(l, v, position, id);
      String selectedOption = getListView().getItemAtPosition(position).toString();
      Table table = ezServe.getTable(this.tableNum);
      Seat seat = table.getSeats().get(this.seatNum);
      if (StringUtils.equals(selectedOption, splitItems[0])) {
        for (Seat seatssas : ezServe.getTable(this.tableNum).getSeats()) {
          FoodItem itemToDelete = null;
          for (FoodItem item : seatssas.getAllItems()) {
            if (item.getDescription().equals(realItem.getDescription())) {
              itemToDelete = item;
            }
            if (itemToDelete != null) {
              if (itemToDelete.type == FOOD_ITEM_TYPE.BEVERAGE) {
                seatssas.getBeverages().remove(itemToDelete);
              }
              if (itemToDelete.type == FOOD_ITEM_TYPE.SALAD) {
                seatssas.getSalads().remove(itemToDelete);
              }
              if (itemToDelete.type == FOOD_ITEM_TYPE.ENTREE) {
                seatssas.getEntrees().remove(itemToDelete);
              }
              if (itemToDelete.type == FOOD_ITEM_TYPE.DESSERT) {
                seatssas.getDesserts().remove(itemToDelete);
              }
              if (itemToDelete.type == FOOD_ITEM_TYPE.KID) {
                seatssas.getKidsmeals().remove(itemToDelete);
              }
              if (itemToDelete.type == FOOD_ITEM_TYPE.APPETIZER) {
                seatssas.getAppetizers().remove(itemToDelete);
              }
              itemToDelete = null;
            }
          }
        }

        Intent intent = new Intent(this, SeatListActivity.class);
        intent.putExtra("seatNumber", this.seatNum);
        intent.putExtra("tableNumber", this.tableNum);
        startActivity(intent);
      }
      if (StringUtils.equals(selectedOption, splitItems[2])) {
        Intent intent = new Intent(this, RemoveActivity.class);
        intent.putExtra("tableNumber", this.tableNum);
        intent.putExtra("seatNumber", this.seatNum);
        intent.putExtra("foodItem", this.identifier);
        startActivity(intent);
      }
      if (StringUtils.equals(selectedOption, splitItems[1])) {
        Intent intent = new Intent(this, AddActivity.class);
        intent.putExtra("tableNumber", this.tableNum);
        intent.putExtra("seatNumber", this.seatNum);
        intent.putExtra("foodItem", this.identifier);
        startActivity(intent);
      }
      if (StringUtils.equals(selectedOption, splitItems[3])) {
        /*
         * Intent intent = new Intent(this, MsgActivity.class);
         * intent.putExtra("tableNumber", this.tableNum);
         * intent.putExtra("seatNumber", this.seatNum);
         * intent.putExtra("foodItem", this.selectedItem);
         * startActivity(intent);
         */
        AlertDialog.Builder alert = new AlertDialog.Builder(this);

        alert.setTitle("Attach Message");

        // Set an EditText view to get user input
        final EditText input = new EditText(this);
        input.setText(ezServe.getItem(identifier).customMsg);
        InputFilter[] filters = new InputFilter[1];
        filters[0] = new InputFilter.LengthFilter(200);
        input.setFilters(filters);
        alert.setView(input);

        alert.setPositiveButton(
            "Ok",
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int whichButton) {
                Editable value = input.getText();
                EzServe ezServe = (EzServe) getApplication();
                ezServe.getItem(identifier).customMsg = value.toString();
              }
            });

        alert.setNegativeButton(
            "Cancel",
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int whichButton) {
                // Canceled.
              }
            });

        alert.show();
      }
    }
  }