Пример #1
0
  public boolean updataFeedFromServer(final int page, final int topicId, final int size) {
    Log.d(
        TAG,
        String.format("::updataFeedFromServer(page=%s,topicID=%s,size%s)", page, topicId, size));
    try {
      List<JokeBean> jokeItems = new ArrayList<JokeBean>();
      JokeClient client = new JokeClient();
      ResponseData responseData = client.getJokes(page, size, topicId);

      if (responseData.getStatus()) {
        SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
        JokeBeanHandler handler = new JokeBeanHandler();
        InputSource is = new InputSource(new StringReader(responseData.toString()));
        parser.parse(is, handler);

        jokeItems.addAll(handler.getJokeItems());

        /* Set topic id */
        for (JokeBean item : jokeItems) {
          item.setTopic(topicId);
        }

        /* Now write the joke to cache */
        return db.addAll(jokeItems);
      }
    } catch (Exception e) {
      Log.e(TAG, "" + e.getMessage());
      e.printStackTrace();
    }
    return false;
  }
Пример #2
0
 public static List<JokeBean> loadJokeFromCache(
     final Context context, final int topicId, final int page) {
   return db.getList(page, mPageSize, topicId);
 }