Exemplo n.º 1
0
  @Override
  public View getView(int i, View view, ViewGroup viewGroup) {
    View v = view;
    if (v == null) {
      v = layoutInflater.inflate(R.layout.history_item, viewGroup, false);
    }
    v.setTag(i);
    final CheckBox cbHistory = (CheckBox) v.findViewById(R.id.cbHistory);
    cbHistory.setTag(i);
    v.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            cbHistory.setChecked(!cbHistory.isChecked());
            if (cbHistory.isChecked()) {
              checkedModelsIDs.add(getItemId(Integer.parseInt(cbHistory.getTag().toString())));
            } else {
              checkedModelsIDs.remove(getItemId(Integer.parseInt(cbHistory.getTag().toString())));
            }
          }
        });

    TripModel tripModel = tripModelList.get(i);

    TextView tvDate = ButterKnife.findById(v, R.id.tvDate);
    TextView tvMark = ButterKnife.findById(v, R.id.tvMark);
    TextView tvType = ButterKnife.findById(v, R.id.tvType);

    tvDate.setText(simpleDateFormat.format(tripModel.getFinishTime()));
    tvMark.setText(String.format(Double.toString(tripModel.getMark())));
    tvType.setText(tripModel.getTripType().toString());

    return v;
  }
Exemplo n.º 2
0
 public double getAverageMark() {
   // TODO: count only exams and practices
   double mark = 0;
   int count = 0;
   for (TripModel model : tripModelList) {
     if (model.getTripType().equals(AppConstants.TripType.EXAM)
         || model.getTripType().equals(AppConstants.TripType.PRACTICE)) {
       count++;
       mark += model.getMark();
     }
   }
   if (count == 0) {
     return 5.0;
   } else {
     mark = mark / count;
     return mark;
   }
 }