From 26d3761d2c1174272dcc65f670c9977566776d3a Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Thu, 19 Apr 2018 18:10:36 +0200 Subject: [PATCH] New features - Created PlaceholderManager for a better readability - Added Pound (GBP) as a default currency option --- .../Activities/CurrencyDetailsActivity.java | 20 ++- .../coinfolio/Activities/HomeActivity.java | 1 - .../MarketCapitalization.java | 102 +++++++------ .../HomeActivityFragments/Summary.java | 83 ++++++----- .../HomeActivityFragments/Watchlist.java | 79 +++++----- .../Activities/SettingsActivity.java | 12 -- .../DataManagers/DatabaseManager.java | 1 - .../DataManagers/PreferencesManager.java | 16 ++- .../LayoutManagers/HomeLayoutGenerator.java | 37 ++--- .../nauk/coinfolio/PlaceholderManager.java | 135 ++++++++++++++++++ app/src/main/res/values/strings.xml | 40 ++++-- 11 files changed, 352 insertions(+), 174 deletions(-) create mode 100644 app/src/main/java/com/nauk/coinfolio/PlaceholderManager.java 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 df8577b..57d3ba0 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -43,11 +43,11 @@ import com.github.mikephil.charting.highlight.Highlight; import com.github.mikephil.charting.listener.OnChartValueSelectedListener; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart; -import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDetailsList; import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction; import com.nauk.coinfolio.DataManagers.DatabaseManager; import com.nauk.coinfolio.DataManagers.ExchangeManager.BinanceManager; import com.nauk.coinfolio.DataManagers.PreferencesManager; +import com.nauk.coinfolio.PlaceholderManager; import com.nauk.coinfolio.R; import java.text.DecimalFormat; @@ -84,7 +84,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private BarChart barChart; private PreferencesManager preferencesManager; private BinanceManager binanceManager; - private CurrencyDetailsList currencyDetailsList; private boolean displayLineChart; @@ -142,7 +141,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity { databaseManager = new DatabaseManager(this); preferencesManager = new PreferencesManager(this); - currencyDetailsList = new CurrencyDetailsList(this); displayLineChart = true; @@ -549,9 +547,9 @@ public class CurrencyDetailsActivity extends AppCompatActivity { date = getDate(dataChartList.get(index).getTimestamp() * 1000); } - volumePlaceholder = getResources().getString(R.string.volumeDollarPlaceholder, numberConformer(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY())); - pricePlaceholder = getResources().getString(R.string.priceDollarPlaceholder, numberConformer(e.getY())); - timestampPlaceholder = getResources().getString(R.string.timestampPlaceholder, date); + volumePlaceholder = PlaceholderManager.getVolumeString(numberConformer(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY()), this); + pricePlaceholder = PlaceholderManager.getPriceString(numberConformer(e.getY()), this); + timestampPlaceholder = PlaceholderManager.getTimestampString(date, this); ((TextView) findViewById(R.id.volumeHightlight)).setText(volumePlaceholder); findViewById(R.id.volumeHightlight).setVisibility(View.VISIBLE); @@ -726,8 +724,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity { updateFluctuation(start, end); - ((TextView) findViewById(R.id.txtViewPriceStart)).setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(start))); - ((TextView) findViewById(R.id.txtViewPriceNow)).setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(end))); + ((TextView) findViewById(R.id.txtViewPriceStart)).setText(PlaceholderManager.getValueString(numberConformer(start), this)); + ((TextView) findViewById(R.id.txtViewPriceNow)).setText(PlaceholderManager.getValueString(numberConformer(end), this)); for(int i = 1; i < dataChartList.size(); i++) { @@ -744,9 +742,9 @@ public class CurrencyDetailsActivity extends AppCompatActivity { } } - ((TextView) findViewById(R.id.totalVolume)).setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(totalVolume))); - ((TextView) findViewById(R.id.highestPrice)).setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(highestPrice))); - ((TextView) findViewById(R.id.lowestPrice)).setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(lowestPrice))); + ((TextView) findViewById(R.id.totalVolume)).setText(PlaceholderManager.getValueString(numberConformer(totalVolume), this)); + ((TextView) findViewById(R.id.highestPrice)).setText(PlaceholderManager.getValueString(numberConformer(highestPrice), this)); + ((TextView) findViewById(R.id.lowestPrice)).setText(PlaceholderManager.getValueString(numberConformer(lowestPrice), this)); } private void updateFluctuation(float start, float end) 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 cb69a10..a4868a5 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -73,7 +73,6 @@ import java.util.Locale; public class HomeActivity extends AppCompatActivity { private BottomNavigationView bottomNavigationView; - private ViewPager viewPager; 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 14b104d..f8669e6 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 @@ -50,6 +50,7 @@ public class MarketCapitalization extends Fragment { private HashMap dominantCurrenciesColors; private SwipeRefreshLayout refreshLayout; private long lastTimestamp; + private String defaultCurrency; private View view; @@ -68,12 +69,13 @@ public class MarketCapitalization extends Fragment { new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { - updateMarketCap(); + updateMarketCap(false); } } ); + defaultCurrency = preferencesManager.getDefaultCurrency(); lastTimestamp = 0; ImageButton settingsButton = view.findViewById(R.id.settings_button); @@ -86,7 +88,7 @@ public class MarketCapitalization extends Fragment { } }); - updateMarketCap(); + updateMarketCap(true); return view; } @@ -96,7 +98,16 @@ public class MarketCapitalization extends Fragment { { super.onResume(); - updateMarketCap(); + if(!defaultCurrency.equals(preferencesManager.getDefaultCurrency())) + { + defaultCurrency = preferencesManager.getDefaultCurrency(); + updateMarketCap(true); + } + else + { + updateMarketCap(false); + } + } private void setupDominantCurrenciesColors() @@ -120,9 +131,9 @@ public class MarketCapitalization extends Fragment { dominantCurrenciesColors.put("ETC", -10448784); } - private void updateMarketCap() + private void updateMarketCap(boolean mustUpdate) { - if(System.currentTimeMillis() / 1000 - lastTimestamp > 60) + if(System.currentTimeMillis() / 1000 - lastTimestamp > 60 || mustUpdate) { if(!refreshLayout.isRefreshing()) { @@ -157,6 +168,48 @@ public class MarketCapitalization extends Fragment { } } + private void refreshDisplayedData() + { + setupTextViewMarketCap(); + + view.findViewById(R.id.progressBarMarketCap).setVisibility(View.GONE); + view.findViewById(R.id.layoutProgressMarketCap).setVisibility(View.VISIBLE); + + List entries = new ArrayList<>(); + + ArrayList colors = new ArrayList<>(); + + float otherCurrenciesDominance = 0; + + for(Iterator i = marketCapManager.getDominance().keySet().iterator(); i.hasNext(); ) + { + String key = (String) i.next(); + 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); + set.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); + set.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); + + PieData data = new PieData(set); + data.setValueTextSize(10); + data.setValueFormatter(new PercentFormatter()); + + setupPieChart(data); + + if(refreshLayout.isRefreshing()) + { + refreshLayout.setRefreshing(false); + } + } + @SuppressLint("ClickableViewAccessibility") private void countCompletedMarketCapRequest() { @@ -164,44 +217,7 @@ public class MarketCapitalization extends Fragment { if(marketCapCounter == 2) { - setupTextViewMarketCap(); - - view.findViewById(R.id.progressBarMarketCap).setVisibility(View.GONE); - view.findViewById(R.id.layoutProgressMarketCap).setVisibility(View.VISIBLE); - - List entries = new ArrayList<>(); - - ArrayList colors = new ArrayList<>(); - - float otherCurrenciesDominance = 0; - - for(Iterator i = marketCapManager.getDominance().keySet().iterator(); i.hasNext(); ) - { - String key = (String) i.next(); - 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); - set.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); - set.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); - - PieData data = new PieData(set); - data.setValueTextSize(10); - data.setValueFormatter(new PercentFormatter()); - - setupPieChart(data); - - if(refreshLayout.isRefreshing()) - { - refreshLayout.setRefreshing(false); - } + refreshDisplayedData(); } } 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 160151a..042ac10 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 @@ -34,13 +34,20 @@ import com.nauk.coinfolio.DataManagers.BalanceManager; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.PreferencesManager; import com.nauk.coinfolio.LayoutManagers.HomeLayoutGenerator; +import com.nauk.coinfolio.PlaceholderManager; 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.List; +import java.util.Locale; + +import static java.lang.Math.abs; /** * Created by Tiji on 13/04/2018. @@ -54,6 +61,7 @@ public class Summary extends Fragment { private HomeLayoutGenerator layoutGenerator; private SwipeRefreshLayout refreshLayout; private Dialog loadingDialog; + private String defaultCurrency; private TextView toolbarSubtitle; private CollapsingToolbarLayout toolbarLayout; @@ -85,6 +93,8 @@ public class Summary extends Fragment { totalFluctuation = 0; lastTimestamp = 0; + defaultCurrency = preferencesManager.getDefaultCurrency(); + handler = new Handler(); updateRunnable = new Runnable() { @Override @@ -180,7 +190,16 @@ public class Summary extends Fragment { displayBalance(preferencesManager.isBalanceHidden()); - updateAll(preferencesManager.mustUpdateSummary()); + if(!defaultCurrency.equals(preferencesManager.getDefaultCurrency())) + { + defaultCurrency = preferencesManager.getDefaultCurrency(); + + updateAll(true); + } + else + { + updateAll(preferencesManager.mustUpdateSummary()); + } } private void updateAll(boolean mustUpdate) @@ -240,13 +259,14 @@ public class Summary extends Fragment { Runnable newRunnable = new Runnable() { @Override public void run() { - for(int i = 0; i < balanceManager.getTotalBalance().size(); i++) + if (balanceManager.getTotalBalance() != null) { - final Currency currency = balanceManager.getTotalBalance().get(i); + for (int i = 0; i < balanceManager.getTotalBalance().size(); i++) { + final Currency currency = balanceManager.getTotalBalance().get(i); - if(!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001)) - { - currencyView.add(layoutGenerator.getInfoLayout(currency, totalValue, preferencesManager.isBalanceHidden())); + if (!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001)) { + currencyView.add(layoutGenerator.getInfoLayout(currency, totalValue, preferencesManager.isBalanceHidden())); + } } } @@ -353,7 +373,7 @@ public class Summary extends Fragment { if(preferencesManager.isBalanceHidden()) { - toolbarLayout.setTitle(getResources().getString(R.string.currencyPercentagePlaceholder, String.format("%.2f", totalFluctuationPercentage))); + toolbarLayout.setTitle(PlaceholderManager.getPercentageString(numberConformer(totalFluctuationPercentage), getActivity())); toolbarSubtitle.setVisibility(View.GONE); if(totalFluctuation > 0) @@ -369,15 +389,7 @@ public class Summary extends Fragment { } else { - switch (preferencesManager.getDefaultCurrency()) - { - case "EUR": - toolbarLayout.setTitle(getResources().getString(R.string.currencyEurosPlaceholder, String.format("%.2f", totalValue))); - break; - default: - toolbarLayout.setTitle(getResources().getString(R.string.currencyDollarPlaceholder, String.format("%.2f", totalValue))); - break; - } + toolbarLayout.setTitle(PlaceholderManager.getValueString(numberConformer(totalValue), getActivity())); toolbarLayout.setCollapsedTitleTextColor(Color.WHITE); toolbarLayout.setExpandedTitleColor(Color.WHITE); @@ -394,33 +406,32 @@ public class Summary extends Fragment { if(totalFluctuation == 0) { - switch (preferencesManager.getDefaultCurrency()) - { - case "EUR": - toolbarSubtitle.setText(getResources().getString(R.string.currencyEurosPlaceholder, "0.00")); - break; - default: - toolbarSubtitle.setText(getResources().getString(R.string.currencyDollarPlaceholder, "0.00")); - break; - } + toolbarSubtitle.setText(PlaceholderManager.getValueString(numberConformer(totalValue), getActivity())); toolbarSubtitle.setTextColor(-1275068417); - } else { - switch (preferencesManager.getDefaultCurrency()) - { - case "EUR": - toolbarSubtitle.setText(String.format("%.2f", totalFluctuation) + "€ (" + String.format("%.2f", totalFluctuationPercentage) + "%)"); - break; - default: - toolbarSubtitle.setText("US$" + String.format("%.2f", totalFluctuation) + " (" + String.format("%.2f", totalFluctuationPercentage) + "%)"); - break; - } + toolbarSubtitle.setText(PlaceholderManager.getValuePercentageString(numberConformer(totalFluctuation), numberConformer(totalFluctuationPercentage), getActivity())); } } } + 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*$", ""); + } + + return str; + } + private class UiHeavyLoadCalculator extends AsyncTask { @@ -622,7 +633,7 @@ public class Summary extends Fragment { { for(int i = 0; i < balanceManager.getTotalBalance().size(); i++) { - balance.get(i).updatePrice(getActivity(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { + balance.get(i).updatePrice(getActivity(), defaultCurrency, new Currency.CurrencyCallBack() { @Override public void onSuccess(Currency currency) { countCoins(true, false); 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 66755f7..e23c03e 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 @@ -70,7 +70,7 @@ public class Watchlist extends Fragment { private SwipeRefreshLayout refreshLayout; private long lastTimestamp; private PreferencesManager preferencesManager; - private Toolbar toolbar; + private String defaultCurrency; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) @@ -82,6 +82,7 @@ public class Watchlist extends Fragment { preferencesManager = new PreferencesManager(getContext()); lastTimestamp = 0; + defaultCurrency = preferencesManager.getDefaultCurrency(); watchlistManager = new WatchlistManager(getContext()); @@ -93,7 +94,6 @@ public class Watchlist extends Fragment { updateWatchlist(false); } }); - toolbar = view.findViewById(R.id.toolbar); Button addWatchlistButton = view.findViewById(R.id.buttonAddWatchlist); addWatchlistButton.setOnClickListener(new View.OnClickListener() { @@ -189,7 +189,15 @@ public class Watchlist extends Fragment { { super.onResume(); - updateWatchlist(preferencesManager.mustUpdateWatchlist()); + if(!defaultCurrency.equals(preferencesManager.getDefaultCurrency())) + { + defaultCurrency = preferencesManager.getDefaultCurrency(); + updateWatchlist(true); + } + else + { + updateWatchlist(preferencesManager.mustUpdateWatchlist()); + } } private void updateWatchlist(boolean mustUpdate) @@ -222,42 +230,47 @@ public class Watchlist extends Fragment { } } + private void generateCards() + { + final List watchlistViews = new ArrayList(); + + ((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).removeAllViews(); + + Runnable newRunnable = new Runnable() { + @Override + public void run() { + for(final Currency currency : watchlistManager.getWatchlist()) + { + watchlistViews.add(getCurrencyCardFor(currency)); + } + + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + for(int i = 0; i < watchlistViews.size(); i++) + { + ((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).addView(watchlistViews.get(i), 0); + } + } + }); + } + }; + + newRunnable.run(); + + if(refreshLayout.isRefreshing()) + { + refreshLayout.setRefreshing(false); + } + } + private void countWatchlist() { watchlistCounter++; if(watchlistCounter >= watchlistManager.getWatchlist().size()) { - final List watchlistViews = new ArrayList(); - - ((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).removeAllViews(); - - Runnable newRunnable = new Runnable() { - @Override - public void run() { - for(final Currency currency : watchlistManager.getWatchlist()) - { - watchlistViews.add(getCurrencyCardFor(currency)); - } - - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - for(int i = 0; i < watchlistViews.size(); i++) - { - ((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).addView(watchlistViews.get(i), 0); - } - } - }); - } - }; - - newRunnable.run(); - - if(refreshLayout.isRefreshing()) - { - refreshLayout.setRefreshing(false); - } + generateCards(); } } diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java index 9bdc14d..7f69200 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java @@ -233,18 +233,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity { }); bindPreferenceSummaryToValue(findPreference("default_currency")); - findPreference("default_currency").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object o) { - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext()); - SharedPreferences.Editor editor = preferences.edit(); - - editor.putBoolean("refresh_default_currency", true); - editor.apply(); - - return false; - } - }); } @Override diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java index 32cb349..f8cb330 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java @@ -128,7 +128,6 @@ public class DatabaseManager extends SQLiteOpenHelper{ values.put(KEY_CURRENCY_BALANCE, balance); values.put(KEY_CURRENCY_DATE, date.getTime()); values.put(KEY_CURRENCY_PURCHASED_PRICE, purchasedPrice); - //values.put(KEY_CURRENCY_PURCHASED_PRICE, something); db.insert(TABLE_MANUAL_CURRENCIES, null, values); db.close(); diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java index 74f4d60..899d55f 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java @@ -9,6 +9,7 @@ import android.preference.PreferenceManager; public class PreferencesManager { + private static int fragmentUpdated = 0; private static final String currencyListFile = "CustomCurrencies"; private static final String preferencesFile = "Preferences"; private SharedPreferences settingPreferences; @@ -34,7 +35,20 @@ public class PreferencesManager { return preferencesList.getBoolean("DetailOption", true); } - public void disableRefreshDefaultCurrency() + public boolean mustRefreshDefaultCurrency() + { + fragmentUpdated++; + + if(fragmentUpdated == 3) + { + disableRefreshDefaultCurrency(); + fragmentUpdated = 0; + } + + return settingPreferences.getBoolean("refresh_default_currency", false); + } + + private void disableRefreshDefaultCurrency() { SharedPreferences.Editor editor = settingPreferences.edit(); editor.putBoolean("refresh_default_currency", false); 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 a0dba8f..c1225a7 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java @@ -26,6 +26,7 @@ import com.nauk.coinfolio.Activities.CurrencyDetailsActivity; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart; import com.nauk.coinfolio.DataManagers.PreferencesManager; +import com.nauk.coinfolio.PlaceholderManager; import com.nauk.coinfolio.R; import java.text.DecimalFormat; @@ -64,7 +65,6 @@ public class HomeLayoutGenerator { currency.updateHistoryMinutes(context, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { @Override public void onSuccess(Currency currency) { - //setupLineChart(view, currency); ChartLoader chartLoader = new ChartLoader(view, currency); chartLoader.execute(); } @@ -206,39 +206,24 @@ public class HomeLayoutGenerator { double value = currency.getValue() * currency.getBalance(); double percentage = value / totalValue * 100; DecimalFormat df = new DecimalFormat(".##"); - PreferencesManager preferencesManager = new PreferencesManager(context); - switch (preferencesManager.getDefaultCurrency()) - { - case "EUR": - ((TextView) view.findViewById(R.id.currencyValueOwnedTextView)) - .setText(context.getResources().getString(R.string.currencyEurosParenthesisPlaceholder, numberConformer(currency.getValue() * currency.getBalance()))); - ((TextView) view.findViewById(R.id.currencyValueTextView)) - .setText(context.getResources().getString(R.string.currencyEurosPlaceholder, numberConformer(currency.getValue()))); - ((TextView) view.findViewById(R.id.currencyFluctuationTextView)) - .setText(context.getResources().getString(R.string.currencyEurosParenthesisPlaceholder, numberConformer(currency.getDayFluctuation()))); - break; - default: - ((TextView) view.findViewById(R.id.currencyValueOwnedTextView)) - .setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getValue() * currency.getBalance()))); - ((TextView) view.findViewById(R.id.currencyValueTextView)) - .setText(context.getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(currency.getValue()))); - ((TextView) view.findViewById(R.id.currencyFluctuationTextView)) - .setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getDayFluctuation()))); - - break; - } + ((TextView) view.findViewById(R.id.currencyValueOwnedTextView)) + .setText(PlaceholderManager.getValueParenthesisString(numberConformer(currency.getValue() * currency.getBalance()), context)); + ((TextView) view.findViewById(R.id.currencyValueTextView)) + .setText(PlaceholderManager.getValueString(numberConformer(currency.getValue()), context)); + ((TextView) view.findViewById(R.id.currencyFluctuationTextView)) + .setText(PlaceholderManager.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), context)); ((ImageView) view.findViewById(R.id.currencyIcon)) .setImageBitmap(currency.getIcon()); ((TextView) view.findViewById(R.id.currencyNameTextView)) .setText(currency.getName()); ((TextView) view.findViewById(R.id.currencySymbolTextView)) - .setText(context.getResources().getString(R.string.currencySymbolPlaceholder, currency.getSymbol())); + .setText(PlaceholderManager.getSymbolString(currency.getSymbol(), context)); ((TextView) view.findViewById(R.id.currencyOwnedTextView)) - .setText(context.getResources().getString(R.string.currencyBalancePlaceholder, numberConformer(currency.getBalance()), currency.getSymbol())); + .setText(PlaceholderManager.getBalanceString(numberConformer(currency.getBalance()), currency.getSymbol(), context)); ((TextView) view.findViewById(R.id.currencyFluctuationPercentageTextView)) - .setText(context.getResources().getString(R.string.currencyPercentagePlaceholder, numberConformer(currency.getDayFluctuationPercentage()))); + .setText(PlaceholderManager.getPercentageString(numberConformer(currency.getDayFluctuationPercentage()), context)); Drawable arrowDrawable = ((ImageView) view.findViewById(R.id.detailsArrow)).getDrawable(); arrowDrawable.mutate(); @@ -251,7 +236,7 @@ public class HomeLayoutGenerator { progressBarDrawable.invalidateSelf(); ((ProgressBar) view.findViewById(R.id.currencyPortfolioDominance)).setProgress((int) Math.round(percentage)); - ((TextView) view.findViewById(R.id.percentageOwnedTextView)).setText(context.getResources().getString(R.string.currencyPercentagePlaceholder, df.format(percentage))); + ((TextView) view.findViewById(R.id.percentageOwnedTextView)).setText(PlaceholderManager.getPercentageString(numberConformer(percentage), context)); if(isBalanceHidden) { diff --git a/app/src/main/java/com/nauk/coinfolio/PlaceholderManager.java b/app/src/main/java/com/nauk/coinfolio/PlaceholderManager.java new file mode 100644 index 0000000..b4b2ddc --- /dev/null +++ b/app/src/main/java/com/nauk/coinfolio/PlaceholderManager.java @@ -0,0 +1,135 @@ +package com.nauk.coinfolio; + +import com.nauk.coinfolio.DataManagers.PreferencesManager; + +/** + * Created by Tiji on 19/04/2018. + */ + +public class PlaceholderManager { + + public static String getValueString(String value, android.content.Context context) + { + PreferencesManager preferencesManager = new PreferencesManager(context); + String formattedString = null; + + switch (preferencesManager.getDefaultCurrency()) + { + case "EUR": + formattedString = context.getResources().getString(R.string.currencyEurosPlaceholder, value); + break; + case "GBP": + formattedString = context.getResources().getString(R.string.currencyPoundPlaceholder, value); + break; + default: + formattedString = context.getResources().getString(R.string.currencyDollarPlaceholder, value); + break; + } + + return formattedString; + } + + public static String getValuePercentageString(String value, String percentage, android.content.Context context) + { + PreferencesManager preferencesManager = new PreferencesManager(context); + String formattedString = null; + + switch (preferencesManager.getDefaultCurrency()) + { + case "EUR": + formattedString = context.getResources().getString(R.string.fluctuationEurosPercentagePlaceholder, value, percentage); + break; + case "GBP": + formattedString = context.getResources().getString(R.string.fluctuationPoundPercentagePlaceholder, value, percentage); + break; + default: + formattedString = context.getResources().getString(R.string.fluctuationDollarPercentagePlaceholder, value, percentage); + break; + } + + return formattedString; + } + + public static String getValueParenthesisString(String value, android.content.Context context) + { + PreferencesManager preferencesManager = new PreferencesManager(context); + String formattedString = null; + + switch (preferencesManager.getDefaultCurrency()) + { + case "EUR": + formattedString = context.getResources().getString(R.string.currencyEurosParenthesisPlaceholder, value); + break; + case "GBP": + formattedString = context.getResources().getString(R.string.currencyPoundParenthesisPlaceholder, value); + break; + default: + formattedString = context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, value); + break; + } + + return formattedString; + } + + public static String getPriceString(String value, android.content.Context context) + { + PreferencesManager preferencesManager = new PreferencesManager(context); + String formattedString = null; + + switch (preferencesManager.getDefaultCurrency()) + { + case "EUR": + formattedString = context.getResources().getString(R.string.priceEurosPlaceholder, value); + break; + case "GBP": + formattedString = context.getResources().getString(R.string.pricePoundPlaceholder, value); + break; + default: + formattedString = context.getResources().getString(R.string.priceDollarPlaceholder, value); + break; + } + + return formattedString; + } + + public static String getVolumeString(String value, android.content.Context context) + { + PreferencesManager preferencesManager = new PreferencesManager(context); + String formattedString = null; + + switch (preferencesManager.getDefaultCurrency()) + { + case "EUR": + formattedString = context.getResources().getString(R.string.volumeEurosPlaceholder, value); + break; + case "GBP": + formattedString = context.getResources().getString(R.string.volumePoundPlaceholder, value); + break; + default: + formattedString = context.getResources().getString(R.string.volumeDollarPlaceholder, value); + break; + } + + return formattedString; + } + + public static String getSymbolString(String symbol, android.content.Context context) + { + return context.getResources().getString(R.string.currencySymbolPlaceholder, symbol); + } + + public static String getBalanceString(String balance, String symbol, android.content.Context context) + { + return context.getResources().getString(R.string.currencyBalancePlaceholder, balance, symbol); + } + + public static String getPercentageString(String value, android.content.Context context) + { + return context.getResources().getString(R.string.currencyPercentagePlaceholder, value); + } + + public static String getTimestampString(String date, android.content.Context context) + { + return context.getResources().getString(R.string.timestampPlaceholder, date); + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4ab2e77..d1c48ab 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -34,17 +34,19 @@ Default currency - USD - EUR - BTC - ETH + Dollar (USD) + Euro (EUR) + Pound (GBP) + USD EUR - BTC - ETH + GBP + @@ -137,20 +139,31 @@ (%1$s) %1$s%2$s + %1$s%% + (US$%1$s) US$%1$s + US$%1$s (%2$s%%) + (%1$s€) %1$s€ - %1$s%% - US$%1$s (%2$s%) - %1$s€ (%2$s%) + %1$s€ (%2$s%%) + + (%1$s£) + %1$s£ + %1$s£ (%2$s%%) + Date\n%1$s + Volume\nUS$%1$s Price\nUS$%1$s + Volume\n%1$s€ Price\n%1$s€ - Date\n%1$s + + Volume\n%1$s£ + Price\n%1$s£ MainActivity @@ -158,10 +171,17 @@ Verify your fingerprint to continue + + Total Market Capitalization :\nUS$%1$s 24h volume :\nUS$%1$s + Total Market Capitalization :\n%1$s€ 24h volume :\n%1$s€ + + Total Market Capitalization :\n%1$s£ + 24h volume :\n%1$s£ + ScrollingActivity