Ejemplo n.º 1
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {

    if (convertView == null) {
      LayoutInflater inflater =
          (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      convertView = inflater.inflate(R.layout.lessons_list, null);
    }

    if (mSelectedPos == position) {
      convertView.setBackgroundColor(
          mActivity.getResources().getColor(android.R.color.holo_blue_dark));
    } else {
      convertView.setBackgroundColor(
          mActivity.getResources().getColor(android.R.color.transparent));
    }

    TextView itemNameView = (TextView) convertView.findViewById(R.id.itemName);
    TextView itemDetailView = (TextView) convertView.findViewById(R.id.itemDetail);

    Lesson l = (Lesson) getItem(position);

    if (l != null) {
      itemNameView.setText(Html.fromHtml("" + l.getNumber() + ". " + l.getFormText()));
      itemDetailView.setText(Html.fromHtml(mFormat.format(l.getStart()) + l.getTeacher()));
    }

    return convertView;
  }
Ejemplo n.º 2
0
  public static void getLessons(Document doc, Schedule s) throws ParseException {

    final SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm", Locale.ENGLISH);
    format.setTimeZone(TimeZone.getTimeZone("Europe/Moscow"));

    Elements lessonCells = doc.getElementsByAttribute("number");

    for (Element lessonCell : lessonCells) {

      Lesson l, lPrev = null; // lPrev to handle duplicate lesson
      int sameLesson = 0; // Also to handle duplicate lesson

      int number = Integer.parseInt(lessonCell.attr("number"));
      String time = "";

      Elements timeDetails = lessonCell.getElementsByClass("cell-header2");
      for (Element timeDetail : timeDetails) {
        if (timeDetail.hasAttr("style")) time = timeDetail.text();
      }

      Elements lessonCellDetails = lessonCell.getElementsByAttribute("jsdate");
      for (Element lessonCellDetail : lessonCellDetails) {

        String date = lessonCellDetail.attr("jsdate");
        int index = 0;
        sameLesson = 0;

        for (Element subject :
            lessonCellDetail.getElementsByAttributeValue("class", "lesson-subject")) {

          if (subject == null || subject.text() == null || subject.text().length() <= 0) {
            // No lesson scheduled
            continue;
          }

          Date start = format.parse(date + " " + time.substring(0, time.indexOf("-") - 1));
          if ((l = s.getLessonByNumber(start, number)) == null) {

            if (BuildConfig.DEBUG)
              Log.d("GshisHTMLParser", TS.get() + " getLessons() not found in db, will insert");

            l = new Lesson();
            sameLesson = 0;

            l.setStart(start);
            l.setStop(
                format.parse(date + " " + time.substring(time.indexOf("-") + 2, time.length())));
            l.setFormId(subject.attr("id"));
            l.setFormText(subject.text());
            l.setTeacher(
                lessonCellDetail
                    .getElementsByAttributeValue("class", "lesson-teacher")
                    .get(sameLesson)
                    .text());
            l.setNumber(number);

            s.addLesson(l);

          } else {

            if (BuildConfig.DEBUG)
              Log.d("GshisHTMLParser", TS.get() + " getLessons() found in db, will update");

            l.setFormId(subject.attr("id"));

            if (lPrev != null && lPrev.getStart().equals(start) && lPrev.getNumber() == number) {

              if (BuildConfig.DEBUG)
                Log.d(
                    "GshisHTMLParser",
                    TS.get()
                        + " getLessons() dup = "
                        + subject.text()
                        + " index = "
                        + index
                        + " sameLesson = "
                        + sameLesson);

              sameLesson++;

              if (!lPrev.getFormText().equals(subject.text()))
                l.setFormText(fixDuplicateString(subject.text(), lPrev.getFormText(), sameLesson));

              String teacher =
                  lessonCellDetail
                      .getElementsByAttributeValue("class", "lesson-teacher")
                      .get(index)
                      .text();

              if (!lPrev.getTeacher().equals(teacher))
                l.setTeacher(fixDuplicateString(teacher, lPrev.getTeacher(), sameLesson));

            } else {

              l.setNumber(number);
              l.setFormText(subject.text());
              l.setTeacher(
                  lessonCellDetail
                      .getElementsByAttributeValue("class", "lesson-teacher")
                      .get(index)
                      .text());
            }

            l.update();
          }

          lPrev = l;
          index++;
        }
      }
    }
  }