Ejemplo n.º 1
0
  public static Week getSelectedWeek(Document doc, Schedule s) throws ParseException {

    boolean found = false;
    Week selectedW = null;

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

    Elements weekSelectors = doc.getElementsByAttributeValue("id", "ctl00_body_week_drdWeeks");
    for (Element weekSelector : weekSelectors) {

      Elements weeks = weekSelector.getAllElements();
      for (Element week : weeks) {
        if (week.tagName().equals("option")) {

          String value = week.text();
          Week w;
          found = true;

          if ((w = s.getWeek(week.attr("value"))) == null) {

            w = new Week();

            String wBegin = value.substring(0, value.indexOf("-") - 1);
            String wMonth = wBegin.substring(wBegin.indexOf(".") + 1, wBegin.length());

            String year;
            if (Integer.parseInt(wMonth) > 7) {
              year = s.getFormText().substring(0, s.getFormText().indexOf("-") - 1);
            } else {
              year =
                  s.getFormText()
                      .substring(s.getFormText().indexOf("-") + 2, s.getFormText().length());
            }

            w.setStart(f.parse(year + " " + wBegin));
            w.setFormText(week.text());
            w.setFormId(week.attr("value"));

            s.addWeek(w);
          }

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

            selectedW = w;
            long u = w.setLoaded().update();

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

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

    return selectedW;
  }
Ejemplo n.º 2
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);
    }