Exemple #1
0
 @Override
 public void deleteTweet(final Column column, final Tweet tweet) {
   this.mDb.beginTransaction();
   try {
     this.mDb.delete(
         TBL_TW,
         TBL_TW_COLID + "=? AND " + TBL_TW_SID + "=?",
         new String[] {String.valueOf(column.getId()), String.valueOf(tweet.getSid())});
     this.log.d("Deleted tweet %s from %s column %d.", tweet.getSid(), TBL_TW, column.getId());
     this.mDb.setTransactionSuccessful();
   } finally {
     this.mDb.endTransaction();
   }
   notifyTwListenersColumnChanged(column.getId());
 }
Exemple #2
0
 @Override
 public Tweet getTweetDetails(final int columnId, final Tweet tweet) {
   return getTweetDetails(columnId, tweet.getSid());
 }
Exemple #3
0
  @Override
  public void storeTweets(final int columnId, final List<Tweet> tweets) {
    // Clear old data.
    this.mDb.beginTransaction();
    try {
      final int n =
          this.mDb.delete(
              TBL_TW,
              TBL_TW_COLID
                  + "=? AND "
                  + TBL_TW_ID
                  + " NOT IN (SELECT "
                  + TBL_TW_ID
                  + " FROM "
                  + TBL_TW
                  + " WHERE "
                  + TBL_TW_COLID
                  + "=?"
                  + " ORDER BY "
                  + TBL_TW_TIME
                  + " DESC LIMIT "
                  + C.DATA_TW_MAX_COL_ENTRIES
                  + ")",
              new String[] {String.valueOf(columnId), String.valueOf(columnId)});

      this.log.d("Deleted %d rows from %s column %d.", n, TBL_TW, columnId);
      this.mDb.setTransactionSuccessful();
    } finally {
      this.mDb.endTransaction();
    }

    this.mDb.beginTransaction();
    try {
      final ContentValues values = new ContentValues();
      for (final Tweet tweet : tweets) {
        values.clear();
        values.put(TBL_TW_COLID, columnId);
        values.put(TBL_TW_SID, tweet.getSid());
        values.put(TBL_TW_TIME, tweet.getTime());
        values.put(TBL_TW_USERNAME, tweet.getUsername());
        values.put(TBL_TW_FULLNAME, tweet.getFullname());
        values.put(TBL_TW_BODY, tweet.getBody());
        values.put(TBL_TW_AVATAR, tweet.getAvatarUrl());
        final long uid =
            this.mDb.insertWithOnConflict(TBL_TW, null, values, SQLiteDatabase.CONFLICT_REPLACE);

        final List<Meta> metas = tweet.getMetas();
        if (metas != null) {
          for (final Meta meta : metas) {
            values.clear();
            values.put(TBL_TM_TWID, uid);
            values.put(TBL_TM_TYPE, meta.getType().getId());
            values.put(TBL_TM_DATA, meta.getData());
            if (meta.getTitle() != null) values.put(TBL_TM_TITLE, meta.getTitle());
            this.mDb.insertWithOnConflict(TBL_TM, null, values, SQLiteDatabase.CONFLICT_REPLACE);
          }
        }
      }
      this.mDb.setTransactionSuccessful();
    } finally {
      this.mDb.endTransaction();
    }

    notifyTwListenersColumnChanged(columnId);
  }