From 009dc09eca6e41225a46d5b7885fc584e1fafd20 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Sun, 29 Apr 2018 15:29:59 +0200 Subject: [PATCH] Add loading indicator for trades --- .idea/modules.xml | 1 - .../Activities/CurrencyDetailsActivity.java | 41 ++++++++++++++++--- .../res/layout/activity_currency_details.xml | 25 ++++++++--- app/src/main/res/layout/custom_trade_row.xml | 4 +- .../res/layout/listview_loading_indicator.xml | 19 +++++++++ 5 files changed, 75 insertions(+), 15 deletions(-) create mode 100644 app/src/main/res/layout/listview_loading_indicator.xml diff --git a/.idea/modules.xml b/.idea/modules.xml index f4fed45..52a531e 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,7 +3,6 @@ - diff --git a/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java b/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java index db08241..7814258 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java @@ -1,9 +1,12 @@ package com.nauk.moodl.Activities; +import android.app.ProgressDialog; +import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; +import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; @@ -21,6 +24,7 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.CardView; import android.text.Html; import android.text.method.LinkMovementMethod; +import android.view.LayoutInflater; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; @@ -101,6 +105,9 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private Button lineChartButton; private Button candleStickChartButton; + + private View loadingFooter; + private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() { @@ -218,6 +225,11 @@ public class CurrencyDetailsActivity extends AppCompatActivity { hasBeenModified = false; + Drawable tradeDrawable = ((ProgressBar) findViewById(R.id.loadingIndicator)).getIndeterminateDrawable(); + tradeDrawable.mutate(); + tradeDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + tradeDrawable.invalidateSelf(); + TradeUpdater updater = new TradeUpdater(); updater.execute(); } @@ -906,8 +918,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private void drawTradeList(ArrayList trades) { - findViewById(R.id.tradeProgressBar).setVisibility(View.GONE); - tradeLayout.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { @@ -922,7 +932,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity { { flag_loading = true; - expand(findViewById(R.id.tradeProgressBar)); TradeAdder tradeAdder = new TradeAdder(); tradeAdder.execute(); } @@ -934,6 +943,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity { tradeLayout.setAdapter(tradeListAdapter); tradeLayout.setTextFilterEnabled(false); + + findViewById(R.id.tradeLoaderIndicator).setVisibility(View.GONE); } private static void expand(final View v) { @@ -983,8 +994,28 @@ public class CurrencyDetailsActivity extends AppCompatActivity { } } + private void loadingIndicatorGenerator() + { + loadingFooter = LayoutInflater.from(CurrencyDetailsActivity.this).inflate(R.layout.listview_loading_indicator, null, false); + + Drawable drawable = ((ProgressBar) loadingFooter.findViewById(R.id.progressIndicator)).getIndeterminateDrawable(); + drawable.mutate(); + drawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + drawable.invalidateSelf(); + + tradeLayout.addFooterView(loadingFooter); + } + private class TradeAdder extends AsyncTask { + @Override + protected void onPreExecute() + { + super.onPreExecute(); + + loadingIndicatorGenerator(); + } + @Override protected Void doInBackground(Void... voids) { @@ -1006,7 +1037,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { tradeListAdapter.notifyDataSetChanged(); flag_loading = false; - findViewById(R.id.tradeProgressBar).setVisibility(View.GONE); + tradeLayout.removeFooterView(loadingFooter); } }); } @@ -1027,8 +1058,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity { protected void onPreExecute() { super.onPreExecute(); - - findViewById(R.id.tradeProgressBar).setVisibility(View.VISIBLE); } @Override diff --git a/app/src/main/res/layout/activity_currency_details.xml b/app/src/main/res/layout/activity_currency_details.xml index 69a1b93..754b82e 100644 --- a/app/src/main/res/layout/activity_currency_details.xml +++ b/app/src/main/res/layout/activity_currency_details.xml @@ -625,18 +625,31 @@ android:layout_weight="0.5" android:orientation="vertical"> + + + + + + + + - - diff --git a/app/src/main/res/layout/custom_trade_row.xml b/app/src/main/res/layout/custom_trade_row.xml index b311d94..aea6ec1 100644 --- a/app/src/main/res/layout/custom_trade_row.xml +++ b/app/src/main/res/layout/custom_trade_row.xml @@ -15,9 +15,9 @@ android:layout_height="match_parent"/> + android:layout_height="match_parent"> + + + + + + + \ No newline at end of file