Since the messages are being persisted to the local database, the StockUpdatePutResolver file and StockUpdateGetResolver need to be updated as well.
We will start by adding a new field definition to the StockUpdateTable:
static class Columns {
...
static final String TWITTER_STATUS = "twitter_status";
}
Then we'll update the createTableQuery() method:
static String createTableQuery() {
return "CREATE TABLE " + TABLE + "("
+ Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ Columns.STOCK_SYMBOL + " TEXT NOT NULL, "
+ Columns.DATE + " LONG NOT NULL, "
+ Columns.PRICE + " LONG NOT NULL, "
+ Columns.TWITTER_STATUS + " TEXT NULL, "
+ ");";
}
Since we have updated the SQLite table definition, we will need to wipe the data of the application so that the database can be recreated from scratch with all the fields.
Normally, we would use the onUpgrade() methods in StorIODbHelper, but since the application wasn't released publicly, there is no need.
Normally, we would use the onUpgrade() methods in StorIODbHelper, but since the application wasn't released publicly, there is no need.
StockUpdatePutResolver will need to save one additional field with this:
protected ContentValues mapToContentValues(@NonNull StockUpdate entity) {
final ContentValues contentValues = new ContentValues();
contentValues.put(StockUpdateTable.Columns.ID, entity.getId());
contentValues.put(StockUpdateTable.Columns.STOCK_SYMBOL,
entity.getStockSymbol());
contentValues.put(StockUpdateTable.Columns.PRICE,
getPrice(entity));
contentValues.put(StockUpdateTable.Columns.DATE, getDate(entity));
contentValues.put(StockUpdateTable.Columns.TWITTER_STATUS,
entity.getTwitterStatus());
return contentValues;
}
On the other hand, the StockUpdateGetResolver will have the following:
final String twitterStatus = cursor.getString(cursor.getColumnIndexOrThrow(StockUpdateTable.Columns.TWITTER_STATUS));
[...]
final StockUpdate stockUpdate = new StockUpdate(
stockSymbol,
price,
date,
twitterStatus
);
After this is done, we can proceed with the layouts.