Beispiel #1
0
  private void dibujarDias() {
    for (int i = 0; i < mDias.size(); i++) {
      final List<String> needPhotos = new ArrayList<>();

      View vDia = LayoutInflater.from(this).inflate(R.layout.proyectos_detalle, null, false);

      TextView dia_p_programado = (TextView) vDia.findViewById(R.id.programado);
      final TextView dia_p_real = (TextView) vDia.findViewById(R.id.real);
      TextView dia_n = (TextView) vDia.findViewById(R.id.dia);
      final LinearLayout dia_contenido = (LinearLayout) vDia.findViewById(R.id.content);
      final LinearLayout dia_actividades = (LinearLayout) vDia.findViewById(R.id.activityList);
      final EditText p_real = (EditText) vDia.findViewById(R.id.avance);
      final EditText p_fecha = (EditText) vDia.findViewById(R.id.fecha);
      EditText p_observacion = (EditText) vDia.findViewById(R.id.observacion);
      final ImageButton expand = (ImageButton) vDia.findViewById(R.id.expand);
      ImageButton dia_foto = (ImageButton) vDia.findViewById(R.id.foto);

      /*p_fecha.setOnFocusChangeListener(new View.OnFocusChangeListener() {
          @Override
          public void onFocusChange(View view, boolean b) {
              if (b) {
                  p_fecha.setText("");
              }
          }
      });*/
      dia_foto.setVisibility(View.GONE);

      expand.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              if (dia_contenido.getVisibility() == View.GONE) {
                dia_contenido.setVisibility(View.VISIBLE);
                expand.setImageResource(R.drawable.ic_action_close);
              } else {
                dia_contenido.setVisibility(View.GONE);
                expand.setImageResource(R.drawable.ic_action_open);
              }
            }
          });

      final Dia dia = mDias.get(i);
      final ArrayList<Actividad> actividadArrayList = dia.getActividades();
      dia.setAdvanceToday("0");

      p_fecha.setText(dia.getDate());

      /*p_fecha.setOnFocusChangeListener(new View.OnFocusChangeListener() {
          @Override
          public void onFocusChange(View view, boolean b) {
              if (!b) {
                  if (!Funciones.validateDate(p_fecha.getText().toString())) {
                      AlertDialog.Builder b1 = new AlertDialog.Builder(mContext);
                      b1.setIcon(android.R.drawable.ic_dialog_alert);
                      b1.setMessage("Formato de fecha Incorrecto.\nDebe ser AAAA-MM-DD");
                      b1.setTitle("Dia " + dia.getDayNumber());
                      b1.setNeutralButton("OK", new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialogInterface, int i) {
                              dialogInterface.dismiss();
                          }
                      });
                      b1.show();
                      error = true;
                  } else {
                      error = false;
                      try {
                          DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                          Date hoy = new Date();
                          Date fecha_envia = formatter.parse(p_fecha.getText().toString());

                          Log.d("FECHAS", hoy + "  " + fecha_envia);
                          if (formatter.format(fecha_envia).compareTo(formatter.format(hoy)) < 0) {
                              AlertDialog.Builder b1 = new AlertDialog.Builder(mContext);
                              b1.setIcon(android.R.drawable.ic_dialog_alert);
                              b1.setMessage("No puede ingresar una fecha anterior al día de hoy.");
                              b1.setTitle("Dia " + dia.getDayNumber());
                              b1.setNeutralButton("OK", new DialogInterface.OnClickListener() {
                                  @Override
                                  public void onClick(DialogInterface dialogInterface, int i) {
                                      dialogInterface.dismiss();
                                  }
                              });
                              b1.show();
                              error = true;
                          }
                      } catch (Exception e) {
                          e.printStackTrace();
                          error = true;
                      }

                  }
              }
          }
      });*/

      p_observacion.setText(dia.getDescriptionDay());
      dia_p_programado.setText(dia.getProgrammedAdvance());
      dia_p_real.setText(dia.getRealAdvance());
      dia_n.setText("DIA " + dia.getDayNumber());

      dia.setFecha(p_fecha);
      dia.setlContenido(dia_contenido);

      ArrayList<CheckBox> checkBoxes = new ArrayList<>();
      for (int j = 0; j < actividadArrayList.size(); j++) {
        final Actividad a = actividadArrayList.get(j);

        /** SI una actividad requiere foto se activara el boton * */
        if (a.isFoto()) dia_foto.setVisibility(View.VISIBLE);
        needPhotos.add(dia.getDayNumber() + ";" + a.getNameActivity());

        CheckBox c = new CheckBox(mContext);
        c.setLayoutParams(
            new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        c.setText(a.getNameActivity());
        c.setPadding(0, 0, 0, 24);

        if (a.isSelected()) {
          c.setEnabled(false);
          c.setChecked(true);
        }

        c.setOnCheckedChangeListener(
            new CompoundButton.OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton compoundButton, boolean b) {

                Log.i("CHECKBOX LISTENER", "****");
                float advance;
                if (dia.getAdvanceToday() == null) {
                  advance = 0;
                } else advance = Float.parseFloat(dia.getAdvanceToday());
                Log.i("CHECKBOX LISTENER", "advance: " + advance);
                try {
                  if (b) {
                    advance += a.getAdvance();
                    avance_real_total += a.getAdvance();
                    dia.setModify(true);

                    for (int k = dia.getDayNumber() - 1; k < mAvances.size(); k++) {
                      float actual = Float.parseFloat(mAvances.get(k).getText().toString());
                      mAvances
                          .get(k)
                          .setText(
                              String.format(Locale.US, FLOAT_FORMAT, (actual + a.getAdvance())));
                    }

                  } else {
                    advance -= a.getAdvance();
                    avance_real_total -= a.getAdvance();
                    if (advance < 0) advance *= -1;

                    for (int k = dia.getDayNumber() - 1; k < mAvances.size(); k++) {
                      float actual = Float.parseFloat(mAvances.get(k).getText().toString());
                      mAvances
                          .get(k)
                          .setText(
                              String.format(Locale.US, FLOAT_FORMAT, (actual - a.getAdvance())));
                    }
                  }

                  Log.i("CHECKBOX LISTENER", "to: " + advance);
                  dia.setAdvanceToday(String.format(Locale.US, FLOAT_FORMAT, advance));
                  p_real.setText(String.format(Locale.US, FLOAT_FORMAT, advance));
                  updateProgresoTotal();
                } catch (Exception e) {
                  Toast.makeText(
                          mContext,
                          e.getMessage() + "\n" + e.getCause() + "\n" + e.getLocalizedMessage(),
                          Toast.LENGTH_LONG)
                      .show();
                }
              }
            });
        checkBoxes.add(c);
        dia_actividades.addView(c);
      }

      dia_foto.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              DateFormat timestamp_name = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
              imgActual = new ImagenDia(mProyecto.getId(), dia.getDayNumber(), null, new Date());
              imgActual.setFilename(
                  imgActual.getIdproject()
                      + "_"
                      + imgActual.getIdday()
                      + "_"
                      + timestamp_name.format(imgActual.getTimestamp())
                      + ".png");
              tomarFotografia();
            }
          });

      mAvances.add(dia_p_real);
      dia.setFecha(p_fecha);
      dia.setObservacion(p_observacion);
      dia.setAvance(p_real);
      dia.setCheckBoxes(checkBoxes);
      listadoDias.addView(vDia);
    }
  }
Beispiel #2
0
  private boolean fechasOK() {
    for (final Dia d : mDias) {
      String fecha = d.getFecha().getText().toString();
      if (fecha.length() > 0) {
        if (!Funciones.validateDate(fecha)) {
          AlertDialog.Builder b1 = new AlertDialog.Builder(mContext);
          b1.setIcon(android.R.drawable.ic_dialog_alert);
          b1.setMessage("Formato de fecha Incorrecto.\nDebe ser AAAA-MM-DD");
          b1.setTitle("Dia " + d.getDayNumber());
          b1.setNeutralButton(
              "OK",
              new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                  if (d.getlContenido().getVisibility() == View.GONE) {
                    d.getlContenido().setVisibility(View.VISIBLE);
                  }
                  d.getFecha().requestFocus();
                  dialogInterface.dismiss();
                }
              });
          b1.show();
          return false;
        } else {
          try {
            DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            Date hoy = new Date();
            Date fecha_envia = formatter.parse(fecha);

            Log.d("FECHAS", hoy + "  " + fecha_envia);
            if (formatter.format(fecha_envia).compareTo(formatter.format(hoy)) < 0) {
              AlertDialog.Builder b1 = new AlertDialog.Builder(mContext);
              b1.setIcon(android.R.drawable.ic_dialog_alert);
              b1.setMessage("No puede ingresar una fecha anterior al día de hoy.");
              b1.setTitle("Dia " + d.getDayNumber());
              b1.setNeutralButton(
                  "OK",
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                      if (d.getlContenido().getVisibility() == View.GONE) {
                        d.getlContenido().setVisibility(View.VISIBLE);
                      }
                      d.getFecha().requestFocus();
                      dialogInterface.dismiss();
                    }
                  });
              b1.show();
              return false;
            }
          } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(
                    mContext,
                    "Ocurrió un error al comprobar la fecha, por favor reintente",
                    Toast.LENGTH_LONG)
                .show();
            return false;
          }
        }
      }
    }
    return true;
  }