From 97dc6df33af33cb41f481bb4f9a87558ad567544 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Sun, 22 Apr 2018 14:49:04 +0200 Subject: [PATCH] Graphical adjustment - Update every progress bar color - Smoother quick chart loading --- .../Activities/CurrencyDetailsActivity.java | 5 ++ .../HomeActivityFragments/Watchlist.java | 55 +++++++++++++------ .../LayoutManagers/HomeLayoutGenerator.java | 33 +++++++++-- .../res/layout/activity_currency_details.xml | 1 + app/src/main/res/layout/cardview_currency.xml | 42 +++++++++----- .../main/res/layout/cardview_watchlist.xml | 40 ++++++++++---- 6 files changed, 129 insertions(+), 47 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 aaf212f..4a8d006 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -185,6 +185,11 @@ public class CurrencyDetailsActivity extends AppCompatActivity { } }); + Drawable progressBarDrawable = ((ProgressBar) findViewById(R.id.progressBarChart)).getIndeterminateDrawable(); + progressBarDrawable.mutate(); + progressBarDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + progressBarDrawable.invalidateSelf(); + setupActionBar(); drawTransactionList(); 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 17fb706..5ac1602 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 @@ -26,6 +26,7 @@ import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.ProgressBar; import android.widget.TextView; import android.support.v7.widget.Toolbar; @@ -292,13 +293,29 @@ public class Watchlist extends Fragment { .setText(PlaceholderManager.getSymbolString(currency.getSymbol(), getActivity())); ((ImageView) card.findViewById(R.id.currencyIcon)).setImageBitmap(currency.getIcon()); + ((LineChart) card.findViewById(R.id.LineChartView)).setNoDataTextColor(currency.getChartColor()); + Drawable arrowDrawable = ((ImageView) card.findViewById(R.id.detailsArrow)).getDrawable(); arrowDrawable.mutate(); arrowDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); arrowDrawable.invalidateSelf(); + Drawable progressDrawable = ((ProgressBar) card.findViewById(R.id.progressBarLinechartWatchlist)).getIndeterminateDrawable(); + progressDrawable.mutate(); + progressDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + progressDrawable.invalidateSelf(); + updateColor(card, currency); + card.findViewById(R.id.LineChartView).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(getActivity(), CurrencyDetailsActivity.class); + intent.putExtra("currency", currency); + getActivity().getApplicationContext().startActivity(intent); + } + }); + card.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); card.setOnClickListener(new View.OnClickListener() { @Override @@ -309,37 +326,39 @@ public class Watchlist extends Fragment { } else { + view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.GONE); + view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.VISIBLE); + extendView(view); + if (currency.getHistoryMinutes() == null) { currency.updateHistoryMinutes(getActivity(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { @Override public void onSuccess(Currency currency) { - extendView(view); - setupLineChart(view, currency); + if(currency.getHistoryMinutes() != null) + { + setupLineChart(view, currency); + view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.GONE); + view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE); + } + else + { + view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.GONE); + view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE); + view.findViewById(R.id.linearLayoutSubLayout).findViewById(R.id.detailsArrow).setVisibility(View.GONE); + } } }); } else { extendView(view); + view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.GONE); + view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE); } } } }); - card.findViewById(R.id.LineChartView).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(getActivity(), CurrencyDetailsActivity.class); - intent.putExtra("currency", currency); - getActivity().getApplicationContext().startActivity(intent); - } - }); - - if(currency.getHistoryMinutes() != null) - { - setupLineChart(card, currency); - } - return card; } @@ -400,11 +419,13 @@ public class Watchlist extends Fragment { lineChart.getXAxis().setEnabled(false); lineChart.setViewPortOffsets(0, 0, 0, 0); lineChart.setData(generateData(currency)); + + lineChart.invalidate(); } private void updateColor(View card, Currency currency) { - if(currency.getDayFluctuation() > 0) + if(currency.getDayFluctuation() >= 0) { ((TextView) card.findViewById(R.id.currencyFluctuationPercentageTextView)).setTextColor(getResources().getColor(R.color.increase)); ((TextView) card.findViewById(R.id.currencyFluctuationTextView)).setTextColor(getResources().getColor(R.color.increase)); 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 c900aeb..0946451 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java @@ -53,6 +53,8 @@ public class HomeLayoutGenerator { { View view = LayoutInflater.from(context).inflate(R.layout.cardview_currency, null, true); + ((LineChart) view.findViewById(R.id.LineChartView)).setNoDataTextColor(currency.getChartColor()); + view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View view) { @@ -61,18 +63,34 @@ public class HomeLayoutGenerator { if (view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE) { collapseView(view); } else { + view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.GONE); + view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.VISIBLE); + extendView(view); + if (currency.getHistoryMinutes() == null) { currency.updateHistoryMinutes(context, preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { @Override public void onSuccess(Currency currency) { - ChartLoader chartLoader = new ChartLoader(view, currency); - chartLoader.execute(); + if(currency.getHistoryMinutes() != null) + { + setupLineChart(view, currency); + view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.GONE); + view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE); + } + else + { + view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.GONE); + view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE); + view.findViewById(R.id.linearLayoutSubLayout).findViewById(R.id.detailsArrow).setVisibility(View.GONE); + } } }); } else { extendView(view); + view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.GONE); + view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE); } } } @@ -94,7 +112,7 @@ public class HomeLayoutGenerator { return view; } - private class ChartLoader extends AsyncTask + /*private class ChartLoader extends AsyncTask { private View view; private Currency currency; @@ -126,7 +144,7 @@ public class HomeLayoutGenerator { view.findViewById(R.id.LineChartView).invalidate(); } } - +*/ private static void expand(final View v) { v.measure(CardView.LayoutParams.MATCH_PARENT, CardView.LayoutParams.WRAP_CONTENT); final int targetHeight = v.getMeasuredHeight(); @@ -230,6 +248,11 @@ public class HomeLayoutGenerator { arrowDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); arrowDrawable.invalidateSelf(); + Drawable progressDrawable = ((ProgressBar) view.findViewById(R.id.progressBarLinechartSummary)).getIndeterminateDrawable(); + progressDrawable.mutate(); + progressDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + progressDrawable.invalidateSelf(); + Drawable progressBarDrawable = ((ProgressBar) view.findViewById(R.id.currencyPortfolioDominance)).getProgressDrawable(); progressBarDrawable.mutate(); progressBarDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); @@ -265,7 +288,7 @@ public class HomeLayoutGenerator { private void updateColor(View view, Currency currency) { - if(currency.getDayFluctuationPercentage() > 0) + if(currency.getDayFluctuationPercentage() >= 0) { ((TextView) view.findViewById(R.id.currencyFluctuationPercentageTextView)) .setTextColor(context.getResources().getColor(R.color.increase)); diff --git a/app/src/main/res/layout/activity_currency_details.xml b/app/src/main/res/layout/activity_currency_details.xml index 171dd3c..5f5f6c2 100644 --- a/app/src/main/res/layout/activity_currency_details.xml +++ b/app/src/main/res/layout/activity_currency_details.xml @@ -50,6 +50,7 @@ android:gravity="center"> - - - - + android:layout_gravity="center" + android:clickable="false" + android:focusable="false" + android:visibility="visible"/> + + + + + + + + diff --git a/app/src/main/res/layout/cardview_watchlist.xml b/app/src/main/res/layout/cardview_watchlist.xml index cb28d39..e970242 100644 --- a/app/src/main/res/layout/cardview_watchlist.xml +++ b/app/src/main/res/layout/cardview_watchlist.xml @@ -139,19 +139,39 @@ android:layout_width="match_parent" android:layout_height="@dimen/cardViewChartSize" android:clickable="true" - android:focusable="true"> + android:focusable="true" + android:visibility="visible"> - - - + android:layout_gravity="center" + android:clickable="false" + android:focusable="false" + android:visibility="visible"/> + + + + + + + +