/** * 添加段子 * * @param content * @param afterToday true今天之后,反之今天之前 * @return */ public boolean inSertContent(String content, boolean afterToday) { Date date = afterToday ? mDailyJokeDAO.getLastDate() : mDailyJokeDAO.getBeforeDate(); if (date == null) { date = filterDateFormat(new Date()); if (getByDate(date) != null) return false; } else { date = offsetDate(afterToday ? 1 : -1, date); } DailyJoke dj = new DailyJoke(); dj.setContent(content); dj.setDate(date); return inSert(dj); }
public DailyJoke getById(int id) { try { return mDailyJokeDAO.getById(id); } catch (Exception e) { e.toString(); } return null; }
public boolean update(String content, Date date) { try { return mDailyJokeDAO.update(content, date) == 1 ? true : false; } catch (Exception e) { e.toString(); } return false; }
/** * @param date 删除date[包括date]之前的段子 * @return */ public boolean deleteBefore(Date date) { try { return mDailyJokeDAO.deleteBefore(date) >= 1 ? true : false; } catch (Exception e) { e.toString(); } return false; }
public int getCount() { try { return mDailyJokeDAO.getCount(); } catch (Exception e) { e.toString(); } return 0; }
public List<DailyJoke> getAll(int offset, int limit) { try { return mDailyJokeDAO.getAll(offset, limit); } catch (Exception e) { e.toString(); } return null; }
public List<DailyJoke> getAll(Date date, int offset, int limit) { try { date = filterDateFormat(date); return mDailyJokeDAO.getAll(date, offset, limit); } catch (Exception e) { e.toString(); } return null; }
public DailyJoke getByDate(Date date) { try { date = filterDateFormat(date); return mDailyJokeDAO.getByDate(date); } catch (Exception e) { e.toString(); } return null; }
/** * 删除今天起多少天以前的段子 * * @param offset * @return */ public boolean deleteBefore(int offset) { try { return mDailyJokeDAO.deleteBefore(offsetDate(-Math.abs(offset), new Date())) >= 1 ? true : false; } catch (Exception e) { e.toString(); } return false; }
public boolean inSert(DailyJoke mDailyJoke) { try { if (getByDate(mDailyJoke.getDate()) != null) { return false; } mDailyJoke.setDate(filterDateFormat(mDailyJoke.getDate())); return mDailyJokeDAO.insert(mDailyJoke) == 1 ? true : false; } catch (Exception e) { e.toString(); } return false; }