Add loading indicator for trades

This commit is contained in:
Tanguy Herbron 2018-04-29 15:29:59 +02:00
parent 680840b262
commit 009dc09eca
5 changed files with 75 additions and 15 deletions

1
.idea/modules.xml generated
View File

@ -3,7 +3,6 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Moodl.iml" filepath="$PROJECT_DIR$/Moodl.iml" />
<module fileurl="file://E:\Github\Moodl\Moodl.iml" filepath="E:\Github\Moodl\Moodl.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>

View File

@ -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<com.nauk.moodl.DataManagers.CurrencyData.Trade> 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<Void, Integer, Void>
{
@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

View File

@ -625,18 +625,31 @@
android:layout_weight="0.5"
android:orientation="vertical">
<LinearLayout
android:id="@+id/tradeLoaderIndicator"
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="center"
android:layout_margin="10dp">
<ProgressBar
android:id="@+id/loadingIndicator"
android:layout_width="20dp"
android:layout_height="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Looking for trades..."/>
</LinearLayout>
<ListView
android:id="@+id/listTrades"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
<ProgressBar
android:id="@+id/tradeProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
</LinearLayout>
</LinearLayout>

View File

@ -15,9 +15,9 @@
android:layout_height="match_parent"/>
<LinearLayout
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainLayout">
android:layout_height="match_parent">
<LinearLayout
android:padding="5dp"

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="center"
android:layout_margin="10dp">
<ProgressBar
android:id="@+id/progressIndicator"
android:layout_width="20dp"
android:layout_height="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Looking for more trades..."/>
</LinearLayout>