From 0c0cfff731f253414b5dc6d90f351b37e123c9a0 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Tue, 5 Jun 2018 08:41:42 +0200 Subject: [PATCH] Add Toast to show when a Currency is already in the watchlist --- .../moodl/Activities/CurrencySelectionActivity.java | 11 +++++++++-- .../herbron/moodl/DataManagers/DatabaseManager.java | 6 +++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/herbron/moodl/Activities/CurrencySelectionActivity.java b/app/src/main/java/com/herbron/moodl/Activities/CurrencySelectionActivity.java index 302d502..c15e4ea 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/CurrencySelectionActivity.java +++ b/app/src/main/java/com/herbron/moodl/Activities/CurrencySelectionActivity.java @@ -14,6 +14,7 @@ import android.view.animation.Transformation; import android.widget.AdapterView; import android.widget.ListView; import android.widget.SearchView; +import android.widget.Toast; import com.herbron.moodl.DataManagers.BalanceManager; import com.herbron.moodl.DataManagers.CurrencyData.Currency; @@ -96,8 +97,14 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear PreferencesManager preferencesManager = new PreferencesManager(getApplicationContext()); DatabaseManager databaseManager = new DatabaseManager(getApplicationContext()); - databaseManager.addCurrencyToWatchlist(selectedCurrency); - preferencesManager.setMustUpdateWatchlist(true); + if(databaseManager.addCurrencyToWatchlist(selectedCurrency)) + { + preferencesManager.setMustUpdateWatchlist(true); + } + else + { + Toast.makeText(getApplicationContext(), "Currency already in watchlist.", Toast.LENGTH_SHORT).show(); + } } else { diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java b/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java index 8a05e56..418bbf6 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java @@ -102,7 +102,7 @@ public class DatabaseManager extends SQLiteOpenHelper{ return result.moveToFirst(); } - public void addCurrencyToWatchlist(Currency currency) + public boolean addCurrencyToWatchlist(Currency currency) { SQLiteDatabase db = this.getWritableDatabase(); @@ -116,7 +116,11 @@ public class DatabaseManager extends SQLiteOpenHelper{ db.insert(TABLE_WATCHLIST, null, values); db.close(); + + return true; } + + return false; } public void updateWatchlistPosition(String symbol, int position)