コード例 #1
0
  public static Pupil getSelectedPupil(Document doc) throws ParseException {

    boolean found = false;
    Pupil p, selectedP = null;

    Elements pupilSelectors =
        doc.getElementsByAttributeValue("id", "ctl00_topMenu_pupil_drdPupils");
    for (Element pupilSelector : pupilSelectors) {

      Elements pupils = pupilSelector.getAllElements();
      for (Element pupil : pupils) {
        if (pupil.tagName().equals("option")) {

          String value = pupil.attr("value");

          found = true;
          if ((p = Pupil.getByFormId(value)) == null) {

            p = new Pupil(pupil.text(), value);
            long rowId = p.insert();

            if (BuildConfig.DEBUG)
              Log.d("GshisHTMLParser", TS.get() + " Pupil.insert() = " + rowId);
          }

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

            selectedP = p;
          }
        }
      }
    }

    if (!found) {

      if (BuildConfig.DEBUG) Log.d("GshisParser", TS.get() + " Alternative fields found!");

      Element userName = doc.getElementsByClass("user-name").first();
      Element userId = doc.getElementsByAttributeValue("id", "ctl00_topMenu_tbUserId").first();

      String name = userName.text();
      String id = userId.attr("value");

      if (BuildConfig.DEBUG) Log.d("GshisParser", TS.get() + " name=" + name + " id=" + id);

      if ((p = Pupil.getByFormId(id)) == null) {

        p = new Pupil(name, id);
        long rowId = p.insert();

        if (BuildConfig.DEBUG) Log.d("GshisParser", TS.get() + " Pupil.insert() = " + rowId);
      }

      selectedP = p;
    }

    if (selectedP == null) throw new ParseException("Pupils not found", 0);

    return selectedP;
  }
コード例 #2
0
  public static Schedule getSelectedSchedule(Document doc, Pupil selPupil) throws ParseException {

    boolean found = false;
    Schedule selectedS = null;

    Elements yearSelectors = doc.getElementsByAttributeValue("id", "ctl00_learnYear_drdLearnYears");
    for (Element yearSelector : yearSelectors) {

      Elements years = yearSelector.getAllElements();
      for (Element year : years) {
        if (year.tagName().equals("option")) {

          String value = year.attr("value");
          Schedule schedule;

          found = true;

          if ((schedule = selPupil.getScheduleByFormId(value)) == null) {

            final SimpleDateFormat f = new SimpleDateFormat("yyyy dd.MM", Locale.ENGLISH);
            f.setTimeZone(TimeZone.getTimeZone("Europe/Moscow"));
            schedule = new Schedule(value, year.text());

            Date start = f.parse(year.text().substring(0, year.text().indexOf("-") - 1) + " 01.09");
            Date stop =
                f.parse(
                    year.text().substring(year.text().indexOf("-") + 2, year.text().length())
                        + " 31.05");

            schedule.setStart(start);
            schedule.setStop(stop);

            selPupil.addSchedule(schedule);
          }

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

            selectedS = schedule;
          }
        }
      }
    }

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

    return selectedS;
  }
コード例 #3
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);
    }