Add Toast to show when a Currency is already in the watchlist

This commit is contained in:
Tanguy Herbron 2018-06-05 08:41:42 +02:00
parent 3b894c634b
commit 0c0cfff731
2 changed files with 14 additions and 3 deletions

View File

@ -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
{

View File

@ -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)