Added Yen to default currency option

- Add Yen default currency option
- Add spaces for big numbers
- Fix Watchlist and Marketcap Fragments where USD was used instead of other currencies when selected
This commit is contained in:
Tanguy Herbron 2018-04-20 00:32:18 +02:00
parent a9229d9509
commit c2ba8c62e6
8 changed files with 133 additions and 59 deletions

View File

@ -635,6 +635,17 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
str = String.format( Locale.UK, "%.4f", number).replaceAll("\\.?0*$", "");
}
int counter = 0;
for(int i = str.indexOf(".") - 1; i > 0; i--)
{
counter++;
if(counter == 3)
{
str = str.substring(0, i) + " " + str.substring(i, str.length());
counter = 0;
}
}
return str;
}
@ -837,7 +848,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
});
amountTxtView.setText(String.valueOf(transactionList.get(i).getAmount()));
valueTxtView.setText(String.valueOf(transactionList.get(i).getPurchasedPrice()));
valueTxtView.setText(numberConformer(transactionList.get(i).getPurchasedPrice() * transactionList.get(i).getAmount()));
setupSwipeView(view);

View File

@ -26,6 +26,7 @@ import com.github.mikephil.charting.formatter.PercentFormatter;
import com.nauk.coinfolio.Activities.SettingsActivity;
import com.nauk.coinfolio.DataManagers.MarketCapManager;
import com.nauk.coinfolio.DataManagers.PreferencesManager;
import com.nauk.coinfolio.PlaceholderManager;
import com.nauk.coinfolio.R;
import java.text.DecimalFormat;
@ -37,6 +38,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import static java.lang.Math.abs;
/**
* Created by Tiji on 13/04/2018.
*/
@ -150,7 +153,7 @@ public class MarketCapitalization extends Fragment {
{
countCompletedMarketCapRequest();
}
});
}, preferencesManager.getDefaultCurrency());
marketCapManager.updateMarketCap(new MarketCapManager.VolleyCallBack() {
@Override
@ -181,11 +184,10 @@ public class MarketCapitalization extends Fragment {
float otherCurrenciesDominance = 0;
for(Iterator i = marketCapManager.getDominance().keySet().iterator(); i.hasNext(); )
for (String key : marketCapManager.getDominance(preferencesManager.getDefaultCurrency()).keySet())
{
String key = (String) i.next();
entries.add(new PieEntry(marketCapManager.getDominance().get(key), key));
otherCurrenciesDominance += marketCapManager.getDominance().get(key);
entries.add(new PieEntry(marketCapManager.getDominance(preferencesManager.getDefaultCurrency()).get(key), key));
otherCurrenciesDominance += marketCapManager.getDominance(preferencesManager.getDefaultCurrency()).get(key);
colors.add(dominantCurrenciesColors.get(key));
}
@ -256,6 +258,33 @@ public class MarketCapitalization extends Fragment {
pieChart.invalidate();
}
private String numberConformer(double number)
{
String str;
if(abs(number) > 1)
{
str = String.format( Locale.UK, "%.2f", number).replaceAll("\\.?0*$", "");
}
else
{
str = String.format( Locale.UK, "%.4f", number).replaceAll("\\.?0*$", "");
}
int counter = 0;
for(int i = str.length() - 1; i > 0; i--)
{
counter++;
if(counter == 3)
{
str = str.substring(0, i) + " " + str.substring(i, str.length());
counter = 0;
}
}
return str;
}
private SpannableString generateCenterSpannableText() {
SpannableString spannableString = new SpannableString("Market Capitalization Dominance");
@ -264,26 +293,9 @@ public class MarketCapitalization extends Fragment {
private void setupTextViewMarketCap()
{
DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.UK);
DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols();
symbols.setGroupingSeparator(' ');
formatter.setDecimalFormatSymbols(symbols);
switch (preferencesManager.getDefaultCurrency())
{
case "EUR":
((TextView) view.findViewById(R.id.marketCapTextView))
.setText(getActivity().getResources().getString(R.string.market_cap_euros_textview, formatter.format(marketCapManager.getMarketCap())));
((TextView) view.findViewById(R.id.dayVolumeTotalMarketCap))
.setText(getActivity().getResources().getString(R.string.volume_euros_market_cap_textview, formatter.format(marketCapManager.getDayVolume())));
break;
default:
((TextView) view.findViewById(R.id.marketCapTextView))
.setText(getActivity().getResources().getString(R.string.market_cap_dollar_textview, formatter.format(marketCapManager.getMarketCap())));
((TextView) view.findViewById(R.id.dayVolumeTotalMarketCap))
.setText(getActivity().getResources().getString(R.string.volume_dollar_market_cap_textview, formatter.format(marketCapManager.getDayVolume())));
break;
}
((TextView) view.findViewById(R.id.marketCapTextView))
.setText(PlaceholderManager.getValueString(numberConformer(marketCapManager.getMarketCap()), getActivity()));
((TextView) view.findViewById(R.id.dayVolumeTotalMarketCap))
.setText(PlaceholderManager.getValueString(numberConformer(marketCapManager.getDayVolume()), getActivity()));
}
}

View File

@ -429,6 +429,17 @@ public class Summary extends Fragment {
str = String.format( Locale.UK, "%.4f", number).replaceAll("\\.?0*$", "");
}
int counter = 0;
for(int i = str.indexOf(".") - 1; i > 0; i--)
{
counter++;
if(counter == 3)
{
str = str.substring(0, i) + " " + str.substring(i, str.length());
counter = 0;
}
}
return str;
}

View File

@ -43,6 +43,7 @@ import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart;
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDetailsList;
import com.nauk.coinfolio.DataManagers.PreferencesManager;
import com.nauk.coinfolio.DataManagers.WatchlistManager;
import com.nauk.coinfolio.PlaceholderManager;
import com.nauk.coinfolio.R;
import org.json.JSONException;
@ -278,28 +279,17 @@ public class Watchlist extends Fragment {
{
View card = LayoutInflater.from(getContext()).inflate(R.layout.cardview_watchlist, null);
switch (preferencesManager.getDefaultCurrency())
{
case "EUR":
((TextView) card.findViewById(R.id.currencyFluctuationTextView))
.setText(getResources().getString(R.string.currencyEurosParenthesisPlaceholder, numberConformer(currency.getDayFluctuation())));
((TextView) card.findViewById(R.id.currencyValueTextView))
.setText(getResources().getString(R.string.currencyEurosPlaceholder, numberConformer(currency.getValue())));
break;
default :
((TextView) card.findViewById(R.id.currencyFluctuationTextView))
.setText(getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getDayFluctuation())));
((TextView) card.findViewById(R.id.currencyValueTextView))
.setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(currency.getValue())));
break;
}
((TextView) card.findViewById(R.id.currencyFluctuationTextView))
.setText(PlaceholderManager.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), getActivity()));
((TextView) card.findViewById(R.id.currencyValueTextView))
.setText(PlaceholderManager.getValueString(numberConformer(currency.getValue()), getActivity()));
((TextView) card.findViewById(R.id.currencyFluctuationPercentageTextView))
.setText(getResources().getString(R.string.currencyPercentagePlaceholder, numberConformer(currency.getDayFluctuationPercentage())));
.setText(PlaceholderManager.getPercentageString(numberConformer(currency.getDayFluctuationPercentage()), getActivity()));
((TextView) card.findViewById(R.id.currencyNameTextView))
.setText(currency.getName());
((TextView) card.findViewById(R.id.currencySymbolTextView))
.setText(getResources().getString(R.string.currencySymbolPlaceholder, currency.getSymbol()));
.setText(PlaceholderManager.getSymbolString(currency.getSymbol(), getActivity()));
((ImageView) card.findViewById(R.id.currencyIcon)).setImageBitmap(currency.getIcon());
Drawable arrowDrawable = ((ImageView) card.findViewById(R.id.detailsArrow)).getDrawable();
@ -359,7 +349,6 @@ public class Watchlist extends Fragment {
List<CurrencyDataChart> dataChartList = currency.getHistoryMinutes();
ArrayList<Entry> values = new ArrayList<>();
Log.d("coinfolio", "Generating data for " + currency.getSymbol());
for(int i = 0; i < dataChartList.size(); i+=10)
{
values.add(new Entry(i, (float) dataChartList.get(i).getOpen()));
@ -519,11 +508,22 @@ public class Watchlist extends Fragment {
if(abs(number) > 1)
{
str = String.format( Locale.UK, "%.2f", number);
str = String.format( Locale.UK, "%.2f", number).replaceAll("\\.?0*$", "");
}
else
{
str = String.format( Locale.UK, "%.4f", number);
str = String.format( Locale.UK, "%.4f", number).replaceAll("\\.?0*$", "");
}
int counter = 0;
for(int i = str.indexOf(".") - 1; i > 0; i--)
{
counter++;
if(counter == 3)
{
str = str.substring(0, i) + " " + str.substring(i, str.length());
counter = 0;
}
}
return str;

View File

@ -22,7 +22,7 @@ import java.util.regex.Pattern;
public class MarketCapManager {
private static final String topCurrenciesUrl = "https://api.coinmarketcap.com/v1/ticker/?limit=9";
private static final String topCurrenciesUrl = "https://api.coinmarketcap.com/v1/ticker/?limit=9&convert=";
private static final String marketCapUrl = "https://api.coinmarketcap.com/v1/global/?convert=";
private RequestQueue requestQueue;
private String topRequestResult[];
@ -34,14 +34,16 @@ public class MarketCapManager {
requestQueue = Volley.newRequestQueue(context);
}
public void updateTopCurrencies(final VolleyCallBack callBack)
public void updateTopCurrencies(final VolleyCallBack callBack, final String toSymbol)
{
StringRequest strRequest = new StringRequest(Request.Method.GET, topCurrenciesUrl,
String requestString = topCurrenciesUrl + toSymbol;
StringRequest strRequest = new StringRequest(Request.Method.GET, requestString,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if (response.length() > 0) {
processTopCurrencies(response);
processTopCurrencies(response, toSymbol);
}
callBack.onSuccess();
@ -57,7 +59,7 @@ public class MarketCapManager {
requestQueue.add(strRequest);
}
public void updateMarketCap(final VolleyCallBack callBack, String toSymbol)
public void updateMarketCap(final VolleyCallBack callBack, final String toSymbol)
{
String requestString = marketCapUrl + toSymbol;
@ -66,7 +68,7 @@ public class MarketCapManager {
@Override
public void onResponse(String response) {
if (response.length() > 0) {
processMarketCapData(response);
processMarketCapData(response, toSymbol);
}
callBack.onSuccess();
@ -82,20 +84,20 @@ public class MarketCapManager {
requestQueue.add(strRequest);
}
private void processMarketCapData(String response)
private void processMarketCapData(String response, String toSymbol)
{
try {
JSONObject jsonObject = new JSONObject(response);
marketCap = new BigDecimal(jsonObject.getString("total_market_cap_usd")).longValue();
marketCap = new BigDecimal(jsonObject.getString("total_market_cap_" + toSymbol.toLowerCase())).longValue();
dayVolume = new BigDecimal(jsonObject.getString("total_24h_volume_usd")).longValue();
dayVolume = new BigDecimal(jsonObject.getString("total_24h_volume_" + toSymbol.toLowerCase())).longValue();
} catch (JSONException e) {
e.printStackTrace();
}
}
public HashMap<String, Float> getDominance()
public HashMap<String, Float> getDominance(String toSymbol)
{
HashMap<String, Float> dominance = new HashMap<>();
@ -104,7 +106,7 @@ public class MarketCapManager {
try {
JSONObject jsonObject = new JSONObject(topRequestResult[i]);
dominance.put(jsonObject.getString("symbol"), (Float.parseFloat(jsonObject.getString("market_cap_usd")) / marketCap)*100);
dominance.put(jsonObject.getString("symbol"), (Float.parseFloat(jsonObject.getString("market_cap_" + toSymbol.toLowerCase())) / marketCap)*100);
} catch (JSONException e) {
e.printStackTrace();
}
@ -118,7 +120,7 @@ public class MarketCapManager {
return dayVolume;
}
private void processTopCurrencies(String response)
private void processTopCurrencies(String response, String toSymbol)
{
response = response.substring(response.indexOf('[')+1, response.lastIndexOf(']'));

View File

@ -333,6 +333,17 @@ public class HomeLayoutGenerator {
str = String.format( Locale.UK, "%.4f", number).replaceAll("\\.?0*$", "");
}
int counter = 0;
for(int i = str.indexOf(".") - 1; i > 0; i--)
{
counter++;
if(counter == 3)
{
str = str.substring(0, i) + " " + str.substring(i, str.length());
counter = 0;
}
}
return str;
}
}

View File

@ -21,6 +21,9 @@ public class PlaceholderManager {
case "GBP":
formattedString = context.getResources().getString(R.string.currencyPoundPlaceholder, value);
break;
case "JPY":
formattedString = context.getResources().getString(R.string.currencyYenPlaceholder, value);
break;
default:
formattedString = context.getResources().getString(R.string.currencyDollarPlaceholder, value);
break;
@ -42,6 +45,9 @@ public class PlaceholderManager {
case "GBP":
formattedString = context.getResources().getString(R.string.fluctuationPoundPercentagePlaceholder, value, percentage);
break;
case "JPY":
formattedString = context.getResources().getString(R.string.fluctuationYenPercentagePlaceholder, value, percentage);
break;
default:
formattedString = context.getResources().getString(R.string.fluctuationDollarPercentagePlaceholder, value, percentage);
break;
@ -63,6 +69,9 @@ public class PlaceholderManager {
case "GBP":
formattedString = context.getResources().getString(R.string.currencyPoundParenthesisPlaceholder, value);
break;
case "JPY":
formattedString = context.getResources().getString(R.string.currencyYenParenthesisPlaceholder, value);
break;
default:
formattedString = context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, value);
break;
@ -84,6 +93,9 @@ public class PlaceholderManager {
case "GBP":
formattedString = context.getResources().getString(R.string.pricePoundPlaceholder, value);
break;
case "JPY":
formattedString = context.getResources().getString(R.string.priceYenPlaceholder, value);
break;
default:
formattedString = context.getResources().getString(R.string.priceDollarPlaceholder, value);
break;
@ -105,6 +117,9 @@ public class PlaceholderManager {
case "GBP":
formattedString = context.getResources().getString(R.string.volumePoundPlaceholder, value);
break;
case "JPY":
formattedString = context.getResources().getString(R.string.volumeYenPlaceholder, value);
break;
default:
formattedString = context.getResources().getString(R.string.volumeDollarPlaceholder, value);
break;

View File

@ -37,6 +37,7 @@
<item>Dollar (USD)</item>
<item>Euro (EUR)</item>
<item>Pound (GBP)</item>
<item>Yen (JPY)</item>
<!--<item>Bitcoin (BTC)</item>
<item>Ethereum (ETH)</item>-->
</string-array>
@ -45,6 +46,7 @@
<item>USD</item>
<item>EUR</item>
<item>GBP</item>
<item>JPY</item>
<!--<item>BTC</item>
<item>ETH</item>-->
</string-array>
@ -152,6 +154,10 @@
<string name="currencyPoundParenthesisPlaceholder">(%1$s£)</string>
<string name="currencyPoundPlaceholder">%1$s£</string>
<string name="fluctuationPoundPercentagePlaceholder">%1$s£ (%2$s%%)</string>
<!--Yen-->
<string name="currencyYenParenthesisPlaceholder">(%1$s¥)</string>
<string name="currencyYenPlaceholder">%1$s¥</string>
<string name="fluctuationYenPercentagePlaceholder">%1$s¥ (%2$s%%)</string>
<!--DetailsActivity placeholders-->
<string name="timestampPlaceholder">Date\n%1$s</string>
@ -164,6 +170,9 @@
<!--Pound-->
<string name="volumePoundPlaceholder">Volume\n%1$s£</string>
<string name="pricePoundPlaceholder">Price\n%1$s£</string>
<!--Yen-->
<string name="volumeYenPlaceholder">Volume\n%1$s¥</string>
<string name="priceYenPlaceholder">Price\n%1$s¥</string>
<string name="title_activity_main">MainActivity</string>
@ -181,6 +190,9 @@
<!--Pound-->
<string name="market_cap_pound_textview">Total Market Capitalization :\n%1$s£</string>
<string name="volume_pound_market_cap_textview">24h volume :\n%1$s£</string>
<!--Yen-->
<string name="market_cap_yen_textview">Total Market Capitalization :\n%1$s¥</string>
<string name="volume_yen_market_cap_textview">24h volume :\n%1$s¥</string>
<string name="title_activity_scrolling">ScrollingActivity</string>