Пример #1
0
  private HomeWork getHomeWorkFromCursor(Cursor c) {
    HomeWork result = new HomeWork();
    result.setId(c.getLong(c.getColumnIndex(HomeWork.ID)));
    result.setDate(
        new Date(c.getLong(c.getColumnIndex(HomeWork.DATE)) * CalendarManager.MILISECONDS_PER_DAY));
    result.setLessonId(c.getLong(c.getColumnIndex(HomeWork.LESSON_ID)));
    result.setMessage(c.getString(c.getColumnIndex(HomeWork.MESSAGE)));
    result.setImages(
        Slipper.deserializeObjectToString(c.getBlob(c.getColumnIndex(HomeWork.IMAGES))));
    result.setComplite(c.getInt(c.getColumnIndex(HomeWork.COMPLITE)) > 0);
    result.setGroupId(c.getLong(c.getColumnIndex(HomeWork.GROUP_ID)));

    return result;
  }
Пример #2
0
  public ArrayList<HomeWork> getAllHomeWorks() {
    Long groupId = PreferenceManager.getInstance().getGroupId();
    ArrayList<HomeWork> result = new ArrayList<HomeWork>();
    String query =
        TextUtils.concat(
                "SELECT h.*,l.* FROM ",
                HomeWork.TABLE_NAME,
                " as h ",
                "INNER JOIN ",
                LessonInformation.TABLE_NAME,
                " as l ON ",
                " h.",
                HomeWork.LESSON_ID,
                "=l.",
                LessonInformation.LESSON_ID,
                " WHERE h.",
                HomeWork.GROUP_ID,
                "=? AND h.",
                HomeWork.DATE,
                ">=? ",
                " GROUP BY l.",
                LessonInformation.LESSON_ID,
                " ORDER BY h.",
                HomeWork.DATE)
            .toString();
    Cursor c =
        mDb.rawQuery(
            query,
            new String[] {
              groupId.toString(), Long.toString(Calendar.getInstance().getTimeInMillis())
            });
    while (c.moveToNext()) {

      HomeWork hw = new HomeWork();
      hw.setId(c.getLong(c.getColumnIndex(HomeWork.ID)));
      hw.setDate(new Date(c.getLong(c.getColumnIndex(HomeWork.DATE))));
      hw.setLessonId(c.getLong(c.getColumnIndex(HomeWork.LESSON_ID)));
      hw.setMessage(c.getString(c.getColumnIndex(HomeWork.MESSAGE)));
      hw.setImages(Slipper.deserializeObjectToString(c.getBlob(c.getColumnIndex(HomeWork.IMAGES))));
      hw.setComplite(c.getInt(c.getColumnIndex(HomeWork.COMPLITE)) > 0);
      hw.setGroupId(c.getLong(c.getColumnIndex(HomeWork.GROUP_ID)));
      hw.setLessonTitle(c.getString(c.getColumnIndex(LessonInformation.LESSON_TITLE)));
      result.add(hw);
    }
    return result;
  }