Example #1
0
  @Override
  public void onGetAlertListByTypeSuccess(ArrayList<HomeBaseAlert> alerts) {
    layout.removeView(loadingProgress);
    // if no alerts
    if (alerts.size() == 0) {
      LayoutInflater inflater = LayoutInflater.from(this);
      LinearLayout buttonCont =
          (LinearLayout) inflater.inflate(R.layout.alert_container, null, false);

      BootstrapButton myButton =
          (BootstrapButton) buttonCont.findViewById(R.id.alertContainer_container);
      BootstrapButton header = (BootstrapButton) myButton.findViewById(R.id.alertContainer_header);

      buttonCont.removeView(myButton);
      myButton.setClickable(false);
      layout.addView(myButton);

      myButton.setText("You have no alerts at this time.");
      myButton.setTextGravity("Center");

      myButton.removeView(header);
      return;
    } else {
      // Fetch all the bills from parse
      for (HomeBaseAlert alert : alerts) {
        LayoutInflater inflater = LayoutInflater.from(this);
        LinearLayout buttonCont =
            (LinearLayout) inflater.inflate(R.layout.bill_container, null, false);

        BootstrapButton myButton =
            (BootstrapButton) buttonCont.findViewById(R.id.alertContainer_container);
        BootstrapButton headerBar =
            (BootstrapButton) myButton.findViewById(R.id.alertContainer_header);
        BootstrapButton amountField =
            (BootstrapButton) myButton.findViewById(R.id.alertContainer_money);

        buttonCont.removeView(myButton);
        layout.addView(myButton);

        String title = alert.getTitle();
        String information = alert.getDescription();
        String money = "$" + alert.getAmount();

        amountField.setBootstrapType("bill");
        amountField.setText(money);
        headerBar.setText(title);
        headerBar.setBootstrapType("bill");
        myButton.fitLine(1);
        myButton.setText(information);

        billContainers.add(myButton);
        billDescriptions.put(myButton, alert);
        billIDs.add(alert.getId());
      }
    }
  }
Example #2
0
  @Override
  public void onUpdateAlertListByTypeSuccess(ArrayList<HomeBaseAlert> alerts) {
    layout.removeAllViews();

    if (alerts.size() == 0) {
      LayoutInflater inflater = LayoutInflater.from(this);
      LinearLayout buttonCont =
          (LinearLayout) inflater.inflate(R.layout.alert_container, null, false);

      BootstrapButton myButton =
          (BootstrapButton) buttonCont.findViewById(R.id.alertContainer_container);
      BootstrapButton header = (BootstrapButton) myButton.findViewById(R.id.alertContainer_header);

      buttonCont.removeView(myButton);
      myButton.setClickable(false);
      layout.addView(myButton);

      myButton.setText("You have no alerts at this time.");
      myButton.setTextGravity("Center");

      myButton.removeView(header);
      return;
    }

    List<BootstrapButton> toDelete = new LinkedList<BootstrapButton>();
    for (BootstrapButton existing : billDescriptions.keySet()) {
      HomeBaseAlert existingAlert = billDescriptions.get(existing);
      if (!alerts.contains(existingAlert)) {
        toDelete.add(existing);
      }
    }

    for (BootstrapButton deleted : toDelete) {
      billIDs.remove(billDescriptions.get(deleted).getId());
      billContainers.remove(deleted);
      billDescriptions.remove(deleted);
    }

    int pointer = 0;
    for (HomeBaseAlert alert : alerts) {
      if (!billIDs.contains(alert.getId())) {
        LayoutInflater inflater = LayoutInflater.from(this);
        LinearLayout buttonCont =
            (LinearLayout) inflater.inflate(R.layout.bill_container, null, false);

        BootstrapButton myButton =
            (BootstrapButton) buttonCont.findViewById(R.id.alertContainer_container);
        BootstrapButton headerBar =
            (BootstrapButton) myButton.findViewById(R.id.alertContainer_header);
        BootstrapButton amountField =
            (BootstrapButton) myButton.findViewById(R.id.alertContainer_money);

        buttonCont.removeView(myButton);

        String title = alert.getTitle();
        String information = alert.getDescription();
        String money = "$" + alert.getAmount();

        amountField.setBootstrapType("bill");
        amountField.setText(money);
        headerBar.setText(title);
        headerBar.setBootstrapType("bill");
        myButton.fitLine(1);
        myButton.setText(information);

        billContainers.add(pointer, myButton);
        pointer++;
        billDescriptions.put(myButton, alert);
        billIDs.add(alert.getId());
      }
    }

    for (int i = 0; i < billContainers.size(); i++) {
      BootstrapButton billContainer = billContainers.get(i);
      layout.addView(billContainer);
    }
  }