From daf2f0ddc1e1257f6df27b6693189c69b31c93e2 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Fri, 6 Apr 2018 09:44:23 +0200 Subject: [PATCH] Add currency dominance bar --- .../Activities/CurrencyDetailsActivity.java | 30 +++++----- .../coinfolio/Activities/HomeActivity.java | 60 +++++-------------- .../Activities/SettingsActivity.java | 27 ++++++--- .../DataManagers/PreferencesManager.java | 5 ++ .../LayoutManagers/HomeLayoutGenerator.java | 22 +++++-- app/src/main/res/layout/cardview_currency.xml | 9 ++- .../main/res/layout/cardview_watchlist.xml | 2 +- app/src/main/res/menu/navigation_home.xml | 2 +- app/src/main/res/values/strings.xml | 5 +- app/src/main/res/xml/pref_general.xml | 15 +++-- app/src/main/res/xml/pref_headers.xml | 7 +++ 11 files changed, 96 insertions(+), 88 deletions(-) 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 9d01100..17ad8c4 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -130,13 +130,13 @@ public class CurrencyDetailsActivity extends AppCompatActivity { ((BottomNavigationView) findViewById(R.id.navigation_details)).getMenu().getItem(1).setEnabled(false); + setupActionBar(); + drawTransactionList(); initializeButtons(); - createCharts(DAY, 1); - - setupActionBar(); + updateChartTab(DAY, 1); BottomNavigationView navigation = findViewById(R.id.navigation_details); navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); @@ -218,13 +218,13 @@ public class CurrencyDetailsActivity extends AppCompatActivity { switch (interval) { case "1h": - createCharts(HOUR, 1); + updateChartTab(HOUR, 1); break; case "3h": - createCharts(HOUR, 3); + updateChartTab(HOUR, 3); break; case "1d": - createCharts(DAY, 1); + updateChartTab(DAY, 1); break; case "3d": currency.updateHistoryHours(this, new Currency.CurrencyCallBack() { @@ -233,7 +233,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - createCharts(CurrencyDetailsActivity.DAY, 3); + updateChartTab(CurrencyDetailsActivity.DAY, 3); } }); } @@ -246,7 +246,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - createCharts(CurrencyDetailsActivity.WEEK, 11); + updateChartTab(CurrencyDetailsActivity.WEEK, 11); } }); } @@ -259,7 +259,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - createCharts(CurrencyDetailsActivity.MONTH, 1); + updateChartTab(CurrencyDetailsActivity.MONTH, 1); } }); } @@ -272,7 +272,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - createCharts(CurrencyDetailsActivity.MONTH, 3); + updateChartTab(CurrencyDetailsActivity.MONTH, 3); } }); } @@ -285,7 +285,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - createCharts(CurrencyDetailsActivity.MONTH, 6); + updateChartTab(CurrencyDetailsActivity.MONTH, 6); } }); } @@ -298,7 +298,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - createCharts(CurrencyDetailsActivity.YEAR, 1); + updateChartTab(CurrencyDetailsActivity.YEAR, 1); } }); } @@ -307,7 +307,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { } } - private void createCharts(int timeUnit, int amount) + private void updateChartTab(int timeUnit, int amount) { updateChartsData(timeUnit, amount); drawPriceChart(); @@ -509,7 +509,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { for(int i = 0, j = 0; i < dataChartList.size(); i += offset, j++) { - values.add(new BarEntry(j, (float) dataChartList.get(i).getVolumeTo())); + values.add(new BarEntry(j, (float) dataChartList.get(j).getVolumeTo())); } dataSet = new BarDataSet(values, "Volume"); @@ -614,7 +614,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private void updateFluctuation(float start, float end) { float fluctuation = end - start; - float percentageFluctuation = (float) (fluctuation / start * 100); + float percentageFluctuation = (fluctuation / start * 100); if(percentageFluctuation < 0) { 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 98a247d..f89f283 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -85,6 +85,7 @@ public class HomeActivity extends AppCompatActivity { private long lastTimestamp; private boolean detailsChecker; private boolean isDetailed; + private float totalValue; private CollapsingToolbarLayout toolbarLayout; private SwipeRefreshLayout refreshLayout; @@ -97,29 +98,6 @@ public class HomeActivity extends AppCompatActivity { private HashMap dominantCurrenciesColors; - private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener - = new BottomNavigationView.OnNavigationItemSelectedListener() { - - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.navigation_something: - - //((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide(); - return true; - case R.id.navigation_view_list: - //((FloatingActionButton) findViewById(R.id.floatingAddButton)).show(); - //viewFlipper.setDisplayedChild(1); - return true; - case R.id.navigation_market_cap: - //((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide(); - //viewFlipper.setDisplayedChild(2); - return true; - } - return false; - } - }; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -289,11 +267,11 @@ public class HomeActivity extends AppCompatActivity { @Override public void onItemClick(int itemIndex, String itemName) { + spaceNavigationItemEvent(itemIndex); } @Override public void onItemReselected(int itemIndex, String itemName) { - spaceNavigationItemEvent(itemIndex); } }); } @@ -437,7 +415,6 @@ public class HomeActivity extends AppCompatActivity { private void adaptView() { - currencyLayout.removeAllViews(); for(int i = 0; i < balanceManager.getTotalBalance().size(); i++) @@ -446,7 +423,7 @@ public class HomeActivity extends AppCompatActivity { if(!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001 || currency.getHistoryMinutes() == null)) { - currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed)); + currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden())); } } @@ -830,7 +807,7 @@ public class HomeActivity extends AppCompatActivity { } } - private void loadCurrency(Currency currency, List cardList) + private void loadCurrency(Currency currency) { if(!currency.getSymbol().equals("USD") && (currency.getBalance() * currency.getValue()) > 0.001) { @@ -838,30 +815,24 @@ public class HomeActivity extends AppCompatActivity { currency.setId(balanceManager.getCurrencyId(currency.getSymbol())); totalValue += currency.getValue() * currency.getBalance(); totalFluctuation += (currency.getValue() * currency.getBalance()) * (currency.getDayFluctuationPercentage() / 100); - - cardList.add(layoutGenerator.getInfoLayout(currency, true)); - } - - if(!currency.getSymbol().equals("USD") && currency.getHistoryMinutes() == null) - { - cardList.add(layoutGenerator.getInfoLayout(currency, true)); } } - private void refreshCurrencyList(final List cardList) + private void refreshCurrencyList() { runOnUiThread(new Runnable() { @Override public void run() { - refreshLayout.setRefreshing(false); currencyLayout.removeAllViews(); - for(int i = 0; i < cardList.size(); i++) + for(int i = 0; i < balanceManager.getTotalBalance().size(); i++) { - currencyLayout.addView(cardList.get(i)); - } + Currency currency = balanceManager.getTotalBalance().get(i); - adaptView(); + if(!currency.getSymbol().equals("USD") && (currency.getBalance() * currency.getValue()) > 0.001) { + currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden())); + } + } } }); } @@ -910,8 +881,6 @@ public class HomeActivity extends AppCompatActivity { @Override protected Void doInBackground(Void... params) { - final List cardList = new ArrayList<>(); - Looper.prepare(); balanceManager.sortCoins(); @@ -922,13 +891,11 @@ public class HomeActivity extends AppCompatActivity { updateChartColor(localCurrency); - loadCurrency(localCurrency, cardList); + loadCurrency(localCurrency); balanceManager.getTotalBalance().set(i, localCurrency); } - refreshCurrencyList(cardList); - toolbarLayout.setTitle("US$" + String.format("%.2f", totalValue)); updateFluctuation(); @@ -941,6 +908,9 @@ public class HomeActivity extends AppCompatActivity { @Override protected void onPostExecute(Void result) { + refreshLayout.setRefreshing(false); + refreshCurrencyList(); + HomeActivity.this.totalValue = totalValue; handler.removeCallbacks(updateRunnable); } } 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 8caff1b..b1afeed 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java @@ -20,6 +20,7 @@ import android.preference.PreferenceActivity; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; import android.preference.RingtonePreference; +import android.preference.SwitchPreference; import android.security.keystore.KeyGenParameterSpec; import android.security.keystore.KeyPermanentlyInvalidatedException; import android.security.keystore.KeyProperties; @@ -131,8 +132,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity { return true; } - Log.d("coinfolio", "hello"); - return super.onOptionsItemSelected(item); } @@ -198,7 +197,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { */ protected boolean isValidFragment(String fragmentName) { return PreferenceFragment.class.getName().equals(fragmentName) - //|| GeneralPreferenceFragment.class.getName().equals(fragmentName) + || GeneralPreferenceFragment.class.getName().equals(fragmentName) || DataSyncPreferenceFragment.class.getName().equals(fragmentName) || NotificationPreferenceFragment.class.getName().equals(fragmentName) || ExchangePreferenceFragment.class.getName().equals(fragmentName); @@ -216,12 +215,22 @@ public class SettingsActivity extends AppCompatPreferenceActivity { addPreferencesFromResource(R.xml.pref_general); setHasOptionsMenu(true); - // Bind the summaries of EditText/List/Dialog/Ringtone preferences - // to their values. When their values change, their summaries are - // updated to reflect the new value, per the Android Design - // guidelines. - bindPreferenceSummaryToValue(findPreference("example_text")); - bindPreferenceSummaryToValue(findPreference("example_list")); + ((SwitchPreference) findPreference("hide_balance")).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + boolean isChecked = !((SwitchPreference) findPreference("hide_balance")).isChecked(); + + ((SwitchPreference) findPreference("hide_balance")).setChecked(isChecked); + + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext()); + + SharedPreferences.Editor editor = preference.getEditor(); + + editor.putBoolean("hide_balance", isChecked); + editor.apply(); + return false; + } + }); } @Override 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 b787925..b676291 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java @@ -58,6 +58,11 @@ public class PreferencesManager { return settingPreferences.getBoolean("enable_hitbtc", false); } + public boolean isBalanceHidden() + { + return settingPreferences.getBoolean("hide_balance", false); + } + public void disableHitBTC() { SharedPreferences.Editor editor = settingPreferences.edit(); 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 ab93f77..f946862 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java @@ -9,6 +9,7 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; +import android.widget.ProgressBar; import android.widget.TextView; import com.db.chart.model.ChartSet; @@ -45,9 +46,8 @@ public class HomeLayoutGenerator { this.context = context; } - public View getInfoLayout(final Currency currency, boolean isExtended) + public View getInfoLayout(final Currency currency, boolean isExtended, float totalValue, boolean isBalanceHidden) { - View view = LayoutInflater.from(context).inflate(R.layout.cardview_currency, null); view.setOnClickListener(new View.OnClickListener() { @@ -64,7 +64,7 @@ public class HomeLayoutGenerator { } }); - updateCardViewInfos(view, currency); + updateCardViewInfos(view, currency, totalValue, isBalanceHidden); view.findViewById(R.id.errorTextView).setOnClickListener(new View.OnClickListener() { @Override @@ -120,7 +120,7 @@ public class HomeLayoutGenerator { }); } - private void updateCardViewInfos(View view, Currency currency) + private void updateCardViewInfos(View view, Currency currency, float totalValue, boolean isBalanceHidden) { ((ImageView) view.findViewById(R.id.currencyIcon)) .setImageBitmap(currency.getIcon()); @@ -141,6 +141,20 @@ public class HomeLayoutGenerator { .setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getDayFluctuation()))); ((ImageView) view.findViewById(R.id.detailsArrow)) .getDrawable().setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + + if(isBalanceHidden) + { + double value = currency.getValue() * currency.getBalance(); + double percentage = value / totalValue * 100; + + view.findViewById(R.id.currencyPortfolioDominance).setVisibility(View.VISIBLE); + ((ProgressBar) view.findViewById(R.id.currencyPortfolioDominance)).setProgress((int) Math.round(percentage)); + ((ProgressBar) view.findViewById(R.id.currencyPortfolioDominance)).getIndeterminateDrawable().setColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_ATOP); + } + else + { + view.findViewById(R.id.currencyPortfolioDominance).setVisibility(View.GONE); + } } private void collapseView(View view) diff --git a/app/src/main/res/layout/cardview_currency.xml b/app/src/main/res/layout/cardview_currency.xml index ba92896..3ebaaa1 100644 --- a/app/src/main/res/layout/cardview_currency.xml +++ b/app/src/main/res/layout/cardview_currency.xml @@ -13,7 +13,7 @@ android:layout_margin="10dp" android:clickable="false" android:backgroundTint="@color/listBackground2" - app:cardCornerRadius="8dp" + app:cardCornerRadius="2dp" app:layout_constraintBottom_toBottomOf="parent"> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a8bb5c0..f885ec0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -12,10 +12,7 @@ General - Enable social recommendations - Recommendations for people to contact - based on your message history - + Hide balance Display name John Smith diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index 36569d6..264c219 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -1,14 +1,13 @@ + android:defaultValue="false" + android:key="hide_balance" + android:title="@string/pref_title_hide_balance" /> - + android:title="@string/pref_title_display_name" />--> - + android:title="@string/pref_title_add_friends_to_messages" />--> diff --git a/app/src/main/res/xml/pref_headers.xml b/app/src/main/res/xml/pref_headers.xml index 5ca4a5f..be8b1af 100644 --- a/app/src/main/res/xml/pref_headers.xml +++ b/app/src/main/res/xml/pref_headers.xml @@ -2,6 +2,11 @@ +
+
--> + +