Complete hide balance feature and fix title updating method

This commit is contained in:
Tanguy Herbron 2018-04-08 20:21:02 +02:00
parent 1bf8aea3d9
commit 8db899ec33

View File

@ -82,7 +82,8 @@ public class HomeActivity extends AppCompatActivity {
private long lastTimestamp; private long lastTimestamp;
private boolean detailsChecker; private boolean detailsChecker;
private boolean isDetailed; private boolean isDetailed;
private float totalValue; protected float totalValue;
protected float totalFluctuation;
private CollapsingToolbarLayout toolbarLayout; private CollapsingToolbarLayout toolbarLayout;
private SwipeRefreshLayout refreshLayout; private SwipeRefreshLayout refreshLayout;
@ -154,6 +155,10 @@ public class HomeActivity extends AppCompatActivity {
ImageButton settingsButton = findViewById(R.id.settings_button); ImageButton settingsButton = findViewById(R.id.settings_button);
toolbarLayout.setForegroundGravity(Gravity.CENTER); toolbarLayout.setForegroundGravity(Gravity.CENTER);
totalValue = 0;
totalFluctuation = 0;
updateTitle(); updateTitle();
//Events setup //Events setup
@ -223,26 +228,55 @@ public class HomeActivity extends AppCompatActivity {
setupDominantCurrenciesColors(); setupDominantCurrenciesColors();
} }
protected void updateTitle(float totalValue, float totalFluctuation) protected void updateTitle()
{ {
float totalFluctuationPercentage = totalFluctuation / (totalValue - totalFluctuation) *100; float totalFluctuationPercentage = totalFluctuation / (totalValue - totalFluctuation) * 100;
if(loadingDialog.isShowing())
{
loadingDialog.dismiss();
}
if(preferencesManager.isBalanceHidden()) if(preferencesManager.isBalanceHidden())
{ {
toolbarLayout.setTitle(getResources().getString(R.string.currencyPercentagePlaceholder, String.format("%.2f", totalFluctuationPercentage)));
toolbarSubtitle.setVisibility(View.GONE);
if(totalFluctuation > 0)
{
toolbarLayout.setCollapsedTitleTextColor(getResources().getColor(R.color.increase));
toolbarLayout.setExpandedTitleColor(getResources().getColor(R.color.increase));
}
else
{
toolbarLayout.setCollapsedTitleTextColor(getResources().getColor(R.color.decrease));
toolbarLayout.setExpandedTitleColor(getResources().getColor(R.color.decrease));
}
}
else
{
toolbarLayout.setTitle(getResources().getString(R.string.currencyDollarPlaceholder, String.format("%.2f", totalValue)));
toolbarLayout.setCollapsedTitleTextColor(Color.WHITE);
toolbarLayout.setExpandedTitleColor(Color.WHITE);
toolbarSubtitle.setVisibility(View.VISIBLE);
if(totalFluctuation > 0)
{
toolbarSubtitle.setTextColor(getResources().getColor(R.color.increase));
}
else
{
toolbarSubtitle.setTextColor(getResources().getColor(R.color.decrease));
}
if(totalFluctuation == 0)
{
toolbarSubtitle.setText(getResources().getString(R.string.currencyDollarPlaceholder, "0.00"));
toolbarSubtitle.setTextColor(-1275068417);
} }
else 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) + "%)"); toolbarSubtitle.setText("US$" + String.format("%.2f", totalFluctuation) + " (" + String.format("%.2f", totalFluctuationPercentage) + "%)");
} }
} }
}
private void setupDominantCurrenciesColors() private void setupDominantCurrenciesColors()
{ {
@ -373,6 +407,8 @@ public class HomeActivity extends AppCompatActivity {
private void displayBalance(boolean hideBalance) private void displayBalance(boolean hideBalance)
{ {
updateTitle();
if(hideBalance) if(hideBalance)
{ {
for(int i = 0; i < currencyLayout.getChildCount(); i++) for(int i = 0; i < currencyLayout.getChildCount(); i++)
@ -499,6 +535,9 @@ public class HomeActivity extends AppCompatActivity {
coinCounter = 0; coinCounter = 0;
iconCounter = 0; iconCounter = 0;
detailsChecker = false; detailsChecker = false;
totalValue = 0;
totalFluctuation = 0;
} }
private void getBitmapFromURL(String src, IconCallBack callBack) { private void getBitmapFromURL(String src, IconCallBack callBack) {
@ -569,11 +608,8 @@ public class HomeActivity extends AppCompatActivity {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
toolbarLayout.setTitle(getResources().getString(R.string.currencyDollarPlaceholder, "0.00"));
toolbarSubtitle.setText(getResources().getString(R.string.currencyDollarPlaceholder, "0.00")); updateTitle();
toolbarSubtitle.setTextColor(-1275068417);
} }
}); });
} }
@ -814,10 +850,6 @@ public class HomeActivity extends AppCompatActivity {
private class UiHeavyLoadCalculator extends AsyncTask<Void, Integer, Void> private class UiHeavyLoadCalculator extends AsyncTask<Void, Integer, Void>
{ {
private float totalValue;
private float totalFluctuation;
private float totalFluctuationPercentage;
@Override @Override
protected void onPreExecute() protected void onPreExecute()
{ {
@ -825,7 +857,6 @@ public class HomeActivity extends AppCompatActivity {
totalValue = 0; totalValue = 0;
totalFluctuation = 0; totalFluctuation = 0;
totalFluctuationPercentage = 0;
} }
@Override @Override
@ -878,47 +909,6 @@ public class HomeActivity extends AppCompatActivity {
}); });
} }
private void updateFluctuation()
{
if(totalFluctuation > 0)
{
runOnUiThread(new Runnable() {
@Override
public void run() {
toolbarSubtitle.setTextColor(getResources().getColor(R.color.increase));
}
});
}
else
{
runOnUiThread(new Runnable() {
@Override
public void run() {
toolbarSubtitle.setTextColor(getResources().getColor(R.color.decrease));
}
});
}
}
private void updateTitle()
{
runOnUiThread(new Runnable() {
@Override
public void run() {
totalFluctuationPercentage = totalFluctuation / (totalValue - totalFluctuation) *100;
//toolbarSubtitle.setText(String.format(getResources().getString(R.string.fluctuationDollarPercentagePlaceholder), totalFluctuation));
toolbarSubtitle.setText("US$" + String.format("%.2f", totalFluctuation) + " (" + String.format("%.2f", totalFluctuationPercentage) + "%)");
if(loadingDialog.isShowing())
{
loadingDialog.dismiss();
}
}
});
}
@Override @Override
protected Void doInBackground(Void... params) protected Void doInBackground(Void... params)
{ {
@ -940,11 +930,17 @@ public class HomeActivity extends AppCompatActivity {
balanceManager.getTotalBalance().set(i, localCurrency); balanceManager.getTotalBalance().set(i, localCurrency);
} }
toolbarLayout.setTitle("US$" + String.format("%.2f", totalValue)); runOnUiThread(new Runnable() {
@Override
updateFluctuation(); public void run() {
updateTitle(); updateTitle();
}
});
if(loadingDialog.isShowing())
{
loadingDialog.dismiss();
}
return null; return null;
} }