diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java index 2675a74..aa44762 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -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); diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/MarketCapitalization.java b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/MarketCapitalization.java index f8669e6..c49f594 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/MarketCapitalization.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/MarketCapitalization.java @@ -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())); } } diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/Summary.java index 042ac10..43dc4c6 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/Summary.java @@ -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; } diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/Watchlist.java b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/Watchlist.java index e23c03e..1edb555 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/Watchlist.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivityFragments/Watchlist.java @@ -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 dataChartList = currency.getHistoryMinutes(); ArrayList 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; diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/MarketCapManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/MarketCapManager.java index f7cf4e9..188f053 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/MarketCapManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/MarketCapManager.java @@ -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() { @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 getDominance() + public HashMap getDominance(String toSymbol) { HashMap 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(']')); diff --git a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java index c1225a7..c900aeb 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java @@ -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; } } diff --git a/app/src/main/java/com/nauk/coinfolio/PlaceholderManager.java b/app/src/main/java/com/nauk/coinfolio/PlaceholderManager.java index b4b2ddc..538baa6 100644 --- a/app/src/main/java/com/nauk/coinfolio/PlaceholderManager.java +++ b/app/src/main/java/com/nauk/coinfolio/PlaceholderManager.java @@ -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; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d1c48ab..9d0c88d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -37,6 +37,7 @@ Dollar (USD) Euro (EUR) Pound (GBP) + Yen (JPY) @@ -45,6 +46,7 @@ USD EUR GBP + JPY @@ -152,6 +154,10 @@ (%1$s£) %1$s£ %1$s£ (%2$s%%) + + (%1$s¥) + %1$s¥ + %1$s¥ (%2$s%%) Date\n%1$s @@ -164,6 +170,9 @@ Volume\n%1$s£ Price\n%1$s£ + + Volume\n%1$s¥ + Price\n%1$s¥ MainActivity @@ -181,6 +190,9 @@ Total Market Capitalization :\n%1$s£ 24h volume :\n%1$s£ + + Total Market Capitalization :\n%1$s¥ + 24h volume :\n%1$s¥ ScrollingActivity