Skip to content

Commit

Permalink
Add Toast to show when a Currency is already in the watchlist
Browse files Browse the repository at this point in the history
  • Loading branch information
TanguyHerbron committed Jun 5, 2018
1 parent 3b894c6 commit 0c0cfff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;
Expand Down Expand Up @@ -96,8 +97,14 @@ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private boolean isCurrencyInWatchlist(String symbol)
return result.moveToFirst();
}

public void addCurrencyToWatchlist(Currency currency)
public boolean addCurrencyToWatchlist(Currency currency)
{
SQLiteDatabase db = this.getWritableDatabase();

Expand All @@ -116,7 +116,11 @@ public void addCurrencyToWatchlist(Currency currency)

db.insert(TABLE_WATCHLIST, null, values);
db.close();

return true;
}

return false;
}

public void updateWatchlistPosition(String symbol, int position)
Expand Down

0 comments on commit 0c0cfff

Please sign in to comment.