Beispiel #1
0
 private void initBody(final Tweet tweet) {
   final String intialBody = this.intentExtras.getString(ARG_BODY);
   if (intialBody != null) {
     this.txtBody.setText(intialBody);
   } else {
     StringBuilder s = new StringBuilder();
     if (tweet != null && tweet.getUsername() != null) s.append("@").append(tweet.getUsername());
     if (this.alsoMentions != null) {
       for (String mention : this.alsoMentions) {
         s.append(" @").append(mention);
       }
     }
     if (s.length() > 0) {
       s.append(" ");
       this.txtBody.setText(s.toString());
     }
   }
 }
Beispiel #2
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);
  }