Ejemplo n.º 1
0
  /**
   * @param username
   * @return Fetch all of the people for one user If null, then request that user check preferences
   */
  public static String getAllPeopleDescFor(String username) {
    List<Person> p = adb.getAllPeopleFor(username);
    String allPeopleDesc = new String();
    if (p != null) {
      for (int i = 0; i < p.size(); i++) {
        Person temp = p.get(i);
        allPeopleDesc = allPeopleDesc + "\n" + temp.returnString();
      }
    } else {
      adb.close();
      return "No one has been added to Cart yet. Please check preferences.";
    }

    adb.close();
    return allPeopleDesc;
  }
Ejemplo n.º 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();
  }
Ejemplo n.º 3
0
  /**
   * @param username
   * @return A string of all of the required values of one entity the user has specified
   */
  public static String getStringRDVTotalsFor(String username) {
    List<Person> p = adb.getAllPeopleFor(username);
    List<RecDailyValues> rdvList = new ArrayList<RecDailyValues>();
    if (p != null) {
      for (int i = 0; i < p.size(); i++) {
        RecDailyValues tempRDV = new RecDailyValues(p.get(i));
        rdvList.add(tempRDV);
      }
    } else {
      adb.close();
      return "No one has been added to Cart yet. Please check preferences.";
    }

    adb.close();
    RecDailyValues total = getTotalRDVOf(rdvList);
    return total.returnString();
  }
Ejemplo n.º 4
0
  /** TOTAL RDR Get the total values of all of the RecDailyValues */
  public static RecDailyValues getRDVTotalsFor(String username) {
    List<Person> p = adb.getAllPeopleFor(username);
    List<RecDailyValues> rdvList = new ArrayList<RecDailyValues>();
    if (p != null) {
      for (int i = 0; i < p.size(); i++) {
        RecDailyValues tempRDV = new RecDailyValues(p.get(i));
        rdvList.add(tempRDV);
      }
    } else {
      adb.close();
      return null;
    }

    adb.close();
    RecDailyValues total = getTotalRDVOf(rdvList);
    return total;
  }
Ejemplo n.º 5
0
  /** TOTAL VALUES Add up all of the values of the current_cart items */
  public PreviousHistory getCartTotalsFor(String username) {
    NutritionDatabaseHelper ndb = new NutritionDatabaseHelper(this);
    AccountDatabaseHelper adb = new AccountDatabaseHelper(this);

    List<GroceryItem> allGItems = adb.getAllGroceryItemsOf(username);
    PreviousHistory cartTotals = new PreviousHistory();
    if (allGItems != null) {
      cartTotals.setId(-1);
      cartTotals.setUsername(username);

      for (int i = 0; i < allGItems.size(); i++) {
        // retrieve the grocery item from the array
        GroceryItem tempGrocery = allGItems.get(i);

        // get the Quantity of the item
        int quantity = tempGrocery.getQuantity();

        // locate the item in the nutrition database
        Item tempItem = ndb.getItem(tempGrocery.getItemName());

        // add the totals to the current cartTotal, remembering
        // to multiply by the quantity!
        cartTotals.setCalories(cartTotals.getCalories() + (tempItem.getCalories() * quantity));
        cartTotals.setProtein(cartTotals.getProtein() + (tempItem.getProtein() * quantity));
        cartTotals.setFat(cartTotals.getFat() + (tempItem.getFat() * quantity));
        cartTotals.setCarbohydrate(
            cartTotals.getCarbohydrate() + (tempItem.getCarbohydrate() * quantity));
        cartTotals.setFiber(cartTotals.getFiber() + (tempItem.getFiber() * quantity));
        cartTotals.setSugar(cartTotals.getSugar() + (tempItem.getSugar() * quantity));
        cartTotals.setCalcium(cartTotals.getCalcium() + (tempItem.getCalcium() * quantity));
        cartTotals.setIron(cartTotals.getIron() + (tempItem.getIron() * quantity));
        cartTotals.setMagnesium(cartTotals.getMagnesium() + (tempItem.getMagnesium() * quantity));
        cartTotals.setPotassium(cartTotals.getPotassium() + (tempItem.getPotassium() * quantity));
        cartTotals.setSodium(cartTotals.getSodium() + (tempItem.getSodium() * quantity));
        cartTotals.setZinc(cartTotals.getZinc() + (tempItem.getZinc() * quantity));
        cartTotals.setVitC(cartTotals.getVitC() + (tempItem.getVitC() * quantity));
        cartTotals.setVitB6(cartTotals.getVitB6() + (tempItem.getVitB6() * quantity));
        cartTotals.setVitB12(cartTotals.getVitB12() + (tempItem.getVitB12() * quantity));
        cartTotals.setVitA(cartTotals.getVitA() + (tempItem.getVitA() * quantity));
        cartTotals.setVitE(cartTotals.getVitE() + (tempItem.getVitE() * quantity));
        cartTotals.setVitD(cartTotals.getVitD() + (tempItem.getVitD() * quantity));
        cartTotals.setVitK(cartTotals.getVitK() + (tempItem.getVitK() * quantity));
        cartTotals.setFatSat(cartTotals.getFatSat() + (tempItem.getFatSat() * quantity));
        cartTotals.setFatMono(cartTotals.getFatMono() + (tempItem.getFatMono() * quantity));
        cartTotals.setFatPoly(cartTotals.getFatPoly() + (tempItem.getFatPoly() * quantity));
        cartTotals.setCholesterol(
            cartTotals.getCholesterol() + (tempItem.getCholesterol() * quantity));
        cartTotals.setDays(days);
      }

      // Log.d("Created: ", "Cart Total for : " + cartTotals.getUsername()
      // + "Total Calories: " + cartTotals.getCalories());
      adb.close();
      ndb.close();
      return cartTotals;
    }
    ndb.close();
    adb.close();
    PreviousHistory emptyHistory = new PreviousHistory();
    emptyHistory.setUsername(currentUsername);
    return emptyHistory;
  }
Ejemplo n.º 6
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cart);

    // From the intent, read the number of days
    Intent passedIntent = getIntent();

    if (passedIntent != null) {
      // retrieve the account
      Account tempAccount = passedIntent.getParcelableExtra("account");

      if (tempAccount != null) {
        act = tempAccount;
        currentUsername = act.getName();
        int tdays = tempAccount.getDays();
        if (tdays != 0) {
          days = tdays;
        } else {
          // set days equal to 1 to prevent crashing
          days = 1;
        }
      } else {
        throw new RuntimeException("CartActivity: account passed was null");
      }
    }

    // ActionBar
    actionBar = (ActionBar) findViewById(R.id.actionbar);
    actionBar.setTitle("Your Grocery Cart");
    actionBar.setHomeAction(new backToDashboardAction());
    actionBar.addAction(new toDaysAction());
    actionBar.addAction(new toPeopleAction());
    actionBar.addAction(new toCheckoutAction());

    // start the db
    adb = new AccountDatabaseHelper(this);
    ndb = new NutritionDatabaseHelper(this);

    // Set the number of days and start the graph view!
    graph = (GraphView) this.findViewById(R.id.graphview);
    graph.setDays(days);

    // Start the graph label view
    graphLabels = (GraphLabelView) this.findViewById(R.id.graphlabelview);

    // Start the nutrition advisor
    advisor = new NutritionAdvisor();

    added = (TextView) findViewById(R.id.tv_added);
    peopleDays = (TextView) findViewById(R.id.tv_cart_peopledays);

    // start the peopledays goal reminder
    int peopleNumber = adb.getPersonCountFor(currentUsername);
    if (days == 1) {
      peopleDays.setText("You're shopping for " + days + " day ");
    } else if (days > 1) {
      peopleDays.setText("You're shopping for " + days + " days ");
    }
    if (peopleNumber == 1) {
      peopleDays.append("and " + peopleNumber + " person");
    } else if (peopleNumber > 1) {
      peopleDays.append("and " + peopleNumber + " people.");
    }

    // initiates the listview within the drawer
    sd_list = (ListView) findViewById(R.id.sd_list);
    sd_itemlist = (SlidingDrawer) findViewById(R.id.sd_itemlist);
    handle = (Button) findViewById(R.id.btn_handle);

    pcart = adb.getPreviousHistoryFor(currentUsername);
    adb.close();

    // Handles the PLU code
    searchItem = (Button) findViewById(R.id.btn_search);
    deleteItem = (Button) findViewById(R.id.btn_delete_item);
    quantityItem = (Button) findViewById(R.id.btn_quantity);

    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    inputsContext = getApplicationContext();

    searchItem.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            // opens up activity with a text entry and numpad
            Intent openSearchItemScreen = new Intent(CartActivity.this, InputSearchActivity.class);
            openSearchItemScreen.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            openSearchItemScreen.putExtra("account", act);
            startActivity(openSearchItemScreen);
          }
        }); // end searchItem

    // Handles the Barcode Scanning activity
    scanItem = (Button) findViewById(R.id.btn_scan);
    scanItem.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            // start a scanner intent, using zxing library
            // refer back to PACKAGE settings
            Intent scanIntent = new Intent(SCANNER);
            scanIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            scanIntent.setPackage(PACKAGE);
            scanIntent.addCategory(Intent.CATEGORY_DEFAULT);
            scanIntent.putExtra("SCAN_FORMATS", SCAN_FORMATS);
            scanIntent.putExtra("SCAN_MODE", SCAN_MODE);
            try {
              startActivityForResult(scanIntent, REQUEST_CODE);
            } catch (ActivityNotFoundException e) {
              Toast eToast =
                  Toast.makeText(CartActivity.this, "Activity Not Found!", Toast.LENGTH_LONG);
              eToast.setGravity(Gravity.TOP, 25, 400);
              eToast.show();
            }
          }
        }); // end scanBarcode onClickListener
  }