From 1bf8aea3d99ff4f34f3f8d3c0a052ea3c6e12a0a Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Sun, 8 Apr 2018 16:50:56 +0200 Subject: [PATCH] Lighter hide balance switch method --- .../Activities/CurrencyDetailsActivity.java | 2 - .../coinfolio/Activities/HomeActivity.java | 55 ++++++++++++++++--- .../Activities/SettingsActivity.java | 1 - .../LayoutManagers/HomeLayoutGenerator.java | 17 +++--- app/src/main/res/layout/cardview_currency.xml | 2 +- 5 files changed, 56 insertions(+), 21 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 596ef95..22775b8 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -657,8 +657,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity { TextView valueTxtView = view.findViewById(R.id.puchasedValue); TextView dateTxtView = view.findViewById(R.id.purchaseDate); - Log.d("coinfolio", "Timestamp " + transactionList.get(i).getTimestamp()); - dateTxtView.setText(getDate(transactionList.get(i).getTimestamp())); LinearLayout deleteLayout = view.findViewById(R.id.deleteTransactionLayout); 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 e5ccc79..c6e1f80 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -154,9 +154,7 @@ public class HomeActivity extends AppCompatActivity { ImageButton settingsButton = findViewById(R.id.settings_button); toolbarLayout.setForegroundGravity(Gravity.CENTER); - toolbarLayout.setTitle(getResources().getString(R.string.currencyDollarPlaceholder, "0.00")); - - toolbarSubtitle.setText(getResources().getString(R.string.currencyDollarPlaceholder, "0.00")); + updateTitle(); //Events setup detailsButton.setOnClickListener(new View.OnClickListener() { @@ -225,6 +223,27 @@ public class HomeActivity extends AppCompatActivity { setupDominantCurrenciesColors(); } + protected void updateTitle(float totalValue, float totalFluctuation) + { + float totalFluctuationPercentage = totalFluctuation / (totalValue - totalFluctuation) *100; + + if(loadingDialog.isShowing()) + { + loadingDialog.dismiss(); + } + + if(preferencesManager.isBalanceHidden()) + { + + } + else + { + toolbarLayout.setTitle(getResources().getString(R.string.currencyDollarPlaceholder, "0.00")); + toolbarSubtitle.setText(getResources().getString(R.string.currencyDollarPlaceholder, "0.00")); + toolbarSubtitle.setText("US$" + String.format("%.2f", totalFluctuation) + " (" + String.format("%.2f", totalFluctuationPercentage) + "%)"); + } + } + private void setupDominantCurrenciesColors() { dominantCurrenciesColors = new HashMap<>(); @@ -347,7 +366,31 @@ public class HomeActivity extends AppCompatActivity { updateAll(preferencesManager.mustUpdate()); - ((SpaceNavigationView) findViewById(R.id.space)).changeCenterButtonIcon(R.drawable.ic_view_list_white_24dp); + displayBalance(preferencesManager.isBalanceHidden()); + + //((SpaceNavigationView) findViewById(R.id.space)).changeCenterButtonIcon(R.drawable.ic_view_list_white_24dp); + } + + private void displayBalance(boolean hideBalance) + { + if(hideBalance) + { + for(int i = 0; i < currencyLayout.getChildCount(); i++) + { + currencyLayout.getChildAt(i).findViewById(R.id.currencyPortfolioDominance).setVisibility(View.VISIBLE); + currencyLayout.getChildAt(i).findViewById(R.id.percentageOwnedTextView).setVisibility(View.VISIBLE); + currencyLayout.getChildAt(i).findViewById(R.id.currencyOwnedInfoLayout).setVisibility(View.GONE); + } + } + else + { + for(int i = 0; i < currencyLayout.getChildCount(); i++) + { + currencyLayout.getChildAt(i).findViewById(R.id.currencyPortfolioDominance).setVisibility(View.INVISIBLE); + currencyLayout.getChildAt(i).findViewById(R.id.percentageOwnedTextView).setVisibility(View.GONE); + currencyLayout.getChildAt(i).findViewById(R.id.currencyOwnedInfoLayout).setVisibility(View.VISIBLE); + } + } } private void addTestWatchlistCardview() @@ -421,8 +464,6 @@ public class HomeActivity extends AppCompatActivity { if(!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001 || currency.getHistoryMinutes() == null)) { - //currencyLayout.addView(new HomeLayoutGenerator(this, currencyLayout).getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden())); - //currencyLayout.addView(new SummaryCurrencyCardView(this, currency, isDetailed, totalValue, preferencesManager.isBalanceHidden())); currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden())); } } @@ -830,8 +871,6 @@ public class HomeActivity extends AppCompatActivity { Currency currency = balanceManager.getTotalBalance().get(i); if(!currency.getSymbol().equals("USD") && (currency.getBalance() * currency.getValue()) > 0.001) { - //currencyLayout.addView(new HomeLayoutGenerator(getApplicationContext(), currencyLayout).getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden())); - //currencyLayout.addView(new SummaryCurrencyCardView(getApplicationContext(), currency, isDetailed, totalValue, preferencesManager.isBalanceHidden())); currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden())); } } 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 f18d8a5..01ffb58 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java @@ -225,7 +225,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity { SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean("hide_balance", isChecked); - editor.putBoolean("mustUpdate", true); editor.apply(); return isChecked; 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 2b9e0e7..580eba5 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java @@ -165,6 +165,10 @@ public class HomeLayoutGenerator { private void updateCardViewInfos(View view, Currency currency, float totalValue, boolean isBalanceHidden) { + double value = currency.getValue() * currency.getBalance(); + double percentage = value / totalValue * 100; + DecimalFormat df = new DecimalFormat(".##"); + ((ImageView) view.findViewById(R.id.currencyIcon)) .setImageBitmap(currency.getIcon()); ((TextView) view.findViewById(R.id.currencyNameTextView)) @@ -193,23 +197,18 @@ public class HomeLayoutGenerator { progressBarDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); 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))); + if(isBalanceHidden) { - double value = currency.getValue() * currency.getBalance(); - double percentage = value / totalValue * 100; - DecimalFormat df = new DecimalFormat(".##"); - view.findViewById(R.id.currencyPortfolioDominance).setVisibility(View.VISIBLE); - ((ProgressBar) view.findViewById(R.id.currencyPortfolioDominance)).setProgress((int) Math.round(percentage)); - view.findViewById(R.id.percentageOwnedTextView).setVisibility(View.VISIBLE); - ((TextView) view.findViewById(R.id.percentageOwnedTextView)).setText(context.getResources().getString(R.string.currencyPercentagePlaceholder, df.format(percentage))); - view.findViewById(R.id.currencyOwnedInfoLayout).setVisibility(View.GONE); } else { - view.findViewById(R.id.currencyPortfolioDominance).setVisibility(View.GONE); + view.findViewById(R.id.currencyPortfolioDominance).setVisibility(View.INVISIBLE); view.findViewById(R.id.percentageOwnedTextView).setVisibility(View.GONE); view.findViewById(R.id.currencyOwnedInfoLayout).setVisibility(View.VISIBLE); } diff --git a/app/src/main/res/layout/cardview_currency.xml b/app/src/main/res/layout/cardview_currency.xml index 3566074..193e044 100644 --- a/app/src/main/res/layout/cardview_currency.xml +++ b/app/src/main/res/layout/cardview_currency.xml @@ -30,7 +30,7 @@ android:layout_width="match_parent" android:layout_height="2dp" style="@style/Widget.AppCompat.ProgressBar.Horizontal" - android:visibility="gone"/> + android:visibility="invisible"/>