diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java index bbce56b..74993b2 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -57,9 +57,15 @@ import com.nauk.coinfolio.R; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.text.NumberFormat; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Locale; +import java.util.Random; //Use WilliamChart for charts https://github.com/diogobernardino/WilliamChart @@ -94,6 +100,8 @@ public class HomeActivity extends AppCompatActivity { private Runnable updateRunnable; private ViewFlipper viewFlipper; + private HashMap dominantCurrenciesColors; + private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() { @@ -246,6 +254,29 @@ public class HomeActivity extends AppCompatActivity { lastTimestamp = 0; setupNavBar(savedInstanceState); + + setupDominantCurrenciesColors(); + } + + private void setupDominantCurrenciesColors() + { + dominantCurrenciesColors = new HashMap<>(); + + dominantCurrenciesColors.put("BTC", -489456); + dominantCurrenciesColors.put("ETH", -13619152); + dominantCurrenciesColors.put("XRP", -16744256); + dominantCurrenciesColors.put("BCH", -1011696); + dominantCurrenciesColors.put("LTC", -4671304); + dominantCurrenciesColors.put("ADA", -16773080); + dominantCurrenciesColors.put("NEO", -9390048); + dominantCurrenciesColors.put("XLM", -11509656); + dominantCurrenciesColors.put("XMR", -499712); + dominantCurrenciesColors.put("EOS", -1513240); + dominantCurrenciesColors.put("IOT", -1513240); + dominantCurrenciesColors.put("DASH", -15175496); + dominantCurrenciesColors.put("XEM", -7829368); + dominantCurrenciesColors.put("TRX", -7829360); + dominantCurrenciesColors.put("ETC", -10448784); } private void setupNavBar(Bundle savedInstanceState) @@ -269,6 +300,7 @@ public class HomeActivity extends AppCompatActivity { nav.changeCurrentItem(-1); + findViewById(R.id.toolbar_layout).setFocusable(true); findViewById(R.id.nestedScrollViewLayout).setNestedScrollingEnabled(true); ((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(true, true); @@ -284,6 +316,7 @@ public class HomeActivity extends AppCompatActivity { //0 : Unknown //1 : Market cap + findViewById(R.id.toolbar_layout).setFocusable(false); ((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(false, true); findViewById(R.id.nestedScrollViewLayout).setNestedScrollingEnabled(false); @@ -421,8 +454,6 @@ public class HomeActivity extends AppCompatActivity { private void getBitmapFromURL(String src, IconCallBack callBack) { Bitmap result; - Log.d("coinfolio", "Downloading bitmap"); - try { java.net.URL url = new java.net.URL(src); HttpURLConnection connection = (HttpURLConnection) url @@ -523,10 +554,15 @@ public class HomeActivity extends AppCompatActivity { if(marketCapCounter == 2) { + setupTextViewMarketCap(); + findViewById(R.id.progressBarMarketCap).setVisibility(View.GONE); + findViewById(R.id.layoutProgressMarketCap).setVisibility(View.VISIBLE); List entries = new ArrayList<>(); + ArrayList colors = new ArrayList<>(); + PieChart pieChart = findViewById(R.id.marketCapPieChart); float otherCurrenciesDominance = 0; @@ -534,14 +570,16 @@ public class HomeActivity extends AppCompatActivity { for(Iterator i = marketCapManager.getDominance().keySet().iterator(); i.hasNext(); ) { String key = (String) i.next(); - Log.d(getResources().getString(R.string.debug), "Sym : " + key + " " + marketCapManager.getDominance().get(key)); entries.add(new PieEntry(marketCapManager.getDominance().get(key), key)); otherCurrenciesDominance += marketCapManager.getDominance().get(key); + colors.add(dominantCurrenciesColors.get(key)); } - entries.add(new PieEntry(100-otherCurrenciesDominance, "Others")); + colors.add(-12369084); PieDataSet set = new PieDataSet(entries, "Market Cap Dominance"); + set.setColors(colors); + set.setSliceSpace(1); PieData data = new PieData(set); pieChart.setData(data); @@ -550,21 +588,28 @@ public class HomeActivity extends AppCompatActivity { pieChart.setTouchEnabled(false); pieChart.getDescription().setEnabled(false); + pieChart.getLegend().setEnabled(false); pieChart.setCenterText(generateCenterSpannableText()); - pieChart.setVisibility(View.VISIBLE); pieChart.invalidate(); // refresh } } + private void setupTextViewMarketCap() + { + DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.UK); + DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols(); + + symbols.setGroupingSeparator(' '); + formatter.setDecimalFormatSymbols(symbols); + + ((TextView) findViewById(R.id.marketCapTextView)).setText(getResources().getString(R.string.market_cap_textview, formatter.format(marketCapManager.getMarketCap()))); + + ((TextView) findViewById(R.id.dayVolumeTotalMarketCap)).setText(getResources().getString(R.string.volume_market_cap_textview, formatter.format(marketCapManager.getDayVolume()))); + } + private SpannableString generateCenterSpannableText() { - SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda"); - s.setSpan(new RelativeSizeSpan(1.7f), 0, 14, 0); - s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0); - s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0); - s.setSpan(new RelativeSizeSpan(.8f), 14, s.length() - 15, 0); - s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0); - s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0); + SpannableString s = new SpannableString("Market Capitalization Dominance"); return s; } @@ -728,6 +773,7 @@ public class HomeActivity extends AppCompatActivity { Palette.Builder builder = Palette.from(localCurrency.getIcon()); localCurrency.setChartColor(builder.generate().getDominantColor(0)); + } else { diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java index 94655ab..be4cf06 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java @@ -239,23 +239,26 @@ public class BalanceManager { private void mergeBalanceTotal(List balance) { - for(int i = 0; i < balance.size(); i++) + if(balance != null) { - boolean isIn = false; - - for(int j = 0; j < totalBalance.size(); j++) + for(int i = 0; i < balance.size(); i++) { - if(balance.get(i).getSymbol().equals(totalBalance.get(j).getSymbol())) + boolean isIn = false; + + for(int j = 0; j < totalBalance.size(); j++) { - totalBalance.get(j).setBalance(totalBalance.get(j).getBalance() + balance.get(i).getBalance()); + if(balance.get(i).getSymbol().equals(totalBalance.get(j).getSymbol())) + { + totalBalance.get(j).setBalance(totalBalance.get(j).getBalance() + balance.get(i).getBalance()); - isIn = true; + isIn = true; + } } - } - if(!isIn) - { - totalBalance.add(balance.get(i)); + if(!isIn) + { + totalBalance.add(balance.get(i)); + } } } } 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 80ea578..9cf3b5e 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/MarketCapManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/MarketCapManager.java @@ -28,6 +28,7 @@ public class MarketCapManager { private RequestQueue requestQueue; private String topRequestResult[]; private long marketCap; + private long dayVolume; public MarketCapManager(android.content.Context context) { @@ -88,6 +89,8 @@ public class MarketCapManager { JSONObject jsonObject = new JSONObject(response); marketCap = new BigDecimal(jsonObject.getString("total_market_cap_usd")).longValue(); + + dayVolume = new BigDecimal(jsonObject.getString("total_24h_volume_usd")).longValue(); } catch (JSONException e) { e.printStackTrace(); } @@ -111,6 +114,11 @@ public class MarketCapManager { return dominance; } + public long getDayVolume() + { + return dayVolume; + } + private void processTopCurrencies(String response) { response = response.substring(response.indexOf('[')+1, response.lastIndexOf(']')); @@ -124,7 +132,7 @@ public class MarketCapManager { JSONObject jsonObject = new JSONObject(topRequestResult[i]); - Log.d("coinfolio", "Symbol : " + jsonObject.getString("symbol") + " " + jsonObject.getString("rank")); + //Log.d("coinfolio", "Symbol : " + jsonObject.getString("symbol") + " " + jsonObject.getString("rank")); } catch (JSONException e) { e.printStackTrace(); @@ -132,6 +140,11 @@ public class MarketCapManager { } } + public long getMarketCap() + { + return marketCap; + } + public interface VolleyCallBack { void onSuccess(); diff --git a/app/src/main/res/layout/content_currency_summary.xml b/app/src/main/res/layout/content_currency_summary.xml index aba6394..c689608 100644 --- a/app/src/main/res/layout/content_currency_summary.xml +++ b/app/src/main/res/layout/content_currency_summary.xml @@ -66,7 +66,8 @@ + android:layout_height="match_parent" + android:orientation="vertical"> + + - + android:layout_marginLeft="10dp" + android:layout_marginTop="10dp" + android:layout_marginRight="10dp" + android:layout_marginBottom="5dp" + android:textSize="20dp" + android:gravity="center_horizontal"/> + + + + android:layout_height="350dp"/> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 949b99d..43484cc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -149,4 +149,8 @@ Cancel Verify your fingerprint to continue + + Total Market Capitalization :\nUS$%1$s + 24h volume :\nUS$%1$s +