Beispiel #1
0
  /** UPDATE GRAPH WITH SELECTED when results are returned */
  private void updateGraphWithSelected(String results) {

    ndb = new NutritionDatabaseHelper(this);

    if (selectedItems != null || quantities != null) {
      selectedItems.clear();
      quantities.clear();
    } else {
      selectedItems = new ArrayList<Item>();
      quantities = new ArrayList<Integer>();
    }

    int position = -1;
    for (int i = 0; i < ccartList.getCount(); i++) {
      String tempItemName = ccartList.getItem(i);
      int pos = tempItemName.indexOf(" ");
      String compare = tempItemName.substring(pos + 1);

      if (compare.equals(results)) {
        position = i;
        break;
      } else {
        continue;
      }
    }

    Item selectedItem = ndb.getItem(results);
    ndb.close();

    selectedItems.add(selectedItem);
    String itemOne;

    if (selectedItems.get(0).getItemName().length() > 20) {
      itemOne = selectedItems.get(0).getItemName().substring(0, 20) + "...";
    } else {
      itemOne = selectedItems.get(0).getItemName();
    }

    String one = "<font color='#7EAD1A'>" + itemOne + "</font> SELECTED";
    added.setText(Html.fromHtml(one));

    for (GroceryItem gItem : ccart) {
      if (gItem.getItemName().equals(results)) {
        quantities.add(gItem.getQuantity());
        Log.d("CartActivity: ", "Name: " + gItem.getItemName() + quantities.get(0));
      }
    }

    Log.d("CartActivity", "Position: " + position);
    sd_list.setItemChecked(position, true);

    graph.passSelectedItems(selectedItems);
    graph.passSelectedQuantities(quantities);

    graph.postInvalidate();

    graphLabels.setDays(days);
    graphLabels.postInvalidate();
  }
Beispiel #2
0
  /** UPDATE BASE GRAPH with new Cart totals */
  private void updateBaseGraph() {
    // get an updated version of the adb on resume each time
    adb = new AccountDatabaseHelper(this);
    ccart = adb.getAllGroceryItemsOf(currentUsername);
    int groceryCount = adb.getGroceryCountFor(currentUsername);
    if (groceryCount == 1) {
      added.setText(groceryCount + " ITEM IN CART");
    } else if (groceryCount == 0 || groceryCount > 1) {
      added.setText(groceryCount + " ITEMS IN CART");
    }
    adb.close();

    if (ccart != null) {
      setupItemDrawer();
    }

    passedIntent = getIntent();

    results = passedIntent.getStringExtra("results");
    int check = passedIntent.getIntExtra("check", 0);
    if (check == 1) {
      Log.d("CartActivity", "This is results " + results);
      if (results != null && !results.equals("e")) {
        updateGraphWithSelected(results);
      } else {
        Toast noData =
            Toast.makeText(
                CartActivity.this,
                "Sorry, we couldn't find the nutrition data for this item",
                Toast.LENGTH_LONG);
        noData.show();
      }
    }

    ccartTotals = getCartTotalsFor(currentUsername);
    totalRDV = getRDVTotalsFor(currentUsername);

    if (pcart.getCalories() != 0.0f) {
      graph.getRatiosWithPCart(ccartTotals, totalRDV, pcart);
    } else {
      graph.getRatiosWithoutPCart(ccartTotals, totalRDV);
    }
    graph.postInvalidate();

    graphLabels.setDays(days);
    graphLabels.postInvalidate();
  }