Commit 3a99cc42 authored by cfabio's avatar cfabio

Add tap on balance to switch from FIAT to Bitcoin

parent 3391dca0
......@@ -25,7 +25,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -7,8 +7,8 @@ android {
applicationId "eu.uwot.fabio.altcoinprices"
minSdkVersion 14
targetSdkVersion 27
versionCode 39
versionName '1.4.17'
versionCode 40
versionName '1.4.18'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
......@@ -29,10 +29,10 @@ dependencies {
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:support-v4:27.1.0'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
}
......@@ -115,12 +115,10 @@ public class AddNewPortfolioItemActivity extends AppCompatActivity implements Ad
final Button button = findViewById(R.id.saveButton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.d("ADDNEW", "altcoinDescription: " + altcoinDescription);
// Check that both amountBought and unitPrice are >= 0
if ((amountBought >= 0f) && (unitPrice >= 0f)) {
boolean res = coin.addItem(altcoinDescription, amountBought, unitPrice, currency);
if (res == true) {
Log.d("DEBUG", "ADDED");
startActivity(new Intent(getApplicationContext(), LoadingActivity.class));
} else {
Log.d("DEBUG", "NOT ADDED");
......
......@@ -97,7 +97,7 @@ class Coin {
"SCX",
"CCP"
};
final String[] iconomi_daa = new String[]{
private final String[] iconomi_daa = new String[]{
"BLX",
"CCC",
"SOPR",
......@@ -207,7 +207,7 @@ class Coin {
String[] coinsLabelDescriptionsString;
Hashtable<String, String> coinsLabelDescriptionHashtable;
Hashtable<String, String> coinsDescriptionLabelHashtable;
final Hashtable<String, String> coinsLabelExchangeHashtable = new Hashtable<String, String>()
private final Hashtable<String, String> coinsLabelExchangeHashtable = new Hashtable<String, String>()
{{ put("BTCUSD", "coinbase");
put("ETHUSD", "coinbase");
......@@ -443,7 +443,7 @@ class Coin {
if (amountBought_old + amountBought > 0) {
// Convert value to the correct currency if needed
if (!altcoinCurrency.equals(currency)) {
unitPrice = currencyToCurrency(unitPrice, altcoinCurrency);
unitPrice = currencyToCurrency(unitPrice, altcoinCurrency, currency);
}
unitPrice = (amountBought_old * unitPrice_old + amountBought * unitPrice) / (amountBought_old + amountBought);
......@@ -500,7 +500,6 @@ class Coin {
coinValue = -1f;
}
// Exchange API are down or reporting broken values
if (coinValue == -1f) {
coinValue = getCoinInitialValue(altcoinName);
......@@ -561,15 +560,36 @@ class Coin {
return coinQuote;
}
// Convert EUR in USD and vice versa //
public float currencyToCurrency(float price, String newCurrency) {
switch (newCurrency) {
// Convert currencies //
public float currencyToCurrency(float price, String currency, String newCurrency) {
switch (currency) {
case "USD":
price *= eurusd;
break;
switch (newCurrency) {
case "EUR":
price *= usdeur;
break;
case "BTC":
price *= 1 / btcusd;
break;
}
case "EUR":
price *= usdeur;
break;
switch (newCurrency) {
case "USD":
price *= eurusd;
break;
case "BTC":
price *= 1 / btceur;
break;
}
case "BTC":
switch (newCurrency) {
case "USD":
price *= btcusd;
break;
case "EUR":
price *= btceur;
break;
}
}
return price;
......
......@@ -52,6 +52,9 @@ public class MainActivity extends AppCompatActivity
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
prefs = getApplicationContext().getSharedPreferences("Settings", 0);
currency = prefs.getString("currency", "EUR");
}
// Reload portfolio data when coming back from nested Activity //
......@@ -70,11 +73,25 @@ public class MainActivity extends AppCompatActivity
// add current balance in FIAT //
TextView balanceCurrency = findViewById(R.id.currentBalance);
currency = prefs.getString("currency", "EUR");
//currency = prefs.getString("currency", "EUR");
float currentPortfolioValueFiat = getCurrentPortfolioValueInFiat();
balanceCurrency.setText(new DecimalFormat("#.###").format(currentPortfolioValueFiat) +
" " +
getCurrencySymbol());
getCurrencySymbol(currency));
// switch balance from FIAT to BTC and vice versa
balanceCurrency.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (currency.equals("BTC")) {
currency = prefs.getString("currency", "EUR");
} else {
currency = "BTC";
}
onResume();
}
});
// gain FIAT/Percentage //
TextView portfolioGain = findViewById(R.id.portfolioGain);
......@@ -91,11 +108,25 @@ public class MainActivity extends AppCompatActivity
portfolioGain.setText(sign +
new DecimalFormat("#.###").format(getPortfolioGainFiat(currentPortfolioValueFiat)) +
" " +
getCurrencySymbol() +
getCurrencySymbol(currency) +
" (" +
sign +
new DecimalFormat("#.##").format(currentPortfolioGain) +
"%)" );
// switch balance from FIAT to BTC and vice versa
portfolioGain.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (currency.equals("BTC")) {
currency = prefs.getString("currency", "EUR");
} else {
currency = "BTC";
}
onResume();
}
});
// display altcoin in portfolio //
ListView listview = findViewById(R.id.portfolioItems);
......@@ -117,10 +148,10 @@ public class MainActivity extends AppCompatActivity
if (!coin.coinsLabelGraph.get(altcoinName).equals("na")) {
loadGraph(altcoinName);
} else {
Toast.makeText(getApplicationContext(),R.string.graphUnavailable, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), R.string.graphUnavailable, Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getApplicationContext(),R.string.networkUnavailable, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), R.string.networkUnavailable, Toast.LENGTH_SHORT).show();
}
}
});
......@@ -209,7 +240,7 @@ public class MainActivity extends AppCompatActivity
return true;
} else {
Toast.makeText(getApplicationContext(),R.string.networkUnavailable, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), R.string.networkUnavailable, Toast.LENGTH_SHORT).show();
return false;
}
}
......@@ -235,40 +266,22 @@ public class MainActivity extends AppCompatActivity
case "USD":
currencySymbol = "$";
break;
case "USDT":
currencySymbol = "USDT";
break;
case "BTC":
currencySymbol = "BTC";
currencySymbol = "\u20BF";
break;
}
return currencySymbol;
}
private String getCurrencySymbol() {
String currencySymbol = null;
switch (currency) {
case "EUR":
currencySymbol = "€";
break;
case "USD":
currencySymbol = "$";
break;
}
return currencySymbol;
}
// Load partfolio array with portfolio items //
// Load portfolio items array //
private void getPortfolioData() {
String coinName;
float amountBought;
float unitValue;
String currency;
prefs = getApplicationContext().getSharedPreferences("Settings", 0);
//prefs = getApplicationContext().getSharedPreferences("Settings", 0);
int y = 0;
......@@ -304,7 +317,7 @@ public class MainActivity extends AppCompatActivity
currentCoinValue = prefs.getFloat(coin.coins[i] + "_currentBalance", 0f);
if (!altcoinCurrency.equals(currency)) {
currentCoinValue = coin.currencyToCurrency(currentCoinValue, currency);
currentCoinValue = coin.currencyToCurrency(currentCoinValue, altcoinCurrency, currency);
}
total += amountBought * currentCoinValue;
}
......@@ -321,10 +334,10 @@ public class MainActivity extends AppCompatActivity
if (amountBought >= 0) {
float unitPrice = prefs.getFloat(coin.coins[i] + "_p", 0);
String altcoinCurrency = prefs.getString(coin.coins[i] + "_currency", "USD");
String altcoinCurrency = prefs.getString(coin.coins[i] + "_currency", "EUR");
if (!altcoinCurrency.equals(currency)) {
unitPrice = coin.currencyToCurrency(unitPrice, currency);
unitPrice = coin.currencyToCurrency(unitPrice, altcoinCurrency, currency);
}
initialValue += amountBought * unitPrice;
}
......@@ -341,10 +354,10 @@ public class MainActivity extends AppCompatActivity
if (amountBought >= 0) {
float unitPrice = prefs.getFloat(coin.coins[i] + "_p", 0);
String altcoinCurrency = prefs.getString(coin.coins[i] + "_currency", "USD");
String altcoinCurrency = prefs.getString(coin.coins[i] + "_currency", "EUR");
if (!altcoinCurrency.equals(currency)) {
unitPrice = coin.currencyToCurrency(unitPrice, currency);
unitPrice = coin.currencyToCurrency(unitPrice, altcoinCurrency, currency);
}
initialValue += amountBought * unitPrice;
}
......@@ -367,7 +380,7 @@ public class MainActivity extends AppCompatActivity
final float unitValue;
final String currency;
public PortfolioItem(String altcoinName, float amountBought, float unitValue, String currency) {
PortfolioItem(String altcoinName, float amountBought, float unitValue, String currency) {
this.altcoinName = altcoinName;
this.amountBought = amountBought;
this.unitValue = unitValue;
......@@ -376,7 +389,7 @@ public class MainActivity extends AppCompatActivity
}
class PortfolioAdapter extends ArrayAdapter<PortfolioItem> {
public PortfolioAdapter(Context context, ArrayList<PortfolioItem> items) {
PortfolioAdapter(Context context, ArrayList<PortfolioItem> items) {
super(context, R.layout.single_element_of_portfolio, items);
}
......
......@@ -8,9 +8,7 @@ import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.TextView;
......@@ -18,7 +16,8 @@ public class SettingsActivity extends AppCompatActivity implements AdapterView.O
private SharedPreferences prefs;
private SharedPreferences.Editor editor;
private Switch currencySwitch;
private Spinner currencySpinner;
private String currency;
private Spinner periodSpinner;
private String period;
private Spinner timezoneSpinner;
......@@ -34,33 +33,24 @@ public class SettingsActivity extends AppCompatActivity implements AdapterView.O
// load user settings //
prefs = getApplicationContext().getSharedPreferences("Settings", 0);
editor = prefs.edit();
String currency = prefs.getString("currency", "EUR");
currency = prefs.getString("currency", "EUR");
this.period = prefs.getString("period", DEFAULT_PERIOD);
this.timezone = prefs.getString("timezone", DEFAULT_TIMEZONE);
// currency switch //
currencySwitch = findViewById(R.id.currencySwitch);
currencySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean bChecked) {
if (bChecked) {
currencySwitch.setChecked(true);
editor.putString("currency", "USD");
editor.apply();
} else {
currencySwitch.setChecked(false);
editor.putString("currency", "EUR");
editor.apply();
}
}
});
// set currency //
currencySpinner = findViewById(R.id.currencySpinner);
// Create an ArrayAdapter using the string array and a default altcoinNameSpinner layout
ArrayAdapter<CharSequence> currencyAdapter = ArrayAdapter.createFromResource(this,
R.array.currency_array, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
currencyAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the periodAdapter to the altcoinNameSpinner
currencySpinner.setAdapter(currencyAdapter);
currencySpinner.setOnItemSelectedListener(this);
if (currency.equals("EUR")) {
currencySwitch.setChecked(false);
} else {
currencySwitch.setChecked(true);
}
// Preload spinner with current period setting
int currencySpinnerPosition = currencyAdapter.getPosition(currency);
currencySpinner.setSelection(currencySpinnerPosition);
// set candlestick period //
periodSpinner = findViewById(R.id.periodSpinner);
......@@ -104,6 +94,10 @@ public class SettingsActivity extends AppCompatActivity implements AdapterView.O
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
currency = currencySpinner.getSelectedItem().toString();
editor.putString("currency", currency);
editor.apply();
period = periodSpinner.getSelectedItem().toString();
if ("1 minute".equals(period)) {
......
......@@ -82,11 +82,11 @@
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/currency"
app:layout_constraintTop_toBottomOf="@+id/currencyDescription"
android:layout_marginLeft="8dp" />
<TextView
android:id="@+id/currency"
android:id="@+id/currencyDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
......
......@@ -6,20 +6,27 @@
android:layout_height="match_parent"
tools:context="eu.uwot.fabio.altcoinprices.SettingsActivity">
<Switch
android:id="@+id/currencySwitch"
<TextView
android:id="@+id/currencyDescription"
android:layout_width="0dp"
android:layout_height="27dp"
android:layout_height="40dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="@string/switch_currency_title"
app:layout_constraintHorizontal_bias="0.0"
android:paddingTop="7dp"
android:text="@string/currencyDescription"
android:textAppearance="@style/TextAppearance.AppCompat"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
app:layout_constraintTop_toTopOf="parent" />
<Spinner
android:id="@+id/currencySpinner"
android:layout_width="136dp"
android:layout_height="37dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/periodDescription"
......@@ -31,18 +38,17 @@
android:text="@string/periodDescription"
android:textAppearance="@style/TextAppearance.AppCompat"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/currencySwitch"
android:layout_marginStart="8dp" />
app:layout_constraintTop_toBottomOf="@+id/currencyDescription" />
<Spinner
android:id="@+id/periodSpinner"
android:layout_width="136dp"
android:layout_height="37dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/currencySwitch"
android:layout_marginRight="8dp" />
app:layout_constraintTop_toBottomOf="@+id/currencySpinner" />
<TextView
android:id="@+id/timezoneDescription"
......
......@@ -8,7 +8,6 @@
<string name="action_reload">Recharger</string>
<string name="menu_subtitle">Contrôle le marché des crypto-monnaies en temps réels</string>
<string name="periodDescription">Ajuste la période des candlesticks</string>
<string name="switch_currency_title">Changer la monnaie de EUR à USD</string>
<string name="about_text">Application Android pour garder un oeil sur le prix des crypto-monnaies en temps réels.
\nCode source sur <a href="https://gitlab.com/cfabio/AltcoinPrices">gitlab.com</a>
\n\n<a href="https://gitlab.com/cfabio/AltcoinPrices#how-can-i-support-the-developer">Soutien le développeur et envoie une donation</a>
......
......@@ -20,7 +20,7 @@
<!-- SETTINGS -->
<string name="periodDescription">Set candlestick period</string>
<string name="timezoneDescription">Set timezone</string>
<string name="switch_currency_title">Switch currency from EUR to USD</string>
<string name="currencyDescription">Set global currency</string>
<string name="about_text">Android application to monitor cryptocurrencies prices in real time.
\nGet the full source code at <a href="https://gitlab.com/cfabio/AltcoinPrices">gitlab.com</a>
\n\n<a href="https://gitlab.com/cfabio/AltcoinPrices#how-can-i-support-the-developer">Support the developer and send a donation</a>
......@@ -49,6 +49,7 @@
<string-array name="currency_array">
<item>EUR</item>
<item>USD</item>
<item>BTC</item>
</string-array>
<string-array name="period_array">
......
# CHANGELOG
### Version 1.4.18
* Add tap on balance to switch from FIAT to Bitcoin
### Version 1.4.17
* Add timezone setting
......
......@@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'com.android.tools.build:gradle:3.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment