Fix duplicated watchlist elements
This commit is contained in:
parent
7505d8a1be
commit
3b894c634b
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
@ -92,17 +92,31 @@ public class DatabaseManager extends SQLiteOpenHelper{
|
|||||||
onCreate(db);
|
onCreate(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isCurrencyInWatchlist(String symbol)
|
||||||
|
{
|
||||||
|
String searchQuerry = "SELECT * FROM " + TABLE_WATCHLIST + " WHERE " + KEY_WATCHLIST_SYMBOL + "='" + symbol + "'";
|
||||||
|
SQLiteDatabase db = this.getWritableDatabase();
|
||||||
|
|
||||||
|
Cursor result = db.rawQuery(searchQuerry, null);
|
||||||
|
|
||||||
|
return result.moveToFirst();
|
||||||
|
}
|
||||||
|
|
||||||
public void addCurrencyToWatchlist(Currency currency)
|
public void addCurrencyToWatchlist(Currency currency)
|
||||||
{
|
{
|
||||||
SQLiteDatabase db = this.getWritableDatabase();
|
SQLiteDatabase db = this.getWritableDatabase();
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
|
|
||||||
values.put(KEY_WATCHLIST_SYMBOL, currency.getSymbol());
|
if(!isCurrencyInWatchlist(currency.getSymbol()))
|
||||||
values.put(KEY_WATCHLIST_NAME, currency.getName());
|
{
|
||||||
values.put(KEY_WATCHLIST_POSITION, getWatchlistRowCount(db));
|
ContentValues values = new ContentValues();
|
||||||
|
|
||||||
db.insert(TABLE_WATCHLIST, null, values);
|
values.put(KEY_WATCHLIST_SYMBOL, currency.getSymbol());
|
||||||
db.close();
|
values.put(KEY_WATCHLIST_NAME, currency.getName());
|
||||||
|
values.put(KEY_WATCHLIST_POSITION, getWatchlistRowCount(db));
|
||||||
|
|
||||||
|
db.insert(TABLE_WATCHLIST, null, values);
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateWatchlistPosition(String symbol, int position)
|
public void updateWatchlistPosition(String symbol, int position)
|
||||||
|
Loading…
Reference in New Issue
Block a user