Fix duplicated watchlist elements

This commit is contained in:
Tanguy Herbron 2018-06-05 08:38:47 +02:00
parent 7505d8a1be
commit 3b894c634b
2 changed files with 20 additions and 6 deletions

Binary file not shown.

View File

@ -92,9 +92,22 @@ 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();
if(!isCurrencyInWatchlist(currency.getSymbol()))
{
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(KEY_WATCHLIST_SYMBOL, currency.getSymbol()); values.put(KEY_WATCHLIST_SYMBOL, currency.getSymbol());
@ -104,6 +117,7 @@ public class DatabaseManager extends SQLiteOpenHelper{
db.insert(TABLE_WATCHLIST, null, values); db.insert(TABLE_WATCHLIST, null, values);
db.close(); db.close();
} }
}
public void updateWatchlistPosition(String symbol, int position) public void updateWatchlistPosition(String symbol, int position)
{ {