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.AdapterView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.SearchView; import android.widget.SearchView;
import android.widget.Toast;
import com.herbron.moodl.DataManagers.BalanceManager; import com.herbron.moodl.DataManagers.BalanceManager;
import com.herbron.moodl.DataManagers.CurrencyData.Currency; import com.herbron.moodl.DataManagers.CurrencyData.Currency;
@ -96,10 +97,16 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear
PreferencesManager preferencesManager = new PreferencesManager(getApplicationContext()); PreferencesManager preferencesManager = new PreferencesManager(getApplicationContext());
DatabaseManager databaseManager = new DatabaseManager(getApplicationContext()); DatabaseManager databaseManager = new DatabaseManager(getApplicationContext());
databaseManager.addCurrencyToWatchlist(selectedCurrency); if(databaseManager.addCurrencyToWatchlist(selectedCurrency))
{
preferencesManager.setMustUpdateWatchlist(true); preferencesManager.setMustUpdateWatchlist(true);
} }
else else
{
Toast.makeText(getApplicationContext(), "Currency already in watchlist.", Toast.LENGTH_SHORT).show();
}
}
else
{ {
Intent intent = new Intent(CurrencySelectionActivity.this, RecordTransactionActivity.class); Intent intent = new Intent(CurrencySelectionActivity.this, RecordTransactionActivity.class);
intent.putExtra("coin", selectedCurrency.getName()); intent.putExtra("coin", selectedCurrency.getName());

View File

@ -102,7 +102,7 @@ public class DatabaseManager extends SQLiteOpenHelper{
return result.moveToFirst(); return result.moveToFirst();
} }
public void addCurrencyToWatchlist(Currency currency) public boolean addCurrencyToWatchlist(Currency currency)
{ {
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
@ -116,7 +116,11 @@ public class DatabaseManager extends SQLiteOpenHelper{
db.insert(TABLE_WATCHLIST, null, values); db.insert(TABLE_WATCHLIST, null, values);
db.close(); db.close();
return true;
} }
return false;
} }
public void updateWatchlistPosition(String symbol, int position) public void updateWatchlistPosition(String symbol, int position)