Ejemplo n.º 1
0
    public void onDateSet(DatePicker view, int year, int month, int day) {
      // Do something with the date chosen by the user
      Calendar c = Calendar.getInstance();
      c.set(Calendar.YEAR, year);
      c.set(Calendar.MONTH, month);
      c.set(Calendar.DAY_OF_MONTH, day);

      Date weekStart = Week.getWeekStart(c.getTime());
      instance.mGshisLoader.setCurrWeekStart(weekStart);

      Pupil p = Pupil.getByFormName(instance.mGshisLoader.getLogin(), instance.getPupilName());
      if (p != null) {

        Schedule s = p.getScheduleByDate(weekStart);

        for (int index = 0; index < 4; index++) {

          GradeSemester sem = s.getSemesterByNumber(index);

          if (sem != null
              && sem.getStart().getTime() <= weekStart.getTime()
              && sem.getStop().getTime() >= weekStart.getTime()) {

            instance.mViewPager.setCurrentItem(index, true);
            break;
          }
        }
      }

      // this picker should not load again
      instance
          .getHandler()
          .postDelayed(
              new Runnable() {
                public void run() {

                  instance.recreate();
                }
              },
              1);
    }
Ejemplo n.º 2
0
  public static GradeSemester getActiveGradeSemester(Document doc, Schedule sch)
      throws ParseException {

    boolean found = false;
    GradeSemester selG = null;

    SimpleDateFormat fmt = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH);
    fmt.setTimeZone(TimeZone.getTimeZone("Europe/Moscow"));

    Elements semesterSelectors = doc.getElementsByAttributeValue("id", "ctl00_body_drdTerms");
    for (Element semesterSelector : semesterSelectors) {

      Elements semesters = semesterSelector.getAllElements();
      for (Element semester : semesters) {
        if (semester.tagName().equals("option")) {

          String value = semester.text();
          GradeSemester sem;
          found = true;

          if ((sem = sch.getSemester(semester.attr("value"))) == null) {

            sem = new GradeSemester();

            sem.setStart(fmt.parse(value.substring(12, value.indexOf("-") - 1)));
            sem.setStop(fmt.parse(value.substring(value.indexOf("-") + 2, value.length() - 2)));
            sem.setFormText(semester.text());
            sem.setFormId(semester.attr("value"));

            sch.addSemester(sem);
          }

          if (semester.hasAttr("selected") && semester.attr("selected").equals("selected")) {

            long u = sem.setLoaded().update();
            selG = sem;

            if (BuildConfig.DEBUG) Log.d("GshisHTMLParser", TS.get() + " Semester.update() = " + u);
          }
        }
      }
    }

    if (!found) throw new ParseException("Semesters not found", 0);

    return selG;
  }
Ejemplo n.º 3
0
  public static void getGrades(Document doc, Schedule sch, GradeSemester s) throws ParseException {

    mNewMarks = new ArrayList<MarkRec>();

    Elements tableCells = doc.getElementsByAttributeValue("class", "table rating");
    for (Element tableCell : tableCells) {

      Elements trs = tableCell.getElementsByTag("tr");
      for (Element tr : trs) {

        if (tr.hasAttr("class") && tr.attr("class").equals("table-header")) continue;

        GradeRec rec = new GradeRec();
        int thCount = 0;

        Elements ths = tr.getElementsByTag("th");
        for (Element th : ths) {

          if (th.hasAttr("class") && th.attr("class").equals("table-header3")) {

            rec.setFormText(th.text());
            thCount = 2;

          } else if (th.hasAttr("class") && th.attr("class").equals("cell-header2")) {

            switch (thCount) {
              case 2:
                if (containsPrintableChars(th.text())) rec.setAbsent(Integer.parseInt(th.text()));
                break;
              case 3:
                if (containsPrintableChars(th.text())) rec.setReleased(Integer.parseInt(th.text()));
                break;
              case 4:
                if (containsPrintableChars(th.text())) rec.setSick(Integer.parseInt(th.text()));
                break;
              case 5:
                if (containsPrintableChars(th.text()))
                  rec.setAverage(Float.parseFloat(th.text().replace(',', '.')));
                break;
            }

            thCount++;
          }
        }

        Element total = tr.getElementsByTag("td").last();
        if (containsPrintableChars(total.text()) && total.text().matches("[-+]?\\d*\\.?\\d+")) {

          rec.setTotal(Integer.parseInt(total.text()));
        }

        rec.setStart(s.getStart());
        rec.setStop(s.getStop());

        if (containsPrintableChars(rec.getFormText())) {

          GradeRec exR = sch.getGradeRecByDateText(rec.getStart(), rec.getFormText());
          if (exR != null) {

            //						if (BuildConfig.DEBUG)
            //							Log.d("GshisHTMLParser",
            //									TS.get()
            //											+ " before update GradeRec, start = "
            //											+ exR.getStart() + " stop = "
            //											+ exR.getStop() + " text = "
            //											+ exR.getFormText());

            exR.setAbsent(rec.getAbsent());
            exR.setAverage(rec.getAverage());
            exR.setReleased(rec.getReleased());
            exR.setSick(rec.getSick());
            exR.setTotal(rec.getTotal());

            // make sure we have only fresh marks
            exR.deleteMarks();

            @SuppressWarnings("unused")
            long u = exR.update();
            rec = exR;

            //						if (BuildConfig.DEBUG)
            //							Log.d("GshisHTMLParser", TS.get()
            //									+ " GradeRec.update() = " + u);
          } else {
            //						if (BuildConfig.DEBUG)
            //							Log.d("GshisHTMLParser", TS.get()
            //									+ " insert GradeRec = " + rec);

            sch.addGradeRec(rec);
          }

          for (Element td : tr.getElementsByTag("td")) {

            if (td.hasAttr("class") && td.attr("class").equals("grade-with-type")) {

              Element span = td.getElementsByTag("span").first();

              if (containsPrintableChars(span.text())
                  && containsPrintableChars(span.attr("title"))) {

                MarkRec mr = rec.getMarkRecByComment(span.attr("title"));
                if (mr != null) {

                  mr.setMarks(span.text());

                  @SuppressWarnings("unused")
                  long u = mr.update();

                  //									if (BuildConfig.DEBUG)
                  //										Log.d("GshisHTMLParser", TS.get() + " MarkRec.update() = " + u
                  //												+ " rec = " + rec);
                } else {

                  mr = new MarkRec(span.text(), span.attr("title"));

                  mNewMarks.add(mr);
                  rec.addMarcRec(mr);

                  //									if (BuildConfig.DEBUG)
                  //										Log.d("GshisHTMLParser", TS.get()
                  //												+ " insert MarkRec Comment = " + mr.getComment() + " Marks = "
                  //												+ mr.getMarks());
                }
              }
            }
          }
        }
      }
    }
  }