コード例 #1
0
  public static void syncPosts(
      ContentResolver content,
      TagNode aThread,
      int aThreadId,
      int unreadIndex,
      int opId,
      AwfulPreferences prefs,
      int startIndex) {
    ArrayList<ContentValues> result =
        AwfulPost.parsePosts(aThread, aThreadId, unreadIndex, opId, prefs, startIndex);

    int resultCount =
        content.bulkInsert(CONTENT_URI, result.toArray(new ContentValues[result.size()]));
    Log.i(
        TAG,
        "Inserted "
            + resultCount
            + " posts into DB, threadId:"
            + aThreadId
            + " unreadIndex: "
            + unreadIndex);
  }
コード例 #2
0
  public static ArrayList<AwfulPost> fromCursor(Context aContext, Cursor aCursor) {
    ArrayList<AwfulPost> result = new ArrayList<AwfulPost>();

    if (aCursor.moveToFirst()) {
      int idIndex = aCursor.getColumnIndex(ID);
      int threadIdIndex = aCursor.getColumnIndex(THREAD_ID);
      int postIndexIndex = aCursor.getColumnIndex(POST_INDEX); // ooh, meta
      int dateIndex = aCursor.getColumnIndex(DATE);
      int userIdIndex = aCursor.getColumnIndex(USER_ID);
      int usernameIndex = aCursor.getColumnIndex(USERNAME);
      int previouslyReadIndex = aCursor.getColumnIndex(PREVIOUSLY_READ);
      int editableIndex = aCursor.getColumnIndex(EDITABLE);
      int isOpIndex = aCursor.getColumnIndex(IS_OP);
      int isAdminIndex = aCursor.getColumnIndex(IS_ADMIN);
      int isModIndex = aCursor.getColumnIndex(IS_MOD);
      int avatarIndex = aCursor.getColumnIndex(AVATAR);
      int avatarTextIndex = aCursor.getColumnIndex(AVATAR_TEXT);
      int contentIndex = aCursor.getColumnIndex(CONTENT);
      int editedIndex = aCursor.getColumnIndex(EDITED);

      AwfulPost current;

      do {
        current = new AwfulPost();
        current.setId(aCursor.getString(idIndex));
        current.setThreadId(aCursor.getInt(threadIdIndex));
        current.setDate(aCursor.getString(dateIndex));
        current.setUserId(aCursor.getString(userIdIndex));
        current.setUsername(aCursor.getString(usernameIndex));
        current.setPreviouslyRead(aCursor.getInt(previouslyReadIndex) > 0 ? true : false);
        current.setLastReadUrl(aCursor.getInt(postIndexIndex) + "");
        current.setEditable(aCursor.getInt(editableIndex) == 1 ? true : false);
        current.setIsOp(aCursor.getInt(isOpIndex) == 1 ? true : false);
        current.setIsAdmin(aCursor.getInt(isAdminIndex) > 0 ? true : false);
        current.setIsMod(aCursor.getInt(isModIndex) > 0 ? true : false);
        current.setAvatar(aCursor.getString(avatarIndex));
        current.setAvatarText(aCursor.getString(avatarTextIndex));
        current.setContent(aCursor.getString(contentIndex));
        current.setEdited(aCursor.getString(editedIndex));

        result.add(current);
      } while (aCursor.moveToNext());
    } else {
      Log.i(TAG, "No posts to convert.");
    }
    return result;
  }