예제 #1
0
 private Long buildLessonId(Day day, Lesson lesson, int weekState, long groupId) {
   long lessonId =
       Long.parseLong(
           TextUtils.concat(
                   Integer.toString(day.getNumber()),
                   Integer.toString(lesson.getNumber()),
                   Integer.toString(weekState),
                   Long.toString(groupId))
               .toString());
   return lessonId;
 }
예제 #2
0
  public void saveLessons(LessonList lessonList, long groupId) {
    deleteOldLessons(groupId);

    try {
      mDb.beginTransaction();
      for (Day day : lessonList.getDays()) {
        for (Lesson lesson : day.getLessons()) {

          if (lesson.getDoubleLine() != null) {
            mSaveLessonStatement.bindLong(1, day.getNumber());
            mSaveLessonStatement.bindLong(2, lesson.getNumber());
            mSaveLessonStatement.bindLong(3, groupId);
            mSaveLessonStatement.bindLong(4, DoubleLine.WEEK_STATE);
            mSaveLessonStatement.bindLong(
                5, buildLessonId(day, lesson, DoubleLine.WEEK_STATE, groupId));
            mSaveLessonStatement.execute();

            for (DoubleLine doubleLine : lesson.getDoubleLine()) {
              saveLessonInformation(
                  doubleLine, buildLessonId(day, lesson, DoubleLine.WEEK_STATE, groupId), groupId);
            }
          } else {

            if (lesson.getUnderLine() != null) {
              mSaveLessonStatement.bindLong(1, day.getNumber());
              mSaveLessonStatement.bindLong(2, lesson.getNumber());
              mSaveLessonStatement.bindLong(3, groupId);
              mSaveLessonStatement.bindLong(4, UnderLine.WEEK_STATE);
              mSaveLessonStatement.bindLong(
                  5, buildLessonId(day, lesson, UnderLine.WEEK_STATE, groupId));
              mSaveLessonStatement.execute();

              for (UnderLine underLine : lesson.getUnderLine()) {
                saveLessonInformation(
                    underLine, buildLessonId(day, lesson, UnderLine.WEEK_STATE, groupId), groupId);
              }
            }

            if (lesson.getOverLine() != null) {
              mSaveLessonStatement.bindLong(1, day.getNumber());
              mSaveLessonStatement.bindLong(2, lesson.getNumber());
              mSaveLessonStatement.bindLong(3, groupId);
              mSaveLessonStatement.bindLong(4, OverLine.WEEK_STATE);
              mSaveLessonStatement.bindLong(
                  5, buildLessonId(day, lesson, OverLine.WEEK_STATE, groupId));
              mSaveLessonStatement.execute();

              for (OverLine overLine : lesson.getOverLine()) {
                saveLessonInformation(
                    overLine, buildLessonId(day, lesson, OverLine.WEEK_STATE, groupId), groupId);
              }
            }
          }
        }
      }
      mDb.setTransactionSuccessful();

    } catch (Exception e) {
      e.printStackTrace();

    } finally {
      mDb.endTransaction();
      notifyObservers();
    }
  }