From defd3db2f0139e2b588fb518e0be56cf3a57d747 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Fri, 16 Mar 2018 15:51:52 +0100 Subject: [PATCH 01/34] Watchlist infalter --- .../coinfolio/Activities/HomeActivity.java | 20 ++ .../main/res/layout/cardview_watchlist.xml | 173 ++++++++++++++++++ 2 files changed, 193 insertions(+) create mode 100644 app/src/main/res/layout/cardview_watchlist.xml 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 b3f63a9..50efe0c 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -28,6 +28,7 @@ import android.text.style.StyleSpan; import android.util.Log; import android.view.DragEvent; import android.view.Gravity; +import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; @@ -58,6 +59,8 @@ import com.nauk.coinfolio.DataManagers.PreferencesManager; import com.nauk.coinfolio.LayoutManagers.HomeLayoutGenerator; import com.nauk.coinfolio.R; +import org.w3c.dom.Text; + import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; @@ -373,6 +376,23 @@ public class HomeActivity extends AppCompatActivity { protected void onResume() { super.onResume(); + + View view = LayoutInflater.from(this).inflate(R.layout.cardview_watchlist, null); + ((TextView) view.findViewById(R.id.currencyFluctuationPercentageTextView)).setText("3%"); + ((TextView) view.findViewById(R.id.currencyFluctuationTextView)).setText("$3"); + ((TextView) view.findViewById(R.id.currencyNameTextView)).setText("TanguyCoin"); + ((TextView) view.findViewById(R.id.currencySymbolTextView)).setText("TGC"); + ((TextView) view.findViewById(R.id.currencyValueTextView)).setText("$100"); + view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Log.d("coinfolio", "Clicked !"); + } + }); + + ((LinearLayout) findViewById(R.id.linearLayoutWatchlist)).addView(view); + Intent intent = getIntent(); updateAll(intent.getBooleanExtra("update", false)); diff --git a/app/src/main/res/layout/cardview_watchlist.xml b/app/src/main/res/layout/cardview_watchlist.xml new file mode 100644 index 0000000..143d029 --- /dev/null +++ b/app/src/main/res/layout/cardview_watchlist.xml @@ -0,0 +1,173 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 056c029424f0df56e7897881090ce65f991a1ac6 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Tue, 20 Mar 2018 23:42:55 +0100 Subject: [PATCH 02/34] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 3c07cdd..f778972 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,7 @@ # Coinfolio + +TODO List : +Sort currencies by marketcap in currency selection activity +Add transaction button to add quick transactions from the detailed activity +Center the price in home activity From c9e7f8f21dd8dcf7602bb5b7cb02f1e49f7cf97b Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Tue, 20 Mar 2018 23:43:27 +0100 Subject: [PATCH 03/34] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f778972..d12f150 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Coinfolio -TODO List : -Sort currencies by marketcap in currency selection activity -Add transaction button to add quick transactions from the detailed activity -Center the price in home activity +TODO List :
+Sort currencies by marketcap in currency selection activity
+Add transaction button to add quick transactions from the detailed activity
+Center the price in home activity
From dc0dedca73967184019e4911522f90720e03d603 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Wed, 28 Mar 2018 00:27:51 +0200 Subject: [PATCH 04/34] FIx 1month detail crash --- .../Activities/CurrencyDetailsActivity.java | 3 +- .../coinfolio/Activities/HomeActivity.java | 5 ++- .../LayoutManagers/HomeLayoutGenerator.java | 3 +- .../res/layout/activity_currency_summary.xml | 32 ++++++++----------- .../res/layout/content_currency_summary.xml | 3 +- app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/styles.xml | 16 +++++++++- 7 files changed, 36 insertions(+), 27 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 80a78d3..6dede6a 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -243,7 +243,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { }); break; case "1M": - currency.updateHistoryDays(this, new Currency.CurrencyCallBack() { + currency.updateHistoryHours(this, new Currency.CurrencyCallBack() { @Override public void onSuccess(Currency currency) { runOnUiThread(new Runnable() { @@ -398,6 +398,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { { case 1: dataChartList = currency.getHistoryHours(); + Log.d("coinfolio", "1 month"); offset = 124; pointFormat = MONTH; break; 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 50efe0c..905b34a 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -140,7 +140,8 @@ public class HomeActivity extends AppCompatActivity { //Setup main interface requestWindowFeature(Window.FEATURE_NO_TITLE); - this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); + getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); + //this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_currency_summary); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); @@ -185,8 +186,6 @@ public class HomeActivity extends AppCompatActivity { ImageButton detailsButton = findViewById(R.id.switch_button); ImageButton settingsButton = findViewById(R.id.settings_button); - toolbarLayout.setExpandedTitleGravity(Gravity.CENTER); - toolbarLayout.setCollapsedTitleGravity(Gravity.CENTER); toolbarLayout.setForegroundGravity(Gravity.CENTER); toolbarLayout.setTitle("US$0.00"); 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 6196e3f..ac2cb2a 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java @@ -154,13 +154,12 @@ public class HomeLayoutGenerator { if(currency.getHistoryMinutes() != null) { view.findViewById(R.id.LineChartView).setVisibility(View.VISIBLE); - ((LineChart) view.findViewById(R.id.LineChartView)).invalidate(); + view.findViewById(R.id.LineChartView).invalidate(); view.findViewById(R.id.errorTextView).setVisibility(View.GONE); } else { view.findViewById(R.id.LineChartView).setVisibility(View.GONE); - view.findViewById(R.id.errorTextView).setVisibility(View.VISIBLE); } diff --git a/app/src/main/res/layout/activity_currency_summary.xml b/app/src/main/res/layout/activity_currency_summary.xml index daf65a1..89d700b 100644 --- a/app/src/main/res/layout/activity_currency_summary.xml +++ b/app/src/main/res/layout/activity_currency_summary.xml @@ -29,7 +29,10 @@ android:fitsSystemWindows="true" app:contentScrim="@drawable/gradient_background" app:layout_scrollFlags="scroll|exitUntilCollapsed" - app:toolbarId="@+id/toolbar"> + app:toolbarId="@+id/toolbar" + app:collapsedTitleGravity="center" + app:expandedTitleGravity="center" + app:titleEnabled="true"> + app:popupTheme="@style/AppTheme.PopupOverlay" + android:layout_marginStart="-30dp"> - - - - - + android:visibility="visible" + android:layout_gravity="start"/> + android:visibility="visible" + android:layout_gravity="end"/> - + diff --git a/app/src/main/res/layout/content_currency_summary.xml b/app/src/main/res/layout/content_currency_summary.xml index eb66f56..207ae88 100644 --- a/app/src/main/res/layout/content_currency_summary.xml +++ b/app/src/main/res/layout/content_currency_summary.xml @@ -82,7 +82,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone" - android:orientation="vertical"> + android:orientation="vertical" + android:gravity="center_vertical"> Total Market Capitalization :\nUS$%1$s 24h volume :\nUS$%1$s + ScrollingActivity diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index c0e13d4..610e24d 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,18 +1,25 @@ - + From 40dc5139a0745ac12a5d861cf5e5f1373d109bea Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Wed, 28 Mar 2018 00:34:12 +0200 Subject: [PATCH 05/34] Fix --- .../java/com/nauk/coinfolio/Activities/HomeActivity.java | 7 +++++-- .../com/nauk/coinfolio/DataManagers/MarketCapManager.java | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) 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 50efe0c..2365778 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -569,10 +569,13 @@ public class HomeActivity extends AppCompatActivity { { marketCapCounter = 0; + Log.d("coinfolio", "Start update market cap"); + marketCapManager.updateTopCurrencies(new MarketCapManager.VolleyCallBack() { @Override public void onSuccess() { + Log.d("coinfolio", "Top updated"); countCompletedMarketCapRequest(); } }); @@ -580,6 +583,7 @@ public class HomeActivity extends AppCompatActivity { marketCapManager.updateMarketCap(new MarketCapManager.VolleyCallBack() { @Override public void onSuccess() { + Log.d("coinfolio", "Marketcap updated"); countCompletedMarketCapRequest(); } }); @@ -601,7 +605,7 @@ public class HomeActivity extends AppCompatActivity { ArrayList colors = new ArrayList<>(); - final PieChart pieChart = findViewById(R.id.marketCapPieChart); + PieChart pieChart = findViewById(R.id.marketCapPieChart); float otherCurrenciesDominance = 0; @@ -624,7 +628,6 @@ public class HomeActivity extends AppCompatActivity { data.setValueTextSize(10); data.setValueFormatter(new PercentFormatter()); pieChart.setData(data); - pieChart.setDrawSlicesUnderHole(false); pieChart.setUsePercentValues(true); pieChart.setTouchEnabled(true); diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/MarketCapManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/MarketCapManager.java index 9cf3b5e..d3b0a6f 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/MarketCapManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/MarketCapManager.java @@ -127,8 +127,8 @@ public class MarketCapManager { for(int i = 0; i < topRequestResult.length; i++) { - try { - topRequestResult[i] += "}"; + topRequestResult[i] += "}"; + /*try { JSONObject jsonObject = new JSONObject(topRequestResult[i]); @@ -136,7 +136,7 @@ public class MarketCapManager { } catch (JSONException e) { e.printStackTrace(); - } + }*/ } } From 9ff13165c6a119f9efeb40ac42086f1698de76d7 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Mon, 2 Apr 2018 23:46:00 +0200 Subject: [PATCH 06/34] Added Volume charts in detail activity --- .../Activities/CurrencyDetailsActivity.java | 171 +++++++++++++----- .../coinfolio/Activities/HomeActivity.java | 12 +- .../CurrencyData/CurrencyDataChart.java | 15 +- .../CurrencyData/CurrencyDataRetriever.java | 4 +- .../main/res/color/home_color_bottombar.xml | 2 +- .../main/res/drawable/gradient_background.xml | 8 +- .../res/layout/activity_currency_details.xml | 12 +- .../res/layout/activity_currency_summary.xml | 3 +- .../res/layout/content_currency_summary.xml | 3 +- app/src/main/res/values/colors.xml | 4 +- app/src/main/res/values/dimens.xml | 2 + app/src/main/res/values/styles.xml | 20 +- 12 files changed, 185 insertions(+), 71 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 6dede6a..1bf561b 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -14,7 +14,6 @@ import android.support.v4.content.ContextCompat; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.util.Log; -import android.view.Gravity; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.MotionEvent; @@ -25,14 +24,16 @@ import android.widget.TextView; import android.widget.ViewFlipper; import com.daimajia.swipe.SwipeLayout; -import com.db.chart.model.LineSet; import com.db.chart.tooltip.Tooltip; +import com.github.mikephil.charting.charts.BarChart; import com.github.mikephil.charting.charts.LineChart; +import com.github.mikephil.charting.data.BarData; +import com.github.mikephil.charting.data.BarDataSet; +import com.github.mikephil.charting.data.BarEntry; import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.LineData; import com.github.mikephil.charting.data.LineDataSet; import com.github.mikephil.charting.highlight.Highlight; -import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; import com.github.mikephil.charting.listener.OnChartValueSelectedListener; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart; @@ -128,17 +129,18 @@ public class CurrencyDetailsActivity extends AppCompatActivity { if(currency.getHistoryMinutes().size() > 0) { - drawChart(DAY, 1); + drawPriceChart(DAY, 1); + drawVolumeChart(DAY, 1); } else { - TextView errorTextView = new TextView(this); + /*TextView errorTextView = new TextView(this); errorTextView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 750)); errorTextView.setText("Not enough data"); errorTextView.setTag("chart_layout"); errorTextView.setGravity(Gravity.CENTER); - chartLayout.addView(errorTextView, 0); + chartLayout.addView(errorTextView, 0);*/ } setTitle(" " + currency.getName()); @@ -182,6 +184,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private void buttonEvent(View v) { v.setEnabled(false); + v.setElevation(convertDpToPx(8)); LinearLayout buttonLayout = (LinearLayout) v.getParent(); @@ -192,15 +195,22 @@ public class CurrencyDetailsActivity extends AppCompatActivity { if(button != v) { button.setEnabled(true); + button.setElevation(convertDpToPx(2)); } } chartEvent((Button) v); } + private float convertDpToPx(float dp) + { + return dp * this.getResources().getDisplayMetrics().density; + } + private void chartEvent(Button button) { - findViewById(R.id.chartView).setVisibility(View.GONE); + findViewById(R.id.chartPriceView).setVisibility(View.GONE); + findViewById(R.id.chartVolumeView).setVisibility(View.GONE); findViewById(R.id.progressLayoutChart).setVisibility(View.VISIBLE); String interval = button.getText().toString().substring(button.getText().toString().length()-2); @@ -208,13 +218,16 @@ public class CurrencyDetailsActivity extends AppCompatActivity { switch (interval) { case "1h": - drawChart(HOUR, 1); + drawPriceChart(HOUR, 1); + drawVolumeChart(HOUR, 1); break; case "3h": - drawChart(HOUR, 3); + drawPriceChart(HOUR, 3); + drawVolumeChart(HOUR, 3); break; case "1d": - drawChart(DAY, 1); + drawPriceChart(DAY, 1); + drawVolumeChart(DAY, 1); break; case "3d": currency.updateHistoryHours(this, new Currency.CurrencyCallBack() { @@ -223,7 +236,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - drawChart(CurrencyDetailsActivity.DAY, 3); + drawPriceChart(CurrencyDetailsActivity.DAY, 3); + drawVolumeChart(CurrencyDetailsActivity.DAY, 3); } }); } @@ -236,7 +250,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - drawChart(CurrencyDetailsActivity.WEEK, 1); + drawPriceChart(CurrencyDetailsActivity.WEEK, 1); + drawVolumeChart(CurrencyDetailsActivity.WEEK, 1); } }); } @@ -249,7 +264,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - drawChart(CurrencyDetailsActivity.MONTH, 1); + drawPriceChart(CurrencyDetailsActivity.MONTH, 1); + drawVolumeChart(CurrencyDetailsActivity.MONTH, 1); } }); } @@ -262,7 +278,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - drawChart(CurrencyDetailsActivity.MONTH, 3); + drawPriceChart(CurrencyDetailsActivity.MONTH, 3); + drawVolumeChart(CurrencyDetailsActivity.MONTH, 3); } }); } @@ -275,7 +292,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - drawChart(CurrencyDetailsActivity.MONTH, 6); + drawPriceChart(CurrencyDetailsActivity.MONTH, 6); + drawVolumeChart(CurrencyDetailsActivity.MONTH, 6); } }); } @@ -288,7 +306,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - drawChart(CurrencyDetailsActivity.YEAR, 1); + drawPriceChart(CurrencyDetailsActivity.YEAR, 1); + drawVolumeChart(CurrencyDetailsActivity.YEAR, 1); } }); } @@ -297,9 +316,34 @@ public class CurrencyDetailsActivity extends AppCompatActivity { } } - private void drawChart(int timeUnit, int amout) + private void drawVolumeChart(int timeUnit, int amout) { - final LineChart lineChart = findViewById(R.id.chartView); + final BarChart barChart = findViewById(R.id.chartVolumeView); + + barChart.setDrawGridBackground(false); + barChart.setDrawBorders(false); + barChart.setDrawMarkers(true); + barChart.setDoubleTapToZoomEnabled(true); + barChart.setPinchZoom(true); + barChart.setScaleEnabled(false); + barChart.setDragEnabled(true); + barChart.getDescription().setEnabled(false); + barChart.getAxisLeft().setEnabled(false); + barChart.getAxisRight().setEnabled(false); + barChart.getLegend().setEnabled(false); + barChart.getXAxis().setEnabled(false); + barChart.setViewPortOffsets(0, 0, 0, 0); + barChart.setFitBars(true); + + barChart.setData(generateVolumeChartSet(timeUnit, amout)); + barChart.invalidate(); + + findViewById(R.id.chartVolumeView).setVisibility(View.VISIBLE); + } + + private void drawPriceChart(int timeUnit, int amout) + { + final LineChart lineChart = findViewById(R.id.chartPriceView); lineChart.setDrawGridBackground(false); lineChart.setDrawBorders(false); @@ -315,7 +359,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { lineChart.getXAxis().setEnabled(false); lineChart.setViewPortOffsets(0, 0, 0, 0); - lineChart.setData(generateChartSet(timeUnit, amout)); + lineChart.setData(generatePriceChartSet(timeUnit, amout)); lineChart.getAxisLeft().setAxisMinValue(lineChart.getData().getYMin()); lineChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { @@ -346,11 +390,73 @@ public class CurrencyDetailsActivity extends AppCompatActivity { updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY()); - findViewById(R.id.chartView).setVisibility(View.VISIBLE); + findViewById(R.id.chartPriceView).setVisibility(View.VISIBLE); findViewById(R.id.progressLayoutChart).setVisibility(View.GONE); } - private LineData generateChartSet(int timeUnit, int amount) + private BarData generateVolumeChartSet(int timeUnit, int amount) + { + BarDataSet dataSet; + List dataChartList = new ArrayList<>(); + ArrayList values = new ArrayList<>(); + + switch (timeUnit) + { + case HOUR: + dataChartList = currency.getHistoryMinutes().subList(currency.getHistoryMinutes().size()-(60*amount), currency.getHistoryMinutes().size()); + break; + case DAY: + if(amount == 1) + { + dataChartList = currency.getHistoryMinutes(); + } + else + { + dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-(24*amount), currency.getHistoryHours().size()); + } + break; + case WEEK: + dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-168, currency.getHistoryHours().size()); + break; + case MONTH: + switch (amount) + { + case 1: + dataChartList = currency.getHistoryHours(); + break; + case 3: + dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-93, currency.getHistoryDays().size()); + break; + case 6: + dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-186, currency.getHistoryDays().size()); + break; + } + break; + case YEAR: + dataChartList = currency.getHistoryDays(); + break; + } + + int offset = (int) Math.floor(dataChartList.size() / 50); + + int loopNumber = 0; + for(int i = 0; i < dataChartList.size(); i += offset) + { + values.add(new BarEntry(loopNumber, (float) dataChartList.get(i).getVolumeTo())); + loopNumber++; + } + + dataSet = new BarDataSet(values, "Volume"); + dataSet.setDrawIcons(false); + dataSet.setColor(Color.GRAY); + dataSet.setDrawValues(false); + dataSet.setHighlightEnabled(true); + dataSet.setHighLightColor(currency.getChartColor()); + + return new BarData(dataSet); + } + + private LineData generatePriceChartSet(int timeUnit, int amount) { LineDataSet dataSet; List dataChartList = new ArrayList<>(); @@ -583,28 +689,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { ((TextView) findViewById(R.id.txtViewPercentage)).setText(percentageFluctuation + "%"); } - private void updateFluctuation(LineData lineData) - { - ILineDataSet dataSet = lineData.getDataSets().get(0); - - float fluctuation = dataSet.getEntryForIndex(dataSet.getEntryCount() - 1).getY() - dataSet.getEntryForIndex(0).getY(); - float percentageFluctuation = (float) (fluctuation / dataSet.getEntryForIndex(0).getY() * 100); - - if(percentageFluctuation < 0) - { - ((TextView) findViewById(R.id.txtViewPercentage)).setTextColor(getResources().getColor(R.color.red)); - } - else - { - ((TextView) findViewById(R.id.txtViewPercentage)).setTextColor(getResources().getColor(R.color.green)); - } - - ((TextView) findViewById(R.id.txtViewPriceStart)).setText("$" + dataSet.getEntryForIndex(0).getY()); - ((TextView) findViewById(R.id.txtViewPriceNow)).setText("$" + dataSet.getEntryForIndex(dataSet.getEntryCount() - 1).getY()); - ((TextView) findViewById(R.id.txtViewPercentage)).setText(percentageFluctuation + "%"); - } - - /*private LineSet generateChartSet(int timeUnit, int amount) + /*private LineSet generatePriceChartSet(int timeUnit, int amount) { List dataChartList = new ArrayList<>(); LineSet lineSet = new LineSet(); 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 8de9607..53f604b 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -6,6 +6,7 @@ import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; +import android.graphics.Outline; import android.graphics.Typeface; import android.os.AsyncTask; import android.os.Bundle; @@ -34,6 +35,7 @@ import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.ViewOutlineProvider; import android.view.Window; import android.view.WindowManager; import android.widget.ImageButton; @@ -139,9 +141,11 @@ public class HomeActivity extends AppCompatActivity { /**Interface setup**/ //Setup main interface - requestWindowFeature(Window.FEATURE_NO_TITLE); - getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); + //requestWindowFeature(Window.FEATURE_NO_TITLE); + //getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); //this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); + getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + setContentView(R.layout.activity_currency_summary); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); @@ -293,7 +297,7 @@ public class HomeActivity extends AppCompatActivity { spaceNavigationView.addSpaceItem(new SpaceItem("Market Cap.", R.drawable.ic_pie_chart_black_24dp)); spaceNavigationView.setSpaceBackgroundColor(getResources().getColor(R.color.colorPrimary)); spaceNavigationView.setCentreButtonIcon(R.drawable.ic_view_list_white_24dp); - spaceNavigationView.setCentreButtonColor(getResources().getColor(R.color.colorAccent)); + spaceNavigationView.setCentreButtonColor(getResources().getColor(R.color.colorPrimary)); spaceNavigationView.setCentreButtonIconColorFilterEnabled(false); spaceNavigationView.changeCurrentItem(-1); @@ -390,7 +394,7 @@ public class HomeActivity extends AppCompatActivity { } }); - ((LinearLayout) findViewById(R.id.linearLayoutWatchlist)).addView(view); + //((LinearLayout) findViewById(R.id.linearLayoutWatchlist)).addView(view); Intent intent = getIntent(); diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java index 31cc654..8fea2be 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java @@ -14,14 +14,18 @@ public class CurrencyDataChart implements Parcelable { double high; double low; double open; + double volumeFrom; + double volumeTo; - public CurrencyDataChart(long timestamp, double close, double high, double low, double open) + public CurrencyDataChart(long timestamp, double close, double high, double low, double open, double volumeFrom, double volumeTo) { this.timestamp = timestamp; this.close = close; this.high = high; this.low = low; this.open = open; + this.volumeFrom = volumeFrom; + this.volumeTo = volumeTo; } public double getOpen() @@ -34,6 +38,11 @@ public class CurrencyDataChart implements Parcelable { return close; } + public double getVolumeTo() + { + return volumeTo; + } + public long getTimestamp() { return timestamp; @@ -51,6 +60,8 @@ public class CurrencyDataChart implements Parcelable { dest.writeDouble(this.high); dest.writeDouble(this.low); dest.writeDouble(this.open); + dest.writeDouble(this.volumeFrom); + dest.writeDouble(this.volumeTo); } protected CurrencyDataChart(Parcel in) { @@ -59,6 +70,8 @@ public class CurrencyDataChart implements Parcelable { this.high = in.readDouble(); this.low = in.readDouble(); this.open = in.readDouble(); + this.volumeFrom = in.readDouble(); + this.volumeTo = in.readDouble(); } public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java index b7e59ab..95a3aee 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java @@ -104,8 +104,10 @@ public class CurrencyDataRetriever { double high = Double.parseDouble(jsonObject.getString("high")); double low = Double.parseDouble(jsonObject.getString("low")); double open = Double.parseDouble(jsonObject.getString("open")); + double volumeFrom = Double.parseDouble(jsonObject.getString("volumefrom")); + double volumeTo = Double.parseDouble(jsonObject.getString("volumeto")); - dataChart.add(new CurrencyDataChart(timestamp, close, high, low, open)); + dataChart.add(new CurrencyDataChart(timestamp, close, high, low, open, volumeFrom, volumeTo)); } catch (JSONException e) { Log.d(context.getResources().getString(R.string.debug_volley), "API Request error: " + e + " index: " + i); diff --git a/app/src/main/res/color/home_color_bottombar.xml b/app/src/main/res/color/home_color_bottombar.xml index b8cae12..5fafac5 100644 --- a/app/src/main/res/color/home_color_bottombar.xml +++ b/app/src/main/res/color/home_color_bottombar.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/app/src/main/res/drawable/gradient_background.xml b/app/src/main/res/drawable/gradient_background.xml index 2dd82b0..24074e2 100644 --- a/app/src/main/res/drawable/gradient_background.xml +++ b/app/src/main/res/drawable/gradient_background.xml @@ -1,9 +1,7 @@ + android:startColor="@color/colorPrimary" + android:endColor="@color/colorPrimaryDark" + android:angle="0"/> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_currency_details.xml b/app/src/main/res/layout/activity_currency_details.xml index 7d3fa03..92892ff 100644 --- a/app/src/main/res/layout/activity_currency_details.xml +++ b/app/src/main/res/layout/activity_currency_details.xml @@ -21,7 +21,7 @@ @@ -37,11 +37,17 @@ + + + android:elevation="10dp"> + android:layout_marginBottom="50dp"> - #000046 - #111124 + #004e92 + #000428 #1CB5E0 #FF000000 #FF222222 diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index b1805b4..5d3f91c 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -15,4 +15,6 @@ 60dp 125dp 250dp + + 1dp diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 610e24d..b3d370f 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,25 +1,28 @@ - From 0cc6da7cdd7c9b062798259d4293f48c96c3f3e6 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Tue, 3 Apr 2018 19:29:36 +0200 Subject: [PATCH 07/34] Synchronize cursor for detail activity --- .../Activities/CurrencyDetailsActivity.java | 58 +++++++++++++++---- .../CurrencyData/CurrencyDataChart.java | 5 ++ .../res/drawable/linear_chart_gradient.xml | 10 ++++ .../res/layout/activity_currency_details.xml | 28 +++++++++ .../res/layout/content_currency_summary.xml | 3 +- 5 files changed, 92 insertions(+), 12 deletions(-) create mode 100644 app/src/main/res/drawable/linear_chart_gradient.xml 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 1bf561b..d176ff9 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -5,7 +5,9 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.PorterDuff; import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.BottomNavigationView; @@ -41,8 +43,10 @@ import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction; import com.nauk.coinfolio.DataManagers.DatabaseManager; import com.nauk.coinfolio.R; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; +import java.util.Date; import java.util.List; import java.util.Locale; @@ -344,6 +348,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private void drawPriceChart(int timeUnit, int amout) { final LineChart lineChart = findViewById(R.id.chartPriceView); + final BarChart barChart = findViewById(R.id.chartVolumeView); lineChart.setDrawGridBackground(false); lineChart.setDrawBorders(false); @@ -366,6 +371,9 @@ public class CurrencyDetailsActivity extends AppCompatActivity { @Override public void onValueSelected(Entry e, Highlight h) { updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), e.getY()); + int index = lineChart.getData().getDataSets().get(0).getEntryIndex(e); + barChart.highlightValue(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getX(), 0, index); + //((TextView) findViewById(R.id.timestampHightlight)).setText(getDate()); } @Override @@ -379,10 +387,9 @@ public class CurrencyDetailsActivity extends AppCompatActivity { public boolean onTouch(View view, MotionEvent motionEvent) { if(motionEvent.getAction() == MotionEvent.ACTION_UP) { - //lineChart.highlightValue(lineChart.getData().getDataSetCount()-1, 0); lineChart.highlightValue(null); updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY()); - + barChart.highlightValues(null); } return false; } @@ -394,6 +401,18 @@ public class CurrencyDetailsActivity extends AppCompatActivity { findViewById(R.id.progressLayoutChart).setVisibility(View.GONE); } + private String getDate(long timeStamp){ + + try{ + SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); + Date netDate = (new Date(timeStamp)); + return sdf.format(netDate); + } + catch(Exception ex){ + return "xx"; + } + } + private BarData generateVolumeChartSet(int timeUnit, int amount) { BarDataSet dataSet; @@ -437,13 +456,16 @@ public class CurrencyDetailsActivity extends AppCompatActivity { break; } - int offset = (int) Math.floor(dataChartList.size() / 50); + int offset = (int) Math.floor(dataChartList.size() / 200); - int loopNumber = 0; - for(int i = 0; i < dataChartList.size(); i += offset) + if(offset < 1) { - values.add(new BarEntry(loopNumber, (float) dataChartList.get(i).getVolumeTo())); - loopNumber++; + offset = 1; + } + + for(int i = 0, j = 0; i < dataChartList.size(); i += offset, j++) + { + values.add(new BarEntry(j, (float) dataChartList.get(i).getVolumeFrom())); } dataSet = new BarDataSet(values, "Volume"); @@ -527,8 +549,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity { break; } - for(int i = 0; i < dataChartList.size(); i++) - { + /*for(int i = 0; i < dataChartList.size(); i++) + {*/ /*if(counter == offset) { calendar.setTimeInMillis(dataChartList.get(i).getTimestamp()*1000); @@ -650,7 +672,19 @@ public class CurrencyDetailsActivity extends AppCompatActivity { counter++; lineSet.addPoint("", (float) dataChartList.get(i).getOpen()); }*/ - values.add(new Entry(i, (float) dataChartList.get(i).getOpen())); + /*values.add(new Entry(i, (float) dataChartList.get(i).getOpen())); + }*/ + + int offsetRange = (int) Math.floor(dataChartList.size() / 200); + + if(offsetRange < 1) + { + offsetRange = 1; + } + + for(int i = 0, j = 0; i < dataChartList.size(); i += offsetRange, j++) + { + values.add(new Entry(j, (float) dataChartList.get(i).getOpen())); } dataSet = new LineDataSet(values, "History"); @@ -667,6 +701,10 @@ public class CurrencyDetailsActivity extends AppCompatActivity { dataSet.setDrawHorizontalHighlightIndicator(false); dataSet.setHighLightColor(currency.getChartColor()); + Drawable fillDrawable = ContextCompat.getDrawable(this, R.drawable.linear_chart_gradient); + fillDrawable.setColorFilter(getColorWithAlpha(currency.getChartColor(), 0.5f), PorterDuff.Mode.SRC_ATOP); + //dataSet.setFillDrawable(fillDrawable); + return new LineData(dataSet); } diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java index 8fea2be..1f96930 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java @@ -43,6 +43,11 @@ public class CurrencyDataChart implements Parcelable { return volumeTo; } + public double getVolumeFrom() + { + return volumeFrom; + } + public long getTimestamp() { return timestamp; diff --git a/app/src/main/res/drawable/linear_chart_gradient.xml b/app/src/main/res/drawable/linear_chart_gradient.xml new file mode 100644 index 0000000..5222848 --- /dev/null +++ b/app/src/main/res/drawable/linear_chart_gradient.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_currency_details.xml b/app/src/main/res/layout/activity_currency_details.xml index 92892ff..3137af2 100644 --- a/app/src/main/res/layout/activity_currency_details.xml +++ b/app/src/main/res/layout/activity_currency_details.xml @@ -42,6 +42,34 @@ android:layout_height="250dp" android:layout_marginTop="15dp" /> + + + + + + + + + + + android:orientation="vertical"> Date: Wed, 4 Apr 2018 01:16:10 +0200 Subject: [PATCH 08/34] Several improvements - Add time/date pickers - Add time for manual transactions recording - Add time for manual transactions listing - Add volume hightlight with price highlight - Cleaning up of CurrencyDetailsActivity code --- app/build.gradle | 1 + .../Activities/CurrencyDetailsActivity.java | 721 ++++++------------ .../coinfolio/Activities/HomeActivity.java | 2 + .../Activities/RecordTransactionActivity.java | 69 +- .../CurrencyData/Transaction.java | 9 +- .../DataManagers/DatabaseManager.java | 9 +- .../ExchangeManager/BinanceManager.java | 5 + .../layout/activity_record_transaction.xml | 9 + app/src/main/res/values/strings.xml | 1 + 9 files changed, 328 insertions(+), 498 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6a810b4..d3fd690 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -42,6 +42,7 @@ dependencies { implementation 'org.apache.commons:commons-lang3:3.6' implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3' implementation 'com.mattprecious.swirl:swirl:1.1.0' + implementation 'com.wdullaer:materialdatetimepicker:3.5.2' //implementation 'com.github.lecho:hellocharts-library:1.5.8@aar' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' 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 d176ff9..f8bfc50 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -61,14 +61,12 @@ public class CurrencyDetailsActivity extends AppCompatActivity { //private String symbol; private Currency currency; private boolean hasBeenModified; - private Tooltip tip; - private int indexMax; - private int indexMin; private final static int HOUR = 0; private final static int DAY = 1; private final static int WEEK = 2; private final static int MONTH = 3; private final static int YEAR = 4; + private List dataChartList; private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() { @@ -103,7 +101,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { - // Respond to the action bar's Up/Home button case android.R.id.home: NavUtils.navigateUpFromSameTask(this); return true; @@ -118,7 +115,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity { Intent intent = getIntent(); - //symbol = intent.getStringExtra("symbol"); currency = intent.getParcelableExtra("currency"); databaseManager = new DatabaseManager(this); @@ -131,23 +127,9 @@ public class CurrencyDetailsActivity extends AppCompatActivity { initializeButtons(); - if(currency.getHistoryMinutes().size() > 0) - { - drawPriceChart(DAY, 1); - drawVolumeChart(DAY, 1); - } - else - { - /*TextView errorTextView = new TextView(this); - errorTextView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 750)); - errorTextView.setText("Not enough data"); - errorTextView.setTag("chart_layout"); - errorTextView.setGravity(Gravity.CENTER); + createCharts(DAY, 1); - chartLayout.addView(errorTextView, 0);*/ - } - - setTitle(" " + currency.getName()); + setTitle(" " + currency.getName() + " | " + currency.getBalance()); getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_USE_LOGO); @@ -222,16 +204,13 @@ public class CurrencyDetailsActivity extends AppCompatActivity { switch (interval) { case "1h": - drawPriceChart(HOUR, 1); - drawVolumeChart(HOUR, 1); + createCharts(HOUR, 1); break; case "3h": - drawPriceChart(HOUR, 3); - drawVolumeChart(HOUR, 3); + createCharts(HOUR, 3); break; case "1d": - drawPriceChart(DAY, 1); - drawVolumeChart(DAY, 1); + createCharts(DAY, 1); break; case "3d": currency.updateHistoryHours(this, new Currency.CurrencyCallBack() { @@ -240,8 +219,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - drawPriceChart(CurrencyDetailsActivity.DAY, 3); - drawVolumeChart(CurrencyDetailsActivity.DAY, 3); + createCharts(CurrencyDetailsActivity.DAY, 3); } }); } @@ -254,8 +232,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - drawPriceChart(CurrencyDetailsActivity.WEEK, 1); - drawVolumeChart(CurrencyDetailsActivity.WEEK, 1); + createCharts(CurrencyDetailsActivity.WEEK, 11); } }); } @@ -268,8 +245,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - drawPriceChart(CurrencyDetailsActivity.MONTH, 1); - drawVolumeChart(CurrencyDetailsActivity.MONTH, 1); + createCharts(CurrencyDetailsActivity.MONTH, 1); } }); } @@ -282,8 +258,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - drawPriceChart(CurrencyDetailsActivity.MONTH, 3); - drawVolumeChart(CurrencyDetailsActivity.MONTH, 3); + createCharts(CurrencyDetailsActivity.MONTH, 3); } }); } @@ -296,8 +271,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - drawPriceChart(CurrencyDetailsActivity.MONTH, 6); - drawVolumeChart(CurrencyDetailsActivity.MONTH, 6); + createCharts(CurrencyDetailsActivity.MONTH, 6); } }); } @@ -310,8 +284,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - drawPriceChart(CurrencyDetailsActivity.YEAR, 1); - drawVolumeChart(CurrencyDetailsActivity.YEAR, 1); + createCharts(CurrencyDetailsActivity.YEAR, 1); } }); } @@ -320,7 +293,56 @@ public class CurrencyDetailsActivity extends AppCompatActivity { } } - private void drawVolumeChart(int timeUnit, int amout) + private void createCharts(int timeUnit, int amount) + { + updateChartsData(timeUnit, amount); + drawPriceChart(); + drawVolumeChart(); + } + + private void updateChartsData(int timeUnit, int amount) + { + dataChartList = new ArrayList<>(); + + switch (timeUnit) + { + case HOUR: + dataChartList = currency.getHistoryMinutes().subList(currency.getHistoryMinutes().size()-(60*amount), currency.getHistoryMinutes().size()); + break; + case DAY: + if(amount == 1) + { + dataChartList = currency.getHistoryMinutes(); + } + else + { + dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-(24*amount), currency.getHistoryHours().size()); + } + break; + case WEEK: + dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-168, currency.getHistoryHours().size()); + break; + case MONTH: + switch (amount) + { + case 1: + dataChartList = currency.getHistoryHours(); + break; + case 3: + dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-93, currency.getHistoryDays().size()); + break; + case 6: + dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-186, currency.getHistoryDays().size()); + break; + } + break; + case YEAR: + dataChartList = currency.getHistoryDays(); + break; + } + } + + private void drawVolumeChart() { final BarChart barChart = findViewById(R.id.chartVolumeView); @@ -339,13 +361,13 @@ public class CurrencyDetailsActivity extends AppCompatActivity { barChart.setViewPortOffsets(0, 0, 0, 0); barChart.setFitBars(true); - barChart.setData(generateVolumeChartSet(timeUnit, amout)); + barChart.setData(generateVolumeChartSet()); barChart.invalidate(); findViewById(R.id.chartVolumeView).setVisibility(View.VISIBLE); } - private void drawPriceChart(int timeUnit, int amout) + private void drawPriceChart() { final LineChart lineChart = findViewById(R.id.chartPriceView); final BarChart barChart = findViewById(R.id.chartVolumeView); @@ -364,16 +386,32 @@ public class CurrencyDetailsActivity extends AppCompatActivity { lineChart.getXAxis().setEnabled(false); lineChart.setViewPortOffsets(0, 0, 0, 0); - lineChart.setData(generatePriceChartSet(timeUnit, amout)); + lineChart.setData(generatePriceChartSet()); lineChart.getAxisLeft().setAxisMinValue(lineChart.getData().getYMin()); lineChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { @Override public void onValueSelected(Entry e, Highlight h) { - updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), e.getY()); + //updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), e.getY()); int index = lineChart.getData().getDataSets().get(0).getEntryIndex(e); + String date = null; barChart.highlightValue(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getX(), 0, index); - //((TextView) findViewById(R.id.timestampHightlight)).setText(getDate()); + findViewById(R.id.volumeHightlight).setVisibility(View.VISIBLE); + findViewById(R.id.priceHightlight).setVisibility(View.VISIBLE); + findViewById(R.id.timestampHightlight).setVisibility(View.VISIBLE); + + if(dataChartList.size() > 200) + { + date = getDate(dataChartList.get((int) Math.floor(dataChartList.size() / 200) * index).getTimestamp() * 1000); + } + else + { + date = getDate(dataChartList.get(index).getTimestamp() * 1000); + } + + ((TextView) findViewById(R.id.volumeHightlight)).setText("Volume : US$" + barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY()); + ((TextView) findViewById(R.id.priceHightlight)).setText("Price : US$" + e.getY()); + ((TextView) findViewById(R.id.timestampHightlight)).setText("Date : " + date); } @Override @@ -390,6 +428,9 @@ public class CurrencyDetailsActivity extends AppCompatActivity { lineChart.highlightValue(null); updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY()); barChart.highlightValues(null); + findViewById(R.id.volumeHightlight).setVisibility(View.INVISIBLE); + findViewById(R.id.priceHightlight).setVisibility(View.INVISIBLE); + findViewById(R.id.timestampHightlight).setVisibility(View.INVISIBLE); } return false; } @@ -404,7 +445,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private String getDate(long timeStamp){ try{ - SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); + SimpleDateFormat sdf = new SimpleDateFormat(" HH:mm dd/MM/yyyy"); Date netDate = (new Date(timeStamp)); return sdf.format(netDate); } @@ -413,49 +454,11 @@ public class CurrencyDetailsActivity extends AppCompatActivity { } } - private BarData generateVolumeChartSet(int timeUnit, int amount) + private BarData generateVolumeChartSet() { BarDataSet dataSet; - List dataChartList = new ArrayList<>(); ArrayList values = new ArrayList<>(); - switch (timeUnit) - { - case HOUR: - dataChartList = currency.getHistoryMinutes().subList(currency.getHistoryMinutes().size()-(60*amount), currency.getHistoryMinutes().size()); - break; - case DAY: - if(amount == 1) - { - dataChartList = currency.getHistoryMinutes(); - } - else - { - dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-(24*amount), currency.getHistoryHours().size()); - } - break; - case WEEK: - dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-168, currency.getHistoryHours().size()); - break; - case MONTH: - switch (amount) - { - case 1: - dataChartList = currency.getHistoryHours(); - break; - case 3: - dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-93, currency.getHistoryDays().size()); - break; - case 6: - dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-186, currency.getHistoryDays().size()); - break; - } - break; - case YEAR: - dataChartList = currency.getHistoryDays(); - break; - } - int offset = (int) Math.floor(dataChartList.size() / 200); if(offset < 1) @@ -465,7 +468,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { for(int i = 0, j = 0; i < dataChartList.size(); i += offset, j++) { - values.add(new BarEntry(j, (float) dataChartList.get(i).getVolumeFrom())); + values.add(new BarEntry(j, (float) dataChartList.get(i).getVolumeTo())); } dataSet = new BarDataSet(values, "Volume"); @@ -478,78 +481,154 @@ public class CurrencyDetailsActivity extends AppCompatActivity { return new BarData(dataSet); } - private LineData generatePriceChartSet(int timeUnit, int amount) + private LineData generatePriceChartSet() { LineDataSet dataSet; - List dataChartList = new ArrayList<>(); ArrayList values = new ArrayList<>(); - int counter = 0; - Calendar calendar = Calendar.getInstance(Locale.FRANCE); - String hour; - String minute; - String dayName = ""; - String dayNumber; - String monthName = ""; - String monthNumber; - int offset = 10; - int pointFormat = HOUR; + int offsetRange = (int) Math.floor(dataChartList.size() / 200); - switch (timeUnit) + if(offsetRange < 1) { - case HOUR: - dataChartList = currency.getHistoryMinutes().subList(currency.getHistoryMinutes().size()-(60*amount), currency.getHistoryMinutes().size()); - offset = 10 * amount; - pointFormat = HOUR; - break; - case DAY: - if(amount == 1) - { - dataChartList = currency.getHistoryMinutes(); - offset = 10 * 24; - pointFormat = HOUR; - } - else - { - dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-(24*amount), currency.getHistoryHours().size()); - offset = 24; - pointFormat = DAY; - } - break; - case WEEK: - dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-168, currency.getHistoryHours().size()); - offset = 28; - pointFormat = DAY; - break; - case MONTH: - switch (amount) - { - case 1: - dataChartList = currency.getHistoryHours(); - Log.d("coinfolio", "1 month"); - offset = 124; - pointFormat = MONTH; - break; - case 3: - dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-93, currency.getHistoryDays().size()); - offset = 15; - pointFormat = MONTH; - break; - case 6: - dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-186, currency.getHistoryDays().size()); - offset = 31; - pointFormat = MONTH; - break; - } - break; - case YEAR: - dataChartList = currency.getHistoryDays(); - offset = 30; - pointFormat = YEAR; - break; + offsetRange = 1; } - /*for(int i = 0; i < dataChartList.size(); i++) + for(int i = 0, j = 0; i < dataChartList.size(); i += offsetRange, j++) + { + values.add(new Entry(j, (float) dataChartList.get(i).getOpen())); + } + + dataSet = new LineDataSet(values, "History"); + dataSet.setDrawIcons(false); + dataSet.setColor(currency.getChartColor()); + dataSet.setLineWidth(1); + dataSet.setDrawFilled(true); + dataSet.setFillColor(getColorWithAlpha(currency.getChartColor(), 0.5f)); + dataSet.setFormLineWidth(1); + dataSet.setFormSize(15); + dataSet.setDrawCircles(false); + dataSet.setDrawValues(false); + dataSet.setHighlightEnabled(true); + dataSet.setDrawHorizontalHighlightIndicator(false); + dataSet.setHighLightColor(currency.getChartColor()); + + Drawable fillDrawable = ContextCompat.getDrawable(this, R.drawable.linear_chart_gradient); + fillDrawable.setColorFilter(getColorWithAlpha(currency.getChartColor(), 0.5f), PorterDuff.Mode.SRC_ATOP); + //dataSet.setFillDrawable(fillDrawable); + + return new LineData(dataSet); + } + + private void updateFluctuation(float start, float end) + { + float fluctuation = end - start; + float percentageFluctuation = (float) (fluctuation / start * 100); + + if(percentageFluctuation < 0) + { + ((TextView) findViewById(R.id.txtViewPercentage)).setTextColor(getResources().getColor(R.color.red)); + } + else + { + ((TextView) findViewById(R.id.txtViewPercentage)).setTextColor(getResources().getColor(R.color.green)); + } + + ((TextView) findViewById(R.id.txtViewPriceStart)).setText("$" + start); + ((TextView) findViewById(R.id.txtViewPriceNow)).setText("$" + end); + ((TextView) findViewById(R.id.txtViewPercentage)).setText(percentageFluctuation + "%"); + } + + private int getColorWithAlpha(int color, float ratio) + { + int transColor; + int alpha = Math.round(Color.alpha(color) * ratio); + int r = Color.red(color); + int g = Color.green(color); + int b = Color.blue(color); + + transColor = Color.argb(alpha, r, g, b); + + return transColor; + } + + private void drawTransactionList() + { + transactionLayout.removeAllViews(); + + List transactionList = databaseManager.getCurrencyTransactions(currency.getSymbol()); + + for(int i = 0; i < transactionList.size(); i++) + { + View view = LayoutInflater.from(this).inflate(R.layout.custom_transaction_row, null); + TextView amountTxtView = view.findViewById(R.id.amountPurchased); + 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); + deleteLayout.setTag(transactionList.get(i).getTransactionId()); + + deleteLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + databaseManager.deleteTransactionFromId(Integer.parseInt(view.getTag().toString())); + drawTransactionList(); + hasBeenModified = true; + } + }); + + amountTxtView.setText(transactionList.get(i).getAmount() + ""); + + SwipeLayout swipeLayout = view.findViewById(R.id.swipeLayout); + + //set show mode. + swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown); + + //add drag edge.(If the BottomView has 'layout_gravity' attribute, this line is unnecessary) + swipeLayout.addDrag(SwipeLayout.DragEdge.Left, view.findViewById(R.id.bottom_wrapper)); + + swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() { + @Override + public void onClose(SwipeLayout layout) { + //when the SurfaceView totally cover the BottomView. + } + + @Override + public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) { + //you are swiping. + } + + @Override + public void onStartOpen(SwipeLayout layout) { + + } + + @Override + public void onOpen(SwipeLayout layout) { + //when the BottomView totally show. + } + + @Override + public void onStartClose(SwipeLayout layout) { + + } + + @Override + public void onHandRelease(SwipeLayout layout, float xvel, float yvel) { + //when user's hand released. + } + }); + + transactionLayout.addView(view); + } + + } + +} +/*for(int i = 0; i < dataChartList.size(); i++) {*/ /*if(counter == offset) { @@ -673,344 +752,4 @@ public class CurrencyDetailsActivity extends AppCompatActivity { lineSet.addPoint("", (float) dataChartList.get(i).getOpen()); }*/ /*values.add(new Entry(i, (float) dataChartList.get(i).getOpen())); - }*/ - - int offsetRange = (int) Math.floor(dataChartList.size() / 200); - - if(offsetRange < 1) - { - offsetRange = 1; - } - - for(int i = 0, j = 0; i < dataChartList.size(); i += offsetRange, j++) - { - values.add(new Entry(j, (float) dataChartList.get(i).getOpen())); - } - - dataSet = new LineDataSet(values, "History"); - dataSet.setDrawIcons(false); - dataSet.setColor(currency.getChartColor()); - dataSet.setLineWidth(1); - dataSet.setDrawFilled(true); - dataSet.setFillColor(getColorWithAlpha(currency.getChartColor(), 0.5f)); - dataSet.setFormLineWidth(1); - dataSet.setFormSize(15); - dataSet.setDrawCircles(false); - dataSet.setDrawValues(false); - dataSet.setHighlightEnabled(true); - dataSet.setDrawHorizontalHighlightIndicator(false); - dataSet.setHighLightColor(currency.getChartColor()); - - Drawable fillDrawable = ContextCompat.getDrawable(this, R.drawable.linear_chart_gradient); - fillDrawable.setColorFilter(getColorWithAlpha(currency.getChartColor(), 0.5f), PorterDuff.Mode.SRC_ATOP); - //dataSet.setFillDrawable(fillDrawable); - - return new LineData(dataSet); - } - - private void updateFluctuation(float start, float end) - { - float fluctuation = end - start; - float percentageFluctuation = (float) (fluctuation / start * 100); - - if(percentageFluctuation < 0) - { - ((TextView) findViewById(R.id.txtViewPercentage)).setTextColor(getResources().getColor(R.color.red)); - } - else - { - ((TextView) findViewById(R.id.txtViewPercentage)).setTextColor(getResources().getColor(R.color.green)); - } - - ((TextView) findViewById(R.id.txtViewPriceStart)).setText("$" + start); - ((TextView) findViewById(R.id.txtViewPriceNow)).setText("$" + end); - ((TextView) findViewById(R.id.txtViewPercentage)).setText(percentageFluctuation + "%"); - } - - /*private LineSet generatePriceChartSet(int timeUnit, int amount) - { - List dataChartList = new ArrayList<>(); - LineSet lineSet = new LineSet(); - int counter = 0; - Calendar calendar = Calendar.getInstance(Locale.FRANCE); - String hour; - String minute; - String dayName = ""; - String dayNumber; - String monthName = ""; - String monthNumber; - int offset = 10; - int pointFormat = HOUR; - - switch (timeUnit) - { - case HOUR: - dataChartList = currency.getHistoryMinutes().subList(currency.getHistoryMinutes().size()-(60*amount), currency.getHistoryMinutes().size()); - offset = 10 * amount; - pointFormat = HOUR; - break; - case DAY: - if(amount == 1) - { - dataChartList = currency.getHistoryMinutes(); - offset = 10 * 24; - pointFormat = HOUR; - } - else - { - dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-(24*amount), currency.getHistoryHours().size()); - offset = 24; - pointFormat = DAY; - } - break; - case WEEK: - dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-168, currency.getHistoryHours().size()); - offset = 28; - pointFormat = DAY; - break; - case MONTH: - switch (amount) - { - case 1: - dataChartList = currency.getHistoryHours(); - offset = 124; - pointFormat = MONTH; - break; - case 3: - dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-93, currency.getHistoryDays().size()); - offset = 15; - pointFormat = MONTH; - break; - case 6: - dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-186, currency.getHistoryDays().size()); - offset = 31; - pointFormat = MONTH; - break; - } - break; - case YEAR: - dataChartList = currency.getHistoryDays(); - offset = 30; - pointFormat = YEAR; - break; - } - - for(int i = 0; i < dataChartList.size(); i++) - { - if(counter == offset) - { - calendar.setTimeInMillis(dataChartList.get(i).getTimestamp()*1000); - - switch (pointFormat) - { - case HOUR: - hour = String.valueOf(calendar.get(Calendar.HOUR_OF_DAY)); - minute = String.valueOf(calendar.get(Calendar.MINUTE)); - - if(hour.length() < 2) - { - hour = "0" + hour; - } - - if(minute.length() < 2) - { - minute = "0" + minute; - } - - lineSet.addPoint(hour + ":" + minute, (float) dataChartList.get(i).getOpen()); - break; - case DAY: - int dayIndex = calendar.get(Calendar.DAY_OF_WEEK)+1; - - switch (dayIndex) - { - case Calendar.MONDAY: - dayName = "Mon"; - break; - case Calendar.TUESDAY: - dayName = "Tue"; - break; - case Calendar.WEDNESDAY: - dayName = "Wed"; - break; - case Calendar.THURSDAY: - dayName = "Thu"; - break; - case Calendar.FRIDAY: - dayName = "Fri"; - break; - case Calendar.SATURDAY: - dayName = "Sat"; - break; - case Calendar.SUNDAY: - dayName = "Sun"; - break; - } - - lineSet.addPoint(dayName, (float) dataChartList.get(i).getOpen()); - break; - case MONTH: - dayNumber = String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)+1); - monthNumber = String.valueOf(calendar.get(Calendar.MONTH)+1); - - if(dayNumber.length() < 2) - { - dayNumber = '0' + dayNumber; - } - - if(monthNumber.length() < 2) - { - monthNumber = '0' + monthNumber; - } - - lineSet.addPoint(dayNumber + "/" + monthNumber, (float) dataChartList.get(i).getOpen()); - break; - case YEAR: - int mb = calendar.get(Calendar.MONTH); - - switch (mb) - { - case Calendar.JANUARY: - monthName = "Jan"; - break; - case Calendar.FEBRUARY: - monthName = "Feb"; - break; - case Calendar.MARCH: - monthName = "Mar"; - break; - case Calendar.APRIL: - monthName = "Apr"; - break; - case Calendar.MAY: - monthName = "May"; - break; - case Calendar.JUNE: - monthName = "Jun"; - break; - case Calendar.JULY: - monthName = "Jul"; - break; - case Calendar.AUGUST: - monthName = "Aug"; - break; - case Calendar.SEPTEMBER: - monthName = "Sep"; - break; - case Calendar.OCTOBER: - monthName = "Oct"; - break; - case Calendar.NOVEMBER: - monthName = "Nov"; - break; - case Calendar.DECEMBER: - monthName = "Dec"; - break; - } - - lineSet.addPoint(monthName, (float) dataChartList.get(i).getOpen()); - break; - } - counter = 0; - } - else - { - counter++; - lineSet.addPoint("", (float) dataChartList.get(i).getOpen()); - } - } - - lineSet.setSmooth(true); - lineSet.setThickness(3); - lineSet.setFill(getColorWithAlpha(currency.getChartColor(), 0.5f)); - lineSet.setColor(currency.getChartColor()); - - return lineSet; - }*/ - - private int getColorWithAlpha(int color, float ratio) - { - int transColor; - int alpha = Math.round(Color.alpha(color) * ratio); - int r = Color.red(color); - int g = Color.green(color); - int b = Color.blue(color); - - transColor = Color.argb(alpha, r, g, b); - - return transColor; - } - - private void drawTransactionList() - { - transactionLayout.removeAllViews(); - - List transactionList = databaseManager.getCurrencyTransactions(currency.getSymbol()); - - for(int i = 0; i < transactionList.size(); i++) - { - View view = LayoutInflater.from(this).inflate(R.layout.custom_transaction_row, null); - TextView amountTxtView = view.findViewById(R.id.amountPurchased); - TextView valueTxtView = view.findViewById(R.id.puchasedValue); - TextView dateTxtView = view.findViewById(R.id.purchaseDate); - - LinearLayout deleteLayout = view.findViewById(R.id.deleteTransactionLayout); - deleteLayout.setTag(transactionList.get(i).getTransactionId()); - - deleteLayout.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - databaseManager.deleteTransactionFromId(Integer.parseInt(view.getTag().toString())); - drawTransactionList(); - hasBeenModified = true; - } - }); - - amountTxtView.setText(transactionList.get(i).getAmount() + ""); - - SwipeLayout swipeLayout = view.findViewById(R.id.swipeLayout); - - //set show mode. - swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown); - - //add drag edge.(If the BottomView has 'layout_gravity' attribute, this line is unnecessary) - swipeLayout.addDrag(SwipeLayout.DragEdge.Left, view.findViewById(R.id.bottom_wrapper)); - - swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() { - @Override - public void onClose(SwipeLayout layout) { - //when the SurfaceView totally cover the BottomView. - } - - @Override - public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) { - //you are swiping. - } - - @Override - public void onStartOpen(SwipeLayout layout) { - - } - - @Override - public void onOpen(SwipeLayout layout) { - //when the BottomView totally show. - } - - @Override - public void onStartClose(SwipeLayout layout) { - - } - - @Override - public void onHandRelease(SwipeLayout layout, float xvel, float yvel) { - //when user's hand released. - } - }); - - transactionLayout.addView(view); - } - - } - -} + }*/ \ No newline at end of file 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 53f604b..fa11d1b 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -398,6 +398,8 @@ public class HomeActivity extends AppCompatActivity { Intent intent = getIntent(); + Log.d("coinfolio", "Updated ? " + intent.getBooleanExtra("update", false)); + updateAll(intent.getBooleanExtra("update", false)); ((SpaceNavigationView) findViewById(R.id.space)).changeCenterButtonIcon(R.drawable.ic_view_list_white_24dp); } diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java index aa07931..f30af5f 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java @@ -1,23 +1,35 @@ package com.nauk.coinfolio.Activities; +import android.app.DatePickerDialog; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.util.Log; import android.view.View; import android.widget.Button; +import android.widget.DatePicker; +import android.widget.EditText; import android.widget.TextView; +import android.widget.TimePicker; import com.nauk.coinfolio.DataManagers.DatabaseManager; import com.nauk.coinfolio.R; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + public class RecordTransactionActivity extends AppCompatActivity { private String coin; private String symbol; private TextView symbolTxtView; - private TextView amountTxtView; + private EditText amountTxtView; + private TextView purchasedDate; private Button validateButton; private DatabaseManager databaseManager; + private Calendar calendar; + private SimpleDateFormat sdf; @Override protected void onCreate(Bundle savedInstanceState) { @@ -30,16 +42,31 @@ public class RecordTransactionActivity extends AppCompatActivity { setTitle("Add " + coin + " transaction"); + sdf = new SimpleDateFormat(" HH:mm dd/MM/yyyy"); + + calendar = Calendar.getInstance(); + databaseManager = new DatabaseManager(this); validateButton = findViewById(R.id.validateButton); amountTxtView = findViewById(R.id.currencyAmount); + purchasedDate = findViewById(R.id.purchaseDate); + + purchasedDate.setText(sdf.format(calendar.getTime())); + + purchasedDate.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + createDatePicker(); + } + }); + validateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - databaseManager.addCurrencyToManualCurrency(symbol, Double.parseDouble(amountTxtView.getText().toString())); + databaseManager.addCurrencyToManualCurrency(symbol, Double.parseDouble(amountTxtView.getText().toString()), calendar.getTime()); Intent intent = new Intent(RecordTransactionActivity.this, HomeActivity.class); intent.putExtra("update", true); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); @@ -48,4 +75,42 @@ public class RecordTransactionActivity extends AppCompatActivity { } }); } + + private void createDatePicker() + { + new android.app.DatePickerDialog( + RecordTransactionActivity.this, + new android.app.DatePickerDialog.OnDateSetListener() { + @Override + public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { + calendar.set(Calendar.YEAR, year); + calendar.set(Calendar.MONTH, month); + calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); + purchasedDate.setText(sdf.format(calendar.getTime())); + createTimePicker(); + } + }, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ).show(); + } + + private void createTimePicker() + { + new android.app.TimePickerDialog( + RecordTransactionActivity.this, + new android.app.TimePickerDialog.OnTimeSetListener() { + @Override + public void onTimeSet(TimePicker view, int hour, int minute) { + calendar.set(Calendar.HOUR_OF_DAY, hour); + calendar.set(Calendar.MINUTE, minute); + purchasedDate.setText(sdf.format(calendar.getTime())); + } + }, + calendar.get(Calendar.HOUR_OF_DAY), + calendar.get(Calendar.MINUTE), + true + ).show(); + } } diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Transaction.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Transaction.java index ac05f62..420092a 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Transaction.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Transaction.java @@ -9,14 +9,16 @@ public class Transaction { private int transactionId; private String symbol; private double amount; + private long timestamp; private double purchasedPrice; private boolean isMined; - public Transaction(int transactionId, String symbol, double amount) + public Transaction(int transactionId, String symbol, double amount, long timestamp) { this.transactionId = transactionId; this.symbol = symbol; this.amount = amount; + this.timestamp = timestamp; } public int getTransactionId() { @@ -39,6 +41,11 @@ public class Transaction { return amount; } + public long getTimestamp() + { + return timestamp; + } + public void setAmount(double amount) { this.amount = amount; } diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java index 4afe2df..82e566e 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java @@ -10,6 +10,7 @@ import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction; import java.util.ArrayList; +import java.util.Date; import java.util.List; /** @@ -51,7 +52,7 @@ public class DatabaseManager extends SQLiteOpenHelper{ + KEY_CURRENCY_SYMBOL + " VARCHAR(4)," + KEY_CURRENCY_NAME + " VARCHAR(45)," + KEY_CURRENCY_BALANCE + " TEXT," - + KEY_CURRENCY_DATE + " DATE," + + KEY_CURRENCY_DATE + " TEXT," + KEY_CURRENCY_PURCHASED_PRICE + " TEXT," + KEY_CURRENCY_IS_MINED + " INTEGER" + ");"); @@ -75,14 +76,14 @@ public class DatabaseManager extends SQLiteOpenHelper{ onCreate(db); } - public void addCurrencyToManualCurrency(String symbol, double balance) + public void addCurrencyToManualCurrency(String symbol, double balance, Date date) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_CURRENCY_SYMBOL, symbol); values.put(KEY_CURRENCY_BALANCE, balance); - //values.put(KEY_CURRENCY_DATE, getDate()); + values.put(KEY_CURRENCY_DATE, date.getTime()); //values.put(KEY_CURRENCY_PURCHASED_PRICE, something); db.insert(TABLE_MANUAL_CURRENCIES, null, values); @@ -122,7 +123,7 @@ public class DatabaseManager extends SQLiteOpenHelper{ while(resultatList.moveToNext()) { //transactionList.put(resultatList.getInt(0), resultatList.getDouble(3)); - transactionList.add(new Transaction(resultatList.getInt(0), resultatList.getString(1), resultatList.getDouble(3))); + transactionList.add(new Transaction(resultatList.getInt(0), resultatList.getString(1), resultatList.getDouble(3), resultatList.getLong(4))); } resultatList.close(); diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java index a035ca1..25544e5 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java @@ -56,6 +56,11 @@ public class BinanceManager { } } + public void getTrades() + { + + } + public void setPublicKey(String publicKey) { this.publicKey = publicKey; diff --git a/app/src/main/res/layout/activity_record_transaction.xml b/app/src/main/res/layout/activity_record_transaction.xml index 8054ae1..f9e21dd 100644 --- a/app/src/main/res/layout/activity_record_transaction.xml +++ b/app/src/main/res/layout/activity_record_transaction.xml @@ -22,7 +22,16 @@ android:layout_height="wrap_content" android:hint="@string/activity_add_amount"/> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 990ec9d..921c25c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -120,6 +120,7 @@ Amount Purchased price + Purchased date CurrencyDetailsActivity History charts Watchlist From 6e0657e5db19e46e6f2eb379e677335d15dfa479 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Wed, 4 Apr 2018 14:12:23 +0200 Subject: [PATCH 09/34] Code cleanup --- .idea/statistic.xml | 21 ++ .../Activities/CurrencyDetailsActivity.java | 244 +++++++------ .../Activities/CurrencySelectionActivity.java | 5 + .../coinfolio/Activities/HomeActivity.java | 322 +++++++++--------- .../Activities/RecordTransactionActivity.java | 2 - .../Activities/SettingsActivity.java | 1 - .../DataManagers/BalanceManager.java | 1 - .../CurrencyData/CurrencyDataChart.java | 14 +- .../CurrencyData/CurrencyDataRetriever.java | 58 ++-- .../DataManagers/DatabaseManager.java | 3 - .../ExchangeManager/BinanceManager.java | 3 - .../ExchangeManager/HitBtcManager.java | 55 +-- .../FingerprintDialogFragment.java | 2 - .../FingerprintHandler.java | 7 - .../LayoutManagers/CurrencyAdapter.java | 19 +- .../LayoutManagers/HomeLayoutGenerator.java | 111 +++--- 16 files changed, 468 insertions(+), 400 deletions(-) create mode 100644 .idea/statistic.xml diff --git a/.idea/statistic.xml b/.idea/statistic.xml new file mode 100644 index 0000000..66820b8 --- /dev/null +++ b/.idea/statistic.xml @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file 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 f8bfc50..60f924d 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -26,7 +26,6 @@ import android.widget.TextView; import android.widget.ViewFlipper; import com.daimajia.swipe.SwipeLayout; -import com.db.chart.tooltip.Tooltip; import com.github.mikephil.charting.charts.BarChart; import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.data.BarData; @@ -45,10 +44,8 @@ import com.nauk.coinfolio.R; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Calendar; import java.util.Date; import java.util.List; -import java.util.Locale; /**Create a Parcelable**/ @@ -67,6 +64,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private final static int MONTH = 3; private final static int YEAR = 4; private List dataChartList; + private LineChart lineChart; + private BarChart barChart; private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() { @@ -122,6 +121,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity { viewFlipper = findViewById(R.id.vfCurrencyDetails); transactionLayout = findViewById(R.id.listTransactions); chartLayout = findViewById(R.id.chartsLayout); + lineChart = findViewById(R.id.chartPriceView); + barChart = findViewById(R.id.chartVolumeView); drawTransactionList(); @@ -129,6 +130,16 @@ public class CurrencyDetailsActivity extends AppCompatActivity { createCharts(DAY, 1); + setupActionBar(); + + BottomNavigationView navigation = findViewById(R.id.navigation_details); + navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); + + hasBeenModified = false; + } + + private void setupActionBar() + { setTitle(" " + currency.getName() + " | " + currency.getBalance()); getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_USE_LOGO); @@ -145,10 +156,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity { getSupportActionBar().setIcon(new BitmapDrawable(Bitmap.createScaledBitmap(result, 120, 120, false))); - BottomNavigationView navigation = findViewById(R.id.navigation_details); - navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); - - hasBeenModified = false; } private void initializeButtons() @@ -185,7 +192,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { } } - chartEvent((Button) v); + updateCharts((Button) v); } private float convertDpToPx(float dp) @@ -193,7 +200,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { return dp * this.getResources().getDisplayMetrics().density; } - private void chartEvent(Button button) + private void updateCharts(Button button) { findViewById(R.id.chartPriceView).setVisibility(View.GONE); findViewById(R.id.chartVolumeView).setVisibility(View.GONE); @@ -344,8 +351,16 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private void drawVolumeChart() { - final BarChart barChart = findViewById(R.id.chartVolumeView); + initializeBarChart(barChart); + barChart.setData(generateVolumeChartSet()); + barChart.invalidate(); + + findViewById(R.id.chartVolumeView).setVisibility(View.VISIBLE); + } + + private void initializeBarChart(BarChart barChart) + { barChart.setDrawGridBackground(false); barChart.setDrawBorders(false); barChart.setDrawMarkers(true); @@ -360,18 +375,42 @@ public class CurrencyDetailsActivity extends AppCompatActivity { barChart.getXAxis().setEnabled(false); barChart.setViewPortOffsets(0, 0, 0, 0); barChart.setFitBars(true); - - barChart.setData(generateVolumeChartSet()); - barChart.invalidate(); - - findViewById(R.id.chartVolumeView).setVisibility(View.VISIBLE); } private void drawPriceChart() { - final LineChart lineChart = findViewById(R.id.chartPriceView); - final BarChart barChart = findViewById(R.id.chartVolumeView); + initializeLineChart(lineChart); + lineChart.setData(generatePriceChartSet()); + lineChart.getAxisLeft().setAxisMinValue(lineChart.getData().getYMin()); + + lineChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { + @Override + public void onValueSelected(Entry e, Highlight h) { + valueSelectedEvent(e); + } + + @Override + public void onNothingSelected() { + + } + }); + + lineChart.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + return toucheEvent(motionEvent); + } + }); + + updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY()); + + findViewById(R.id.chartPriceView).setVisibility(View.VISIBLE); + findViewById(R.id.progressLayoutChart).setVisibility(View.GONE); + } + + private void initializeLineChart(LineChart lineChart) + { lineChart.setDrawGridBackground(false); lineChart.setDrawBorders(false); lineChart.setDrawMarkers(true); @@ -385,61 +424,57 @@ public class CurrencyDetailsActivity extends AppCompatActivity { lineChart.getLegend().setEnabled(false); lineChart.getXAxis().setEnabled(false); lineChart.setViewPortOffsets(0, 0, 0, 0); + } - lineChart.setData(generatePriceChartSet()); - lineChart.getAxisLeft().setAxisMinValue(lineChart.getData().getYMin()); + private void valueSelectedEvent(Entry e) + { + //updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), e.getY()); + int index = lineChart.getData().getDataSets().get(0).getEntryIndex(e); + String date = null; + barChart.highlightValue(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getX(), 0, index); - lineChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { - @Override - public void onValueSelected(Entry e, Highlight h) { - //updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), e.getY()); - int index = lineChart.getData().getDataSets().get(0).getEntryIndex(e); - String date = null; - barChart.highlightValue(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getX(), 0, index); - findViewById(R.id.volumeHightlight).setVisibility(View.VISIBLE); - findViewById(R.id.priceHightlight).setVisibility(View.VISIBLE); - findViewById(R.id.timestampHightlight).setVisibility(View.VISIBLE); + if(dataChartList.size() > 200) + { + date = getDate(dataChartList.get((int) Math.floor(dataChartList.size() / 200) * index).getTimestamp() * 1000); + } + else + { + date = getDate(dataChartList.get(index).getTimestamp() * 1000); + } - if(dataChartList.size() > 200) - { - date = getDate(dataChartList.get((int) Math.floor(dataChartList.size() / 200) * index).getTimestamp() * 1000); - } - else - { - date = getDate(dataChartList.get(index).getTimestamp() * 1000); - } + displayDataIndicators(); - ((TextView) findViewById(R.id.volumeHightlight)).setText("Volume : US$" + barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY()); - ((TextView) findViewById(R.id.priceHightlight)).setText("Price : US$" + e.getY()); - ((TextView) findViewById(R.id.timestampHightlight)).setText("Date : " + date); - } + ((TextView) findViewById(R.id.volumeHightlight)).setText("Volume : US$" + barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY()); + ((TextView) findViewById(R.id.priceHightlight)).setText("Price : US$" + e.getY()); + ((TextView) findViewById(R.id.timestampHightlight)).setText("Date : " + date); - @Override - public void onNothingSelected() { + } - } - }); + private boolean toucheEvent(MotionEvent motionEvent) + { + if(motionEvent.getAction() == MotionEvent.ACTION_UP) + { + lineChart.highlightValue(null); + updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY()); + barChart.highlightValues(null); + hideDataIndicators(); + } - lineChart.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View view, MotionEvent motionEvent) { - if(motionEvent.getAction() == MotionEvent.ACTION_UP) - { - lineChart.highlightValue(null); - updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY()); - barChart.highlightValues(null); - findViewById(R.id.volumeHightlight).setVisibility(View.INVISIBLE); - findViewById(R.id.priceHightlight).setVisibility(View.INVISIBLE); - findViewById(R.id.timestampHightlight).setVisibility(View.INVISIBLE); - } - return false; - } - }); + return false; + } - updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY()); + private void displayDataIndicators() + { + findViewById(R.id.volumeHightlight).setVisibility(View.VISIBLE); + findViewById(R.id.priceHightlight).setVisibility(View.VISIBLE); + findViewById(R.id.timestampHightlight).setVisibility(View.VISIBLE); + } - findViewById(R.id.chartPriceView).setVisibility(View.VISIBLE); - findViewById(R.id.progressLayoutChart).setVisibility(View.GONE); + private void hideDataIndicators() + { + findViewById(R.id.volumeHightlight).setVisibility(View.INVISIBLE); + findViewById(R.id.priceHightlight).setVisibility(View.INVISIBLE); + findViewById(R.id.timestampHightlight).setVisibility(View.INVISIBLE); } private String getDate(long timeStamp){ @@ -514,7 +549,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity { Drawable fillDrawable = ContextCompat.getDrawable(this, R.drawable.linear_chart_gradient); fillDrawable.setColorFilter(getColorWithAlpha(currency.getChartColor(), 0.5f), PorterDuff.Mode.SRC_ATOP); - //dataSet.setFillDrawable(fillDrawable); return new LineData(dataSet); } @@ -582,49 +616,53 @@ public class CurrencyDetailsActivity extends AppCompatActivity { amountTxtView.setText(transactionList.get(i).getAmount() + ""); - SwipeLayout swipeLayout = view.findViewById(R.id.swipeLayout); - - //set show mode. - swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown); - - //add drag edge.(If the BottomView has 'layout_gravity' attribute, this line is unnecessary) - swipeLayout.addDrag(SwipeLayout.DragEdge.Left, view.findViewById(R.id.bottom_wrapper)); - - swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() { - @Override - public void onClose(SwipeLayout layout) { - //when the SurfaceView totally cover the BottomView. - } - - @Override - public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) { - //you are swiping. - } - - @Override - public void onStartOpen(SwipeLayout layout) { - - } - - @Override - public void onOpen(SwipeLayout layout) { - //when the BottomView totally show. - } - - @Override - public void onStartClose(SwipeLayout layout) { - - } - - @Override - public void onHandRelease(SwipeLayout layout, float xvel, float yvel) { - //when user's hand released. - } - }); + setupSwipeView(view); transactionLayout.addView(view); } + } + private void setupSwipeView(View view) + { + SwipeLayout swipeLayout = view.findViewById(R.id.swipeLayout); + + //set show mode. + swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown); + + //add drag edge.(If the BottomView has 'layout_gravity' attribute, this line is unnecessary) + swipeLayout.addDrag(SwipeLayout.DragEdge.Left, view.findViewById(R.id.bottom_wrapper)); + + swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() { + @Override + public void onClose(SwipeLayout layout) { + //when the SurfaceView totally cover the BottomView. + } + + @Override + public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) { + //you are swiping. + } + + @Override + public void onStartOpen(SwipeLayout layout) { + + } + + @Override + public void onOpen(SwipeLayout layout) { + //when the BottomView totally show. + } + + @Override + public void onStartClose(SwipeLayout layout) { + + } + + @Override + public void onHandRelease(SwipeLayout layout, float xvel, float yvel) { + //when user's hand released. + } + }); } } diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencySelectionActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencySelectionActivity.java index 364de08..17d2753 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencySelectionActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencySelectionActivity.java @@ -46,6 +46,11 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear setupList(); + setupSearchView(); + } + + private void setupSearchView() + { SearchView searchView = findViewById(R.id.search_bar); searchView.setIconifiedByDefault(false); 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 fa11d1b..3274f46 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -6,8 +6,6 @@ import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; -import android.graphics.Outline; -import android.graphics.Typeface; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; @@ -23,11 +21,7 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.graphics.Palette; import android.support.v7.widget.Toolbar; import android.text.SpannableString; -import android.text.style.ForegroundColorSpan; -import android.text.style.RelativeSizeSpan; -import android.text.style.StyleSpan; import android.util.Log; -import android.view.DragEvent; import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; @@ -35,22 +29,17 @@ import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; -import android.view.ViewOutlineProvider; -import android.view.Window; -import android.view.WindowManager; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.ViewFlipper; -import com.github.mikephil.charting.animation.Easing; import com.github.mikephil.charting.charts.PieChart; import com.github.mikephil.charting.data.PieData; import com.github.mikephil.charting.data.PieDataSet; import com.github.mikephil.charting.data.PieEntry; import com.github.mikephil.charting.formatter.PercentFormatter; -import com.github.mikephil.charting.utils.ColorTemplate; import com.luseen.spacenavigation.SpaceItem; import com.luseen.spacenavigation.SpaceNavigationView; import com.luseen.spacenavigation.SpaceOnClickListener; @@ -61,8 +50,6 @@ import com.nauk.coinfolio.DataManagers.PreferencesManager; import com.nauk.coinfolio.LayoutManagers.HomeLayoutGenerator; import com.nauk.coinfolio.R; -import org.w3c.dom.Text; - import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; @@ -74,7 +61,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Locale; -import java.util.Random; //Use WilliamChart for charts https://github.com/diogobernardino/WilliamChart @@ -149,7 +135,7 @@ public class HomeActivity extends AppCompatActivity { setContentView(R.layout.activity_currency_summary); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); - generateSplash(); + generateSplashScreen(); //Objects initialization preferencesManager = new PreferencesManager(this); @@ -195,12 +181,6 @@ public class HomeActivity extends AppCompatActivity { toolbarSubtitle.setText("US$0.00"); - /*BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation_home); - navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); - navigation.setSelectedItemId(R.id.navigation_view_list); - navigation.setFitsSystemWindows(true); - navigation.setItemBackgroundResource(R.color.colorAccent);*/ - //Events setup detailsButton.setOnClickListener(new View.OnClickListener() { @Override @@ -304,59 +284,66 @@ public class HomeActivity extends AppCompatActivity { spaceNavigationView.setSpaceOnClickListener(new SpaceOnClickListener() { @Override public void onCentreButtonClick() { - //Toast.makeText(MainActivity.this,"onCentreButtonClick", Toast.LENGTH_SHORT).show(); - ((FloatingActionButton) findViewById(R.id.floatingAddButton)).show(); - SpaceNavigationView nav = findViewById(R.id.space); - - nav.changeCurrentItem(-1); - - findViewById(R.id.toolbar_layout).setFocusable(true); - ((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(true, true); - findViewById(R.id.nestedScrollViewLayout).setNestedScrollingEnabled(true); - - findViewById(R.id.app_bar).setEnabled(true); - findViewById(R.id.toolbar_layout).setNestedScrollingEnabled(true); - findViewById(R.id.coordinatorLayout).setNestedScrollingEnabled(true); - - findViewById(R.id.switch_button).setVisibility(View.VISIBLE); - - viewFlipper.setDisplayedChild(1); + spaceNavigationCentreButtonEvent(); } @Override public void onItemClick(int itemIndex, String itemName) { - ((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide(); - ((SpaceNavigationView) findViewById(R.id.space)).setCentreButtonIcon(R.drawable.ic_view_list_white_24dp); - - //0 : Watchlist - //1 : Market cap - findViewById(R.id.toolbar_layout).setFocusable(false); - ((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(false, true); - findViewById(R.id.nestedScrollViewLayout).setNestedScrollingEnabled(false); - - findViewById(R.id.app_bar).setEnabled(false); - findViewById(R.id.toolbar_layout).setNestedScrollingEnabled(false); - findViewById(R.id.coordinatorLayout).setNestedScrollingEnabled(false); - - findViewById(R.id.switch_button).setVisibility(View.GONE); - - - - viewFlipper.setDisplayedChild(itemIndex * 2); - - if(itemIndex == 1) - { - ((PieChart) findViewById(R.id.marketCapPieChart)).animateX(1000); - } } @Override public void onItemReselected(int itemIndex, String itemName) { - //Toast.makeText(MainActivity.this, itemIndex + " " + itemName, Toast.LENGTH_SHORT).show(); + spaceNavigationItemEvent(itemIndex); } }); } + private void spaceNavigationCentreButtonEvent() + { + //Toast.makeText(MainActivity.this,"onCentreButtonClick", Toast.LENGTH_SHORT).show(); + ((FloatingActionButton) findViewById(R.id.floatingAddButton)).show(); + SpaceNavigationView nav = findViewById(R.id.space); + + nav.changeCurrentItem(-1); + + findViewById(R.id.toolbar_layout).setFocusable(true); + ((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(true, true); + findViewById(R.id.nestedScrollViewLayout).setNestedScrollingEnabled(true); + + findViewById(R.id.app_bar).setEnabled(true); + findViewById(R.id.toolbar_layout).setNestedScrollingEnabled(true); + findViewById(R.id.coordinatorLayout).setNestedScrollingEnabled(true); + + findViewById(R.id.switch_button).setVisibility(View.VISIBLE); + + viewFlipper.setDisplayedChild(1); + } + + private void spaceNavigationItemEvent(int itemIndex) + { + ((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide(); + ((SpaceNavigationView) findViewById(R.id.space)).setCentreButtonIcon(R.drawable.ic_view_list_white_24dp); + + //0 : Watchlist + //1 : Market cap + findViewById(R.id.toolbar_layout).setFocusable(false); + ((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(false, true); + findViewById(R.id.nestedScrollViewLayout).setNestedScrollingEnabled(false); + + findViewById(R.id.app_bar).setEnabled(false); + findViewById(R.id.toolbar_layout).setNestedScrollingEnabled(false); + findViewById(R.id.coordinatorLayout).setNestedScrollingEnabled(false); + + findViewById(R.id.switch_button).setVisibility(View.GONE); + + viewFlipper.setDisplayedChild(itemIndex * 2); + + if(itemIndex == 1) + { + ((PieChart) findViewById(R.id.marketCapPieChart)).animateX(1000); + } + } + @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); @@ -379,13 +366,24 @@ public class HomeActivity extends AppCompatActivity { protected void onResume() { super.onResume(); + //addTestWatchlistCardview(); + Intent intent = getIntent(); + updateAll(intent.getBooleanExtra("update", false)); + + ((SpaceNavigationView) findViewById(R.id.space)).changeCenterButtonIcon(R.drawable.ic_view_list_white_24dp); + } + + private void addTestWatchlistCardview() + { View view = LayoutInflater.from(this).inflate(R.layout.cardview_watchlist, null); + ((TextView) view.findViewById(R.id.currencyFluctuationPercentageTextView)).setText("3%"); ((TextView) view.findViewById(R.id.currencyFluctuationTextView)).setText("$3"); ((TextView) view.findViewById(R.id.currencyNameTextView)).setText("TanguyCoin"); ((TextView) view.findViewById(R.id.currencySymbolTextView)).setText("TGC"); ((TextView) view.findViewById(R.id.currencyValueTextView)).setText("$100"); + view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); view.setOnClickListener(new View.OnClickListener() { @Override @@ -394,14 +392,7 @@ public class HomeActivity extends AppCompatActivity { } }); - //((LinearLayout) findViewById(R.id.linearLayoutWatchlist)).addView(view); - - Intent intent = getIntent(); - - Log.d("coinfolio", "Updated ? " + intent.getBooleanExtra("update", false)); - - updateAll(intent.getBooleanExtra("update", false)); - ((SpaceNavigationView) findViewById(R.id.space)).changeCenterButtonIcon(R.drawable.ic_view_list_white_24dp); + ((LinearLayout) findViewById(R.id.linearLayoutWatchlist)).addView(view); } @Override @@ -455,7 +446,6 @@ public class HomeActivity extends AppCompatActivity { if(!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001 || currency.getHistoryMinutes() == null)) { - //currencyLayout.addView(layoutGenerator.getInfoLayout(currency)); currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed)); } } @@ -574,13 +564,10 @@ public class HomeActivity extends AppCompatActivity { { marketCapCounter = 0; - Log.d("coinfolio", "Start update market cap"); - marketCapManager.updateTopCurrencies(new MarketCapManager.VolleyCallBack() { @Override public void onSuccess() { - Log.d("coinfolio", "Top updated"); countCompletedMarketCapRequest(); } }); @@ -588,7 +575,6 @@ public class HomeActivity extends AppCompatActivity { marketCapManager.updateMarketCap(new MarketCapManager.VolleyCallBack() { @Override public void onSuccess() { - Log.d("coinfolio", "Marketcap updated"); countCompletedMarketCapRequest(); } }); @@ -610,8 +596,6 @@ public class HomeActivity extends AppCompatActivity { ArrayList colors = new ArrayList<>(); - PieChart pieChart = findViewById(R.id.marketCapPieChart); - float otherCurrenciesDominance = 0; for(Iterator i = marketCapManager.getDominance().keySet().iterator(); i.hasNext(); ) @@ -632,38 +616,47 @@ public class HomeActivity extends AppCompatActivity { PieData data = new PieData(set); data.setValueTextSize(10); data.setValueFormatter(new PercentFormatter()); - pieChart.setData(data); - pieChart.setDrawSlicesUnderHole(false); - pieChart.setUsePercentValues(true); - pieChart.setTouchEnabled(true); - pieChart.setEntryLabelColor(Color.parseColor("#FF000000")); - - pieChart.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View view, MotionEvent motionEvent) { - switch (motionEvent.getAction()) - { - case MotionEvent.ACTION_DOWN: - refreshLayout.setEnabled(false); - break; - case MotionEvent.ACTION_MOVE: - break; - default: - refreshLayout.setEnabled(true); - break; - } - return false; - } - }); - - pieChart.getDescription().setEnabled(false); - pieChart.getLegend().setEnabled(false); - pieChart.setCenterText(generateCenterSpannableText()); - pieChart.invalidate(); // refresh + setupPieChart(data); } } + private void setupPieChart(PieData data) + { + PieChart pieChart = findViewById(R.id.marketCapPieChart); + + pieChart.setData(data); + pieChart.setDrawSlicesUnderHole(false); + pieChart.setUsePercentValues(true); + pieChart.setTouchEnabled(true); + + pieChart.setEntryLabelColor(Color.parseColor("#FF000000")); + + pieChart.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + switch (motionEvent.getAction()) + { + case MotionEvent.ACTION_DOWN: + refreshLayout.setEnabled(false); + break; + case MotionEvent.ACTION_MOVE: + break; + default: + refreshLayout.setEnabled(true); + break; + } + return false; + } + }); + + pieChart.getDescription().setEnabled(false); + pieChart.getLegend().setEnabled(false); + pieChart.setCenterText(generateCenterSpannableText()); + pieChart.invalidate(); // refresh + + } + private void setupTextViewMarketCap() { DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.UK); @@ -679,8 +672,8 @@ public class HomeActivity extends AppCompatActivity { private SpannableString generateCenterSpannableText() { - SpannableString s = new SpannableString("Market Capitalization Dominance"); - return s; + SpannableString spannableString = new SpannableString("Market Capitalization Dominance"); + return spannableString; } private void countCoins(boolean isCoin, boolean isDetails) @@ -706,8 +699,6 @@ public class HomeActivity extends AppCompatActivity { { if(balanceManager.getTotalBalance().size() == 0) { - Log.d("coinfolio", "Empty"); - countIcons(); } } @@ -732,7 +723,7 @@ public class HomeActivity extends AppCompatActivity { } } - private void generateSplash() + private void generateSplashScreen() { LinearLayout loadingLayout = new LinearLayout(this); @@ -825,49 +816,40 @@ public class HomeActivity extends AppCompatActivity { super.onProgressUpdate(values); } - @Override - protected Void doInBackground(Void... params) + private void updateChartColor(Currency currency) { - final List cardList = new ArrayList<>(); - - Looper.prepare(); - - balanceManager.sortCoins(); - - for(int i = 0; i < balanceManager.getTotalBalance().size(); i++) + if(currency.getIcon() != null) { - final Currency localCurrency = balanceManager.getTotalBalance().get(i); + Palette.Builder builder = Palette.from(currency.getIcon()); - if(localCurrency.getIcon() != null) - { - Palette.Builder builder = Palette.from(localCurrency.getIcon()); + currency.setChartColor(builder.generate().getDominantColor(0)); + } + else + { + currency.setChartColor(12369084); + } + } - localCurrency.setChartColor(builder.generate().getDominantColor(0)); + private void loadCurrency(Currency currency, List cardList) + { + if(!currency.getSymbol().equals("USD") && (currency.getBalance() * currency.getValue()) > 0.001) + { + currency.setName(balanceManager.getCurrencyName(currency.getSymbol())); + currency.setId(balanceManager.getCurrencyId(currency.getSymbol())); + totalValue += currency.getValue() * currency.getBalance(); + totalFluctuation += (currency.getValue() * currency.getBalance()) * (currency.getDayFluctuationPercentage() / 100); - } - else - { - localCurrency.setChartColor(12369084); - } - - if(!localCurrency.getSymbol().equals("USD") && (localCurrency.getBalance() * localCurrency.getValue()) > 0.001) - { - localCurrency.setName(balanceManager.getCurrencyName(localCurrency.getSymbol())); - localCurrency.setId(balanceManager.getCurrencyId(localCurrency.getSymbol())); - totalValue += localCurrency.getValue() * localCurrency.getBalance(); - totalFluctuation += (localCurrency.getValue() * localCurrency.getBalance()) * (localCurrency.getDayFluctuationPercentage() / 100); - - cardList.add(layoutGenerator.getInfoLayout(localCurrency, true)); - } - - if(!localCurrency.getSymbol().equals("USD") && localCurrency.getHistoryMinutes() == null) - { - cardList.add(layoutGenerator.getInfoLayout(localCurrency, true)); - } - - balanceManager.getTotalBalance().set(i, localCurrency); + cardList.add(layoutGenerator.getInfoLayout(currency, true)); } + if(!currency.getSymbol().equals("USD") && currency.getHistoryMinutes() == null) + { + cardList.add(layoutGenerator.getInfoLayout(currency, true)); + } + } + + private void refreshCurrencyList(final List cardList) + { runOnUiThread(new Runnable() { @Override public void run() { @@ -882,9 +864,10 @@ public class HomeActivity extends AppCompatActivity { adaptView(); } }); + } - toolbarLayout.setTitle("US$" + String.format("%.2f", totalValue)); - + private void updateFluctuation() + { if(totalFluctuation > 0) { runOnUiThread(new Runnable() { @@ -903,7 +886,10 @@ public class HomeActivity extends AppCompatActivity { } }); } + } + private void updateTitle() + { runOnUiThread(new Runnable() { @Override public void run() { @@ -918,6 +904,35 @@ public class HomeActivity extends AppCompatActivity { } } }); + } + + @Override + protected Void doInBackground(Void... params) + { + final List cardList = new ArrayList<>(); + + Looper.prepare(); + + balanceManager.sortCoins(); + + for(int i = 0; i < balanceManager.getTotalBalance().size(); i++) + { + final Currency localCurrency = balanceManager.getTotalBalance().get(i); + + updateChartColor(localCurrency); + + loadCurrency(localCurrency, cardList); + + balanceManager.getTotalBalance().set(i, localCurrency); + } + + refreshCurrencyList(cardList); + + toolbarLayout.setTitle("US$" + String.format("%.2f", totalValue)); + + updateFluctuation(); + + updateTitle(); return null; } @@ -1011,17 +1026,6 @@ public class HomeActivity extends AppCompatActivity { updateMarketCap(); - /*marketCapManager.updateTopCurrencies(new BalanceManager.VolleyCallBack() { - @Override - public void onSuccess() { - - } - - @Override - public void onError(String error) { - - }});*/ - return null; } diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java index f30af5f..a6ffcc1 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java @@ -49,9 +49,7 @@ public class RecordTransactionActivity extends AppCompatActivity { databaseManager = new DatabaseManager(this); validateButton = findViewById(R.id.validateButton); - amountTxtView = findViewById(R.id.currencyAmount); - purchasedDate = findViewById(R.id.purchaseDate); purchasedDate.setText(sdf.format(calendar.getTime())); 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 40e91e8..8caff1b 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java @@ -280,7 +280,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity { if(preferences.getBoolean("enable_fingerprint", false)) { - newFragment.setCancelable(false); newFragment.show(getFragmentManager(), "dialog"); diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java index be4cf06..43ecafb 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/BalanceManager.java @@ -95,7 +95,6 @@ public class BalanceManager { while(index < 11) { - //currenciesDetails.add(index, coinInfosHashmap.keySet().iterator().next()); index++; Log.d("coinfolio", "For " + index + " : " + coinIterator.next()); diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java index 1f96930..2ca5f20 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java @@ -9,13 +9,13 @@ import android.os.Parcelable; public class CurrencyDataChart implements Parcelable { - long timestamp; - double close; - double high; - double low; - double open; - double volumeFrom; - double volumeTo; + private long timestamp; + private double close; + private double high; + private double low; + private double open; + private double volumeFrom; + private double volumeTo; public CurrencyDataChart(long timestamp, double close, double high, double low, double open, double volumeFrom, double volumeTo) { diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java index 95a3aee..2ffb89d 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java @@ -44,20 +44,7 @@ public class CurrencyDataRetriever { private void updateHistory(final String symbolCurrencyFrom, String symbolCyrrencyTo, final DataChartCallBack callBack, int timeUnit) { - String requestUrl = null; - - switch (timeUnit) - { - case MINUTES: - requestUrl = minuteHistoryUrl + "?fsym=" + symbolCurrencyFrom + "&tsym=" + symbolCyrrencyTo + "&limit=1440"; - break; - case HOURS: - requestUrl = hourHistoryUrl + "?fsym=" + symbolCurrencyFrom + "&tsym=" + symbolCyrrencyTo + "&limit=744"; - break; - case DAYS: - requestUrl = dayHistoryUrl + "?fsym=" + symbolCurrencyFrom + "&tsym=" + symbolCyrrencyTo + "&limit=365"; - break; - } + String requestUrl = getRequestUrl(timeUnit, symbolCurrencyFrom, symbolCyrrencyTo); StringRequest stringRequest = new StringRequest(Request.Method.GET, requestUrl, new Response.Listener() { @@ -76,6 +63,26 @@ public class CurrencyDataRetriever { requestQueue.add(stringRequest); } + private String getRequestUrl(int timeUnit, String symbolCurrencyFrom, String symbolCyrrencyTo) + { + String requestUrl = null; + + switch (timeUnit) + { + case MINUTES: + requestUrl = minuteHistoryUrl + "?fsym=" + symbolCurrencyFrom + "&tsym=" + symbolCyrrencyTo + "&limit=1440"; + break; + case HOURS: + requestUrl = hourHistoryUrl + "?fsym=" + symbolCurrencyFrom + "&tsym=" + symbolCyrrencyTo + "&limit=744"; + break; + case DAYS: + requestUrl = dayHistoryUrl + "?fsym=" + symbolCurrencyFrom + "&tsym=" + symbolCyrrencyTo + "&limit=365"; + break; + } + + return requestUrl; + } + private List processHistoryResult(String response) { List dataChart = new ArrayList<>(); @@ -99,15 +106,7 @@ public class CurrencyDataRetriever { try { JSONObject jsonObject = new JSONObject(tab[i]); - long timestamp = Long.parseLong(jsonObject.getString("time")); - double close = Double.parseDouble(jsonObject.getString("close")); - double high = Double.parseDouble(jsonObject.getString("high")); - double low = Double.parseDouble(jsonObject.getString("low")); - double open = Double.parseDouble(jsonObject.getString("open")); - double volumeFrom = Double.parseDouble(jsonObject.getString("volumefrom")); - double volumeTo = Double.parseDouble(jsonObject.getString("volumeto")); - - dataChart.add(new CurrencyDataChart(timestamp, close, high, low, open, volumeFrom, volumeTo)); + dataChart.add(parseJSON(jsonObject)); } catch (JSONException e) { Log.d(context.getResources().getString(R.string.debug_volley), "API Request error: " + e + " index: " + i); @@ -122,6 +121,19 @@ public class CurrencyDataRetriever { return dataChart; } + private CurrencyDataChart parseJSON(JSONObject jsonObject) throws JSONException { + + long timestamp = Long.parseLong(jsonObject.getString("time")); + double close = Double.parseDouble(jsonObject.getString("close")); + double high = Double.parseDouble(jsonObject.getString("high")); + double low = Double.parseDouble(jsonObject.getString("low")); + double open = Double.parseDouble(jsonObject.getString("open")); + double volumeFrom = Double.parseDouble(jsonObject.getString("volumefrom")); + double volumeTo = Double.parseDouble(jsonObject.getString("volumeto")); + + return new CurrencyDataChart(timestamp, close, high, low, open, volumeFrom, volumeTo); + } + void updateHistory(String symbolCurrencyFrom, final DataChartCallBack callBack, int timeUnit) { if(symbolCurrencyFrom.equals("USD")) diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java index 82e566e..01a1b4f 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java @@ -110,19 +110,16 @@ public class DatabaseManager extends SQLiteOpenHelper{ return currencyList; } - //public HashMap getCurrencyTransactions(String symbol) public List getCurrencyTransactions(String symbol) { String searchQuerry = "SELECT * FROM " + TABLE_MANUAL_CURRENCIES + " WHERE symbol='" + symbol.toUpperCase() + "'"; SQLiteDatabase db = this.getWritableDatabase(); Cursor resultatList = db.rawQuery(searchQuerry, null); - //HashMap transactionList = new HashMap<>(); List transactionList = new ArrayList<>(); while(resultatList.moveToNext()) { - //transactionList.put(resultatList.getInt(0), resultatList.getDouble(3)); transactionList.add(new Transaction(resultatList.getInt(0), resultatList.getString(1), resultatList.getDouble(3), resultatList.getLong(4))); } diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java index 25544e5..07d9d15 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java @@ -22,8 +22,6 @@ public class BinanceManager { private List balance; - public BinanceManager(){} - public BinanceManager(String publicKey, String privateKey) { this.publicKey = publicKey; @@ -32,7 +30,6 @@ public class BinanceManager { public void updateBalance(BinanceCallBack callBack) { - Map accountBalanceCache; BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(publicKey, privateKey); BinanceApiRestClient client = factory.newRestClient(); diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/HitBtcManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/HitBtcManager.java index 43c7a91..49afd1b 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/HitBtcManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/HitBtcManager.java @@ -36,12 +36,6 @@ public class HitBtcManager { private List balance; private android.content.Context context; - public HitBtcManager(android.content.Context context) - { - this.context = context; - requestQueue = Volley.newRequestQueue(context); - } - public HitBtcManager(android.content.Context context, String publicKey, String privateKey) { this.context = context; @@ -53,27 +47,9 @@ public class HitBtcManager { public void updateBalance(final HitBtcCallBack callBack) { - JsonArrayRequest arrayRequest = new JsonArrayRequest(Request.Method.GET, hitBalanceUrl, - new Response.Listener() { - @Override - public void onResponse(JSONArray response) { - if (response.length() > 0) { - parseBalance(response); - } else { - //No balance - } - - callBack.onSuccess(); - } - }, - new Response.ErrorListener() { - @Override - public void onErrorResponse(VolleyError error) { - Log.e(context.getResources().getString(R.string.debug), "API Error : " + error); - callBack.onError(error.toString()); - } - } - ) { + JsonArrayRequest arrayRequest = new JsonArrayRequest(Request.Method.GET, hitBalanceUrl + , getResponseListener(callBack), getErrorResponseListener(callBack)) + { @Override public Map getHeaders() throws AuthFailureError { Map headers = new HashMap<>(); @@ -89,6 +65,31 @@ public class HitBtcManager { requestQueue.add(arrayRequest); } + private Response.Listener getResponseListener(final HitBtcCallBack callBack) + { + return new Response.Listener() { + @Override + public void onResponse(JSONArray response) { + if (response.length() > 0) { + parseBalance(response); + } + + callBack.onSuccess(); + } + }; + } + + private Response.ErrorListener getErrorResponseListener(final HitBtcCallBack callBack) + { + return new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + Log.e(context.getResources().getString(R.string.debug), "API Error : " + error); + callBack.onError(error.toString()); + } + }; + } + private void parseBalance(JSONArray response) { balance = new ArrayList<>(); diff --git a/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintDialogFragment.java b/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintDialogFragment.java index 86ab29e..71c82e9 100644 --- a/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintDialogFragment.java +++ b/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintDialogFragment.java @@ -32,8 +32,6 @@ public class FingerprintDialogFragment extends DialogFragment{ View view = inflater.inflate(R.layout.fragment_fingerprint_scanner, container); - //getDialog().getWindow().setLayout(getResources().getDimensionPixelSize(R.dimen.fingerprint_dialog_width), getResources().getDimensionPixelSize(R.dimen.fingerprint_dialog_height)); - view.findViewById(R.id.cancelButton).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { diff --git a/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintHandler.java b/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintHandler.java index bdbc661..0eae113 100644 --- a/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintHandler.java +++ b/app/src/main/java/com/nauk/coinfolio/FingerprintToolkit/FingerprintHandler.java @@ -37,7 +37,6 @@ public class FingerprintHandler extends FingerprintManager.AuthenticationCallbac @Override public void onAuthenticationError(int errMsgId, CharSequence errString) { - //Toast.makeText(context, "Authentification error\n" + errString, Toast.LENGTH_LONG).show(); if(dialogFragment.isVisible()) { dialogFragment.wrongFingerprint("Error"); @@ -56,7 +55,6 @@ public class FingerprintHandler extends FingerprintManager.AuthenticationCallbac @Override public void onAuthenticationFailed() { - //Toast.makeText(context, "Authentification failed", Toast.LENGTH_LONG).show(); if(dialogFragment.isVisible()) { dialogFragment.wrongFingerprint("Wrong fingerprint"); @@ -75,8 +73,6 @@ public class FingerprintHandler extends FingerprintManager.AuthenticationCallbac @Override public void onAuthenticationHelp(int helpMsgIf, CharSequence helpString) { - //Toast.makeText(context, "Authentification help\n" + helpString, Toast.LENGTH_LONG).show(); - if(dialogFragment.isVisible()) { dialogFragment.wrongFingerprint(helpString.toString()); @@ -95,9 +91,6 @@ public class FingerprintHandler extends FingerprintManager.AuthenticationCallbac @Override public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) { - //Toast.makeText(context, "Success !", Toast.LENGTH_LONG).show(); - //dialogFragment.dismiss(); - dialogFragment.correctFingerprint(); new Handler().postDelayed(new Runnable() { @Override diff --git a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyAdapter.java b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyAdapter.java index 5691fd8..166ede8 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyAdapter.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyAdapter.java @@ -31,20 +31,25 @@ public class CurrencyAdapter extends ArrayAdapter { } @Override - public View getView(int position, View convertView, ViewGroup parent) { + public View getView(int position, View convertView, ViewGroup parent) + { Currency currency = getItem(position); + if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.custom_currency_row, parent, false); } + TextView currencyName = convertView.findViewById(R.id.currencyName); TextView currencySymbol = convertView.findViewById(R.id.currencySymbol); + if (currencyName != null) currencyName.setText(currency.getName()); + if(currencySymbol != null) { currencySymbol.setText(currency.getSymbol()); } - // Now assign alternate color for rows + if (position % 2 == 0) convertView.setBackgroundColor(context.getResources().getColor(R.color.listBackground2)); else @@ -74,7 +79,7 @@ public class CurrencyAdapter extends ArrayAdapter { int found = 0; String temp = constraint.toString().toLowerCase(); - while(i < tempCurrency.size() && found < 25) + while(i < tempCurrency.size() && found < 50) { Currency currency = tempCurrency.get(i); if (currency.getName().toLowerCase().startsWith(temp) @@ -85,14 +90,6 @@ public class CurrencyAdapter extends ArrayAdapter { i++; } - - /*for (Currency currency : tempCurrency) { - if (currency.getName().toLowerCase().startsWith(temp) - || currency.getSymbol().toLowerCase().startsWith(temp)) { - suggestions.add(currency); - } - }*/ - FilterResults filterResults = new FilterResults(); filterResults.values = suggestions; filterResults.count = suggestions.size(); 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 ac2cb2a..a1b468e 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java @@ -64,6 +64,64 @@ public class HomeLayoutGenerator { } }); + updateCardViewInfos(view, currency); + + view.findViewById(R.id.errorTextView).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class); + intent.putExtra("currency", currency); + context.getApplicationContext().startActivity(intent); + } + }); + + setupLineChart(view, currency); + + if(isExtended) + { + extendView(currency, view); + } + else + { + collapseView(view); + } + + updateColor(view, currency); + + return view; + } + + private void setupLineChart(View view, final Currency currency) + { + LineChart lineChart = view.findViewById(R.id.LineChartView); + + lineChart.setDrawGridBackground(false); + lineChart.setDrawBorders(false); + lineChart.setDrawMarkers(false); + lineChart.setDoubleTapToZoomEnabled(false); + lineChart.setPinchZoom(false); + lineChart.setScaleEnabled(false); + lineChart.setDragEnabled(false); + lineChart.getDescription().setEnabled(false); + lineChart.getAxisLeft().setEnabled(false); + lineChart.getAxisRight().setEnabled(false); + lineChart.getLegend().setEnabled(false); + lineChart.getXAxis().setEnabled(false); + lineChart.setViewPortOffsets(0, 0, 0, 0); + lineChart.setData(generateData(currency)); + + lineChart.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class); + intent.putExtra("currency", currency); + context.getApplicationContext().startActivity(intent); + } + }); + } + + private void updateCardViewInfos(View view, Currency currency) + { ((ImageView) view.findViewById(R.id.currencyIcon)) .setImageBitmap(currency.getIcon()); ((TextView) view.findViewById(R.id.currencyNameTextView)) @@ -83,57 +141,6 @@ public class HomeLayoutGenerator { .setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getDayFluctuation()))); ((ImageView) view.findViewById(R.id.detailsArrow)) .getDrawable().setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); - - view.findViewById(R.id.errorTextView).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class); - intent.putExtra("currency", currency); - context.getApplicationContext().startActivity(intent); - } - }); - - if(currency.getHistoryMinutes() != null) - { - LineChart lineChart = view.findViewById(R.id.LineChartView); - - lineChart.setDrawGridBackground(false); - lineChart.setDrawBorders(false); - lineChart.setDrawMarkers(false); - lineChart.setDoubleTapToZoomEnabled(false); - lineChart.setPinchZoom(false); - lineChart.setScaleEnabled(false); - lineChart.setDragEnabled(false); - lineChart.getDescription().setEnabled(false); - lineChart.getAxisLeft().setEnabled(false); - lineChart.getAxisRight().setEnabled(false); - lineChart.getLegend().setEnabled(false); - lineChart.getXAxis().setEnabled(false); - lineChart.setViewPortOffsets(0, 0, 0, 0); - lineChart.setData(generateData(currency)); - - lineChart.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class); - intent.putExtra("currency", currency); - context.getApplicationContext().startActivity(intent); - } - }); - } - - if(isExtended) - { - extendView(currency, view); - } - else - { - collapseView(view); - } - - updateColor(view, currency); - - return view; } private void collapseView(View view) @@ -241,7 +248,9 @@ public class HomeLayoutGenerator { int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); + transColor = Color.argb(alpha, r, g, b); + return transColor ; } From e9cbbd7b27a3fa99c5b39e7dd346aff404250638 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Wed, 4 Apr 2018 14:22:24 +0200 Subject: [PATCH 10/34] Fix data indicators in DetailsActivity --- .../Activities/CurrencyDetailsActivity.java | 21 +++------- .../LayoutManagers/HomeLayoutGenerator.java | 2 +- .../res/layout/activity_currency_details.xml | 41 ++++++------------- 3 files changed, 20 insertions(+), 44 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 60f924d..9f6360f 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -442,11 +442,9 @@ public class CurrencyDetailsActivity extends AppCompatActivity { date = getDate(dataChartList.get(index).getTimestamp() * 1000); } - displayDataIndicators(); - - ((TextView) findViewById(R.id.volumeHightlight)).setText("Volume : US$" + barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY()); - ((TextView) findViewById(R.id.priceHightlight)).setText("Price : US$" + e.getY()); - ((TextView) findViewById(R.id.timestampHightlight)).setText("Date : " + date); + ((TextView) findViewById(R.id.volumeHightlight)).setText("Volume\nUS$" + barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY()); + ((TextView) findViewById(R.id.priceHightlight)).setText("Price\nUS$" + e.getY()); + ((TextView) findViewById(R.id.timestampHightlight)).setText("Date\n" + date); } @@ -463,18 +461,11 @@ public class CurrencyDetailsActivity extends AppCompatActivity { return false; } - private void displayDataIndicators() - { - findViewById(R.id.volumeHightlight).setVisibility(View.VISIBLE); - findViewById(R.id.priceHightlight).setVisibility(View.VISIBLE); - findViewById(R.id.timestampHightlight).setVisibility(View.VISIBLE); - } - private void hideDataIndicators() { - findViewById(R.id.volumeHightlight).setVisibility(View.INVISIBLE); - findViewById(R.id.priceHightlight).setVisibility(View.INVISIBLE); - findViewById(R.id.timestampHightlight).setVisibility(View.INVISIBLE); + ((TextView) findViewById(R.id.volumeHightlight)).setText("\n"); + ((TextView) findViewById(R.id.priceHightlight)).setText("\n"); + ((TextView) findViewById(R.id.timestampHightlight)).setText("\n"); } private String getDate(long timeStamp){ 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 a1b468e..ab93f77 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java @@ -248,7 +248,7 @@ public class HomeLayoutGenerator { int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); - + transColor = Color.argb(alpha, r, g, b); return transColor ; diff --git a/app/src/main/res/layout/activity_currency_details.xml b/app/src/main/res/layout/activity_currency_details.xml index 3137af2..051e6bd 100644 --- a/app/src/main/res/layout/activity_currency_details.xml +++ b/app/src/main/res/layout/activity_currency_details.xml @@ -51,22 +51,28 @@ android:id="@+id/timestampHightlight" android:layout_width="match_parent" android:layout_height="wrap_content" - android:visibility="invisible" - android:layout_weight="0.33"/> + android:layout_gravity="center_horizontal" + android:gravity="center_horizontal" + android:layout_weight="0.33" + android:text="\n" /> + android:layout_gravity="center_horizontal" + android:gravity="center_horizontal" + android:layout_weight="0.33" + android:text="\n" /> + android:layout_gravity="center_horizontal" + android:gravity="center_horizontal" + android:layout_weight="0.33" + android:text="\n"/> @@ -276,25 +282,4 @@ app:menu="@menu/navigation_details" android:layout_alignParentBottom="true"/> - - \ No newline at end of file + \ No newline at end of file From 360c41751e8a68f4fb35d0654e3b8fe7984e715f Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Wed, 4 Apr 2018 15:41:28 +0200 Subject: [PATCH 11/34] Details Activity data interface rework --- app/build.gradle | 1 - .../Activities/CurrencyDetailsActivity.java | 71 +++++++- .../res/layout/activity_currency_details.xml | 154 +++++++++++++++--- app/src/main/res/layout/cardview_currency.xml | 2 +- app/src/main/res/values/dimens.xml | 2 +- 5 files changed, 202 insertions(+), 28 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d3fd690..137cede 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -43,7 +43,6 @@ dependencies { implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3' implementation 'com.mattprecious.swirl:swirl:1.1.0' implementation 'com.wdullaer:materialdatetimepicker:3.5.2' - //implementation 'com.github.lecho:hellocharts-library:1.5.8@aar' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 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 9f6360f..d7cc0e9 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -42,10 +42,19 @@ import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction; import com.nauk.coinfolio.DataManagers.DatabaseManager; import com.nauk.coinfolio.R; +import org.json.JSONException; + +import java.io.IOException; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Locale; + +import static java.lang.Math.abs; /**Create a Parcelable**/ @@ -403,7 +412,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { } }); - updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY()); + updateGeneralData(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY()); findViewById(R.id.chartPriceView).setVisibility(View.VISIBLE); findViewById(R.id.progressLayoutChart).setVisibility(View.GONE); @@ -442,8 +451,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity { date = getDate(dataChartList.get(index).getTimestamp() * 1000); } - ((TextView) findViewById(R.id.volumeHightlight)).setText("Volume\nUS$" + barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY()); - ((TextView) findViewById(R.id.priceHightlight)).setText("Price\nUS$" + e.getY()); + ((TextView) findViewById(R.id.volumeHightlight)).setText("Volume\nUS$" + numberConformer(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY())); + ((TextView) findViewById(R.id.priceHightlight)).setText("Price\nUS$" + numberConformer(e.getY())); ((TextView) findViewById(R.id.timestampHightlight)).setText("Date\n" + date); } @@ -507,6 +516,27 @@ public class CurrencyDetailsActivity extends AppCompatActivity { return new BarData(dataSet); } + private String numberConformer(double number) + { + String str; + DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.UK); + DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols(); + + symbols.setGroupingSeparator(' '); + formatter.setDecimalFormatSymbols(symbols); + + if(abs(number) > 1) + { + str = formatter.format(number); + } + else + { + str = String.format( Locale.UK, "%.4f", number); + } + + return str; + } + private LineData generatePriceChartSet() { LineDataSet dataSet; @@ -544,6 +574,37 @@ public class CurrencyDetailsActivity extends AppCompatActivity { return new LineData(dataSet); } + private void updateGeneralData(float start, float end) + { + double totalVolume = dataChartList.get(0).getVolumeTo(); + double highestPrice = dataChartList.get(0).getOpen(); + double lowestPrice = dataChartList.get(0).getOpen(); + + updateFluctuation(start, end); + + ((TextView) findViewById(R.id.txtViewPriceStart)).setText("$" + numberConformer(start)); + ((TextView) findViewById(R.id.txtViewPriceNow)).setText("$" + numberConformer(end)); + + for(int i = 1; i < dataChartList.size(); i++) + { + totalVolume += dataChartList.get(i).getVolumeTo(); + + if(highestPrice < dataChartList.get(i).getOpen()) + { + highestPrice = dataChartList.get(i).getOpen(); + } + + if(lowestPrice > dataChartList.get(i).getOpen()) + { + lowestPrice = dataChartList.get(i).getOpen(); + } + } + + ((TextView) findViewById(R.id.totalVolume)).setText("US$" + numberConformer(totalVolume)); + ((TextView) findViewById(R.id.highestPrice)).setText("US$" + numberConformer(highestPrice)); + ((TextView) findViewById(R.id.lowestPrice)).setText("US$" + numberConformer(lowestPrice)); + } + private void updateFluctuation(float start, float end) { float fluctuation = end - start; @@ -558,9 +619,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { ((TextView) findViewById(R.id.txtViewPercentage)).setTextColor(getResources().getColor(R.color.green)); } - ((TextView) findViewById(R.id.txtViewPriceStart)).setText("$" + start); - ((TextView) findViewById(R.id.txtViewPriceNow)).setText("$" + end); - ((TextView) findViewById(R.id.txtViewPercentage)).setText(percentageFluctuation + "%"); + ((TextView) findViewById(R.id.txtViewPercentage)).setText(numberConformer(percentageFluctuation) + "%"); } private int getColorWithAlpha(int color, float ratio) diff --git a/app/src/main/res/layout/activity_currency_details.xml b/app/src/main/res/layout/activity_currency_details.xml index 051e6bd..3bbb8fa 100644 --- a/app/src/main/res/layout/activity_currency_details.xml +++ b/app/src/main/res/layout/activity_currency_details.xml @@ -154,44 +154,160 @@ - - + android:layout_height="match_parent" + android:orientation="horizontal" + android:layout_weight="0.16"> + + + android:layout_height="match_parent" + android:gravity="center_horizontal" + android:layout_weight="0.25"/> + + + + + + + + + android:layout_height="match_parent" + android:gravity="center_horizontal" + android:layout_weight="0.25"/> + + + + + + + + + android:layout_height="match_parent" + android:gravity="center_horizontal" + android:layout_weight="0.25"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/cardview_currency.xml b/app/src/main/res/layout/cardview_currency.xml index e124ddd..ba92896 100644 --- a/app/src/main/res/layout/cardview_currency.xml +++ b/app/src/main/res/layout/cardview_currency.xml @@ -134,7 +134,7 @@ 125dp 250dp - 1dp + 1dp From b211a4f698d069fb8e3dfe7d339c14062d6f8882 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Wed, 4 Apr 2018 16:02:06 +0200 Subject: [PATCH 12/34] Details Activity placeholders --- .../Activities/CurrencyDetailsActivity.java | 42 +++++++++++-------- app/src/main/res/values/strings.xml | 6 +++ 2 files changed, 30 insertions(+), 18 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 d7cc0e9..9d01100 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -42,9 +42,6 @@ import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction; import com.nauk.coinfolio.DataManagers.DatabaseManager; import com.nauk.coinfolio.R; -import org.json.JSONException; - -import java.io.IOException; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.NumberFormat; @@ -62,7 +59,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private ViewFlipper viewFlipper; private LinearLayout transactionLayout; - private LinearLayout chartLayout; private DatabaseManager databaseManager; //private String symbol; private Currency currency; @@ -129,10 +125,11 @@ public class CurrencyDetailsActivity extends AppCompatActivity { viewFlipper = findViewById(R.id.vfCurrencyDetails); transactionLayout = findViewById(R.id.listTransactions); - chartLayout = findViewById(R.id.chartsLayout); lineChart = findViewById(R.id.chartPriceView); barChart = findViewById(R.id.chartVolumeView); + ((BottomNavigationView) findViewById(R.id.navigation_details)).getMenu().getItem(1).setEnabled(false); + drawTransactionList(); initializeButtons(); @@ -150,6 +147,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private void setupActionBar() { setTitle(" " + currency.getName() + " | " + currency.getBalance()); + getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_USE_LOGO); @@ -437,9 +435,12 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private void valueSelectedEvent(Entry e) { - //updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), e.getY()); int index = lineChart.getData().getDataSets().get(0).getEntryIndex(e); - String date = null; + String date; + String volumePlaceholder; + String pricePlaceholder; + String timestampPlaceholder; + barChart.highlightValue(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getX(), 0, index); if(dataChartList.size() > 200) @@ -451,9 +452,13 @@ public class CurrencyDetailsActivity extends AppCompatActivity { date = getDate(dataChartList.get(index).getTimestamp() * 1000); } - ((TextView) findViewById(R.id.volumeHightlight)).setText("Volume\nUS$" + numberConformer(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY())); - ((TextView) findViewById(R.id.priceHightlight)).setText("Price\nUS$" + numberConformer(e.getY())); - ((TextView) findViewById(R.id.timestampHightlight)).setText("Date\n" + date); + volumePlaceholder = getResources().getString(R.string.volumePlaceholder, numberConformer(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY())); + pricePlaceholder = getResources().getString(R.string.pricePlaceholder, numberConformer(e.getY())); + timestampPlaceholder = getResources().getString(R.string.timestampPlaceholder, date); + + ((TextView) findViewById(R.id.volumeHightlight)).setText(volumePlaceholder); + ((TextView) findViewById(R.id.priceHightlight)).setText(pricePlaceholder); + ((TextView) findViewById(R.id.timestampHightlight)).setText(timestampPlaceholder); } @@ -480,7 +485,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private String getDate(long timeStamp){ try{ - SimpleDateFormat sdf = new SimpleDateFormat(" HH:mm dd/MM/yyyy"); + //SimpleDateFormat sdf = new SimpleDateFormat(" HH:mm dd/MM/yyyy"); + SimpleDateFormat sdf = new SimpleDateFormat(" HH:mm dd/MM/yyyy", Locale.getDefault()); Date netDate = (new Date(timeStamp)); return sdf.format(netDate); } @@ -582,8 +588,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity { updateFluctuation(start, end); - ((TextView) findViewById(R.id.txtViewPriceStart)).setText("$" + numberConformer(start)); - ((TextView) findViewById(R.id.txtViewPriceNow)).setText("$" + numberConformer(end)); + ((TextView) findViewById(R.id.txtViewPriceStart)).setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(start))); + ((TextView) findViewById(R.id.txtViewPriceNow)).setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(end))); for(int i = 1; i < dataChartList.size(); i++) { @@ -600,9 +606,9 @@ public class CurrencyDetailsActivity extends AppCompatActivity { } } - ((TextView) findViewById(R.id.totalVolume)).setText("US$" + numberConformer(totalVolume)); - ((TextView) findViewById(R.id.highestPrice)).setText("US$" + numberConformer(highestPrice)); - ((TextView) findViewById(R.id.lowestPrice)).setText("US$" + numberConformer(lowestPrice)); + ((TextView) findViewById(R.id.totalVolume)).setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(totalVolume))); + ((TextView) findViewById(R.id.highestPrice)).setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(highestPrice))); + ((TextView) findViewById(R.id.lowestPrice)).setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(lowestPrice))); } private void updateFluctuation(float start, float end) @@ -619,7 +625,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { ((TextView) findViewById(R.id.txtViewPercentage)).setTextColor(getResources().getColor(R.color.green)); } - ((TextView) findViewById(R.id.txtViewPercentage)).setText(numberConformer(percentageFluctuation) + "%"); + ((TextView) findViewById(R.id.txtViewPercentage)).setText(getResources().getString(R.string.currencyPercentagePlaceholder, numberConformer(percentageFluctuation))); } private int getColorWithAlpha(int color, float ratio) @@ -664,7 +670,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { } }); - amountTxtView.setText(transactionList.get(i).getAmount() + ""); + amountTxtView.setText(String.valueOf(transactionList.get(i).getAmount())); setupSwipeView(view); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 921c25c..a51ea37 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -146,6 +146,12 @@ (US$%1$s) US$%1$s %1$s%% + + + Volume\nUS$%1$s + Price\nUS$%1$s + Date\n%1$s + MainActivity Cancel From e7378c278b37f3a554565299ca78ebe1a8e400ef Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Wed, 4 Apr 2018 16:14:56 +0200 Subject: [PATCH 13/34] HomeActivity placeholders --- .../coinfolio/Activities/CurrencySelectionActivity.java | 6 +++--- .../java/com/nauk/coinfolio/Activities/HomeActivity.java | 9 +++++---- app/src/main/res/values/strings.xml | 1 + 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencySelectionActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencySelectionActivity.java index 17d2753..5d431a5 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencySelectionActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencySelectionActivity.java @@ -61,11 +61,11 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear private void setupAdapter() { - String[] currencyFullname = new String[currencyNames.length]; + String[] currencyFullName = new String[currencyNames.length]; - for(int i = 0; i < currencyFullname.length; i++) + for(int i = 0; i < currencyFullName.length; i++) { - currencyFullname[i] = currencyNames[i] + " " + currencySymbols[i]; + currencyFullName[i] = currencyNames[i] + " " + currencySymbols[i]; } ArrayList currencyArrayList = new ArrayList<>(); 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 3274f46..98a247d 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -177,9 +177,9 @@ public class HomeActivity extends AppCompatActivity { ImageButton settingsButton = findViewById(R.id.settings_button); toolbarLayout.setForegroundGravity(Gravity.CENTER); - toolbarLayout.setTitle("US$0.00"); + toolbarLayout.setTitle(getResources().getString(R.string.currencyDollarPlaceholder, "0.00")); - toolbarSubtitle.setText("US$0.00"); + toolbarSubtitle.setText(getResources().getString(R.string.currencyDollarPlaceholder, "0.00")); //Events setup detailsButton.setOnClickListener(new View.OnClickListener() { @@ -551,9 +551,9 @@ public class HomeActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - toolbarLayout.setTitle("US$0.00"); + toolbarLayout.setTitle(getResources().getString(R.string.currencyDollarPlaceholder, "0.00")); - toolbarSubtitle.setText("US$0.00"); + toolbarSubtitle.setText(getResources().getString(R.string.currencyDollarPlaceholder, "0.00")); toolbarSubtitle.setTextColor(-1275068417); } @@ -896,6 +896,7 @@ public class HomeActivity extends AppCompatActivity { 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()) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a51ea37..a8bb5c0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -146,6 +146,7 @@ (US$%1$s) US$%1$s %1$s%% + US$%1$s (%2$s%) Volume\nUS$%1$s From daf2f0ddc1e1257f6df27b6693189c69b31c93e2 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Fri, 6 Apr 2018 09:44:23 +0200 Subject: [PATCH 14/34] Add currency dominance bar --- .../Activities/CurrencyDetailsActivity.java | 30 +++++----- .../coinfolio/Activities/HomeActivity.java | 60 +++++-------------- .../Activities/SettingsActivity.java | 27 ++++++--- .../DataManagers/PreferencesManager.java | 5 ++ .../LayoutManagers/HomeLayoutGenerator.java | 22 +++++-- app/src/main/res/layout/cardview_currency.xml | 9 ++- .../main/res/layout/cardview_watchlist.xml | 2 +- app/src/main/res/menu/navigation_home.xml | 2 +- app/src/main/res/values/strings.xml | 5 +- app/src/main/res/xml/pref_general.xml | 15 +++-- app/src/main/res/xml/pref_headers.xml | 7 +++ 11 files changed, 96 insertions(+), 88 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 9d01100..17ad8c4 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -130,13 +130,13 @@ public class CurrencyDetailsActivity extends AppCompatActivity { ((BottomNavigationView) findViewById(R.id.navigation_details)).getMenu().getItem(1).setEnabled(false); + setupActionBar(); + drawTransactionList(); initializeButtons(); - createCharts(DAY, 1); - - setupActionBar(); + updateChartTab(DAY, 1); BottomNavigationView navigation = findViewById(R.id.navigation_details); navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); @@ -218,13 +218,13 @@ public class CurrencyDetailsActivity extends AppCompatActivity { switch (interval) { case "1h": - createCharts(HOUR, 1); + updateChartTab(HOUR, 1); break; case "3h": - createCharts(HOUR, 3); + updateChartTab(HOUR, 3); break; case "1d": - createCharts(DAY, 1); + updateChartTab(DAY, 1); break; case "3d": currency.updateHistoryHours(this, new Currency.CurrencyCallBack() { @@ -233,7 +233,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - createCharts(CurrencyDetailsActivity.DAY, 3); + updateChartTab(CurrencyDetailsActivity.DAY, 3); } }); } @@ -246,7 +246,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - createCharts(CurrencyDetailsActivity.WEEK, 11); + updateChartTab(CurrencyDetailsActivity.WEEK, 11); } }); } @@ -259,7 +259,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - createCharts(CurrencyDetailsActivity.MONTH, 1); + updateChartTab(CurrencyDetailsActivity.MONTH, 1); } }); } @@ -272,7 +272,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - createCharts(CurrencyDetailsActivity.MONTH, 3); + updateChartTab(CurrencyDetailsActivity.MONTH, 3); } }); } @@ -285,7 +285,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - createCharts(CurrencyDetailsActivity.MONTH, 6); + updateChartTab(CurrencyDetailsActivity.MONTH, 6); } }); } @@ -298,7 +298,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - createCharts(CurrencyDetailsActivity.YEAR, 1); + updateChartTab(CurrencyDetailsActivity.YEAR, 1); } }); } @@ -307,7 +307,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { } } - private void createCharts(int timeUnit, int amount) + private void updateChartTab(int timeUnit, int amount) { updateChartsData(timeUnit, amount); drawPriceChart(); @@ -509,7 +509,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { for(int i = 0, j = 0; i < dataChartList.size(); i += offset, j++) { - values.add(new BarEntry(j, (float) dataChartList.get(i).getVolumeTo())); + values.add(new BarEntry(j, (float) dataChartList.get(j).getVolumeTo())); } dataSet = new BarDataSet(values, "Volume"); @@ -614,7 +614,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private void updateFluctuation(float start, float end) { float fluctuation = end - start; - float percentageFluctuation = (float) (fluctuation / start * 100); + float percentageFluctuation = (fluctuation / start * 100); if(percentageFluctuation < 0) { 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 98a247d..f89f283 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -85,6 +85,7 @@ public class HomeActivity extends AppCompatActivity { private long lastTimestamp; private boolean detailsChecker; private boolean isDetailed; + private float totalValue; private CollapsingToolbarLayout toolbarLayout; private SwipeRefreshLayout refreshLayout; @@ -97,29 +98,6 @@ public class HomeActivity extends AppCompatActivity { private HashMap dominantCurrenciesColors; - private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener - = new BottomNavigationView.OnNavigationItemSelectedListener() { - - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case R.id.navigation_something: - - //((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide(); - return true; - case R.id.navigation_view_list: - //((FloatingActionButton) findViewById(R.id.floatingAddButton)).show(); - //viewFlipper.setDisplayedChild(1); - return true; - case R.id.navigation_market_cap: - //((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide(); - //viewFlipper.setDisplayedChild(2); - return true; - } - return false; - } - }; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -289,11 +267,11 @@ public class HomeActivity extends AppCompatActivity { @Override public void onItemClick(int itemIndex, String itemName) { + spaceNavigationItemEvent(itemIndex); } @Override public void onItemReselected(int itemIndex, String itemName) { - spaceNavigationItemEvent(itemIndex); } }); } @@ -437,7 +415,6 @@ public class HomeActivity extends AppCompatActivity { private void adaptView() { - currencyLayout.removeAllViews(); for(int i = 0; i < balanceManager.getTotalBalance().size(); i++) @@ -446,7 +423,7 @@ public class HomeActivity extends AppCompatActivity { if(!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001 || currency.getHistoryMinutes() == null)) { - currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed)); + currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden())); } } @@ -830,7 +807,7 @@ public class HomeActivity extends AppCompatActivity { } } - private void loadCurrency(Currency currency, List cardList) + private void loadCurrency(Currency currency) { if(!currency.getSymbol().equals("USD") && (currency.getBalance() * currency.getValue()) > 0.001) { @@ -838,30 +815,24 @@ public class HomeActivity extends AppCompatActivity { currency.setId(balanceManager.getCurrencyId(currency.getSymbol())); totalValue += currency.getValue() * currency.getBalance(); totalFluctuation += (currency.getValue() * currency.getBalance()) * (currency.getDayFluctuationPercentage() / 100); - - cardList.add(layoutGenerator.getInfoLayout(currency, true)); - } - - if(!currency.getSymbol().equals("USD") && currency.getHistoryMinutes() == null) - { - cardList.add(layoutGenerator.getInfoLayout(currency, true)); } } - private void refreshCurrencyList(final List cardList) + private void refreshCurrencyList() { runOnUiThread(new Runnable() { @Override public void run() { - refreshLayout.setRefreshing(false); currencyLayout.removeAllViews(); - for(int i = 0; i < cardList.size(); i++) + for(int i = 0; i < balanceManager.getTotalBalance().size(); i++) { - currencyLayout.addView(cardList.get(i)); - } + Currency currency = balanceManager.getTotalBalance().get(i); - adaptView(); + if(!currency.getSymbol().equals("USD") && (currency.getBalance() * currency.getValue()) > 0.001) { + currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden())); + } + } } }); } @@ -910,8 +881,6 @@ public class HomeActivity extends AppCompatActivity { @Override protected Void doInBackground(Void... params) { - final List cardList = new ArrayList<>(); - Looper.prepare(); balanceManager.sortCoins(); @@ -922,13 +891,11 @@ public class HomeActivity extends AppCompatActivity { updateChartColor(localCurrency); - loadCurrency(localCurrency, cardList); + loadCurrency(localCurrency); balanceManager.getTotalBalance().set(i, localCurrency); } - refreshCurrencyList(cardList); - toolbarLayout.setTitle("US$" + String.format("%.2f", totalValue)); updateFluctuation(); @@ -941,6 +908,9 @@ public class HomeActivity extends AppCompatActivity { @Override protected void onPostExecute(Void result) { + refreshLayout.setRefreshing(false); + refreshCurrencyList(); + HomeActivity.this.totalValue = totalValue; handler.removeCallbacks(updateRunnable); } } 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 8caff1b..b1afeed 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java @@ -20,6 +20,7 @@ import android.preference.PreferenceActivity; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; import android.preference.RingtonePreference; +import android.preference.SwitchPreference; import android.security.keystore.KeyGenParameterSpec; import android.security.keystore.KeyPermanentlyInvalidatedException; import android.security.keystore.KeyProperties; @@ -131,8 +132,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity { return true; } - Log.d("coinfolio", "hello"); - return super.onOptionsItemSelected(item); } @@ -198,7 +197,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { */ protected boolean isValidFragment(String fragmentName) { return PreferenceFragment.class.getName().equals(fragmentName) - //|| GeneralPreferenceFragment.class.getName().equals(fragmentName) + || GeneralPreferenceFragment.class.getName().equals(fragmentName) || DataSyncPreferenceFragment.class.getName().equals(fragmentName) || NotificationPreferenceFragment.class.getName().equals(fragmentName) || ExchangePreferenceFragment.class.getName().equals(fragmentName); @@ -216,12 +215,22 @@ public class SettingsActivity extends AppCompatPreferenceActivity { addPreferencesFromResource(R.xml.pref_general); setHasOptionsMenu(true); - // Bind the summaries of EditText/List/Dialog/Ringtone preferences - // to their values. When their values change, their summaries are - // updated to reflect the new value, per the Android Design - // guidelines. - bindPreferenceSummaryToValue(findPreference("example_text")); - bindPreferenceSummaryToValue(findPreference("example_list")); + ((SwitchPreference) findPreference("hide_balance")).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + boolean isChecked = !((SwitchPreference) findPreference("hide_balance")).isChecked(); + + ((SwitchPreference) findPreference("hide_balance")).setChecked(isChecked); + + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext()); + + SharedPreferences.Editor editor = preference.getEditor(); + + editor.putBoolean("hide_balance", isChecked); + editor.apply(); + return false; + } + }); } @Override diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java index b787925..b676291 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java @@ -58,6 +58,11 @@ public class PreferencesManager { return settingPreferences.getBoolean("enable_hitbtc", false); } + public boolean isBalanceHidden() + { + return settingPreferences.getBoolean("hide_balance", false); + } + public void disableHitBTC() { SharedPreferences.Editor editor = settingPreferences.edit(); 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 ab93f77..f946862 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java @@ -9,6 +9,7 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; +import android.widget.ProgressBar; import android.widget.TextView; import com.db.chart.model.ChartSet; @@ -45,9 +46,8 @@ public class HomeLayoutGenerator { this.context = context; } - public View getInfoLayout(final Currency currency, boolean isExtended) + public View getInfoLayout(final Currency currency, boolean isExtended, float totalValue, boolean isBalanceHidden) { - View view = LayoutInflater.from(context).inflate(R.layout.cardview_currency, null); view.setOnClickListener(new View.OnClickListener() { @@ -64,7 +64,7 @@ public class HomeLayoutGenerator { } }); - updateCardViewInfos(view, currency); + updateCardViewInfos(view, currency, totalValue, isBalanceHidden); view.findViewById(R.id.errorTextView).setOnClickListener(new View.OnClickListener() { @Override @@ -120,7 +120,7 @@ public class HomeLayoutGenerator { }); } - private void updateCardViewInfos(View view, Currency currency) + private void updateCardViewInfos(View view, Currency currency, float totalValue, boolean isBalanceHidden) { ((ImageView) view.findViewById(R.id.currencyIcon)) .setImageBitmap(currency.getIcon()); @@ -141,6 +141,20 @@ public class HomeLayoutGenerator { .setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getDayFluctuation()))); ((ImageView) view.findViewById(R.id.detailsArrow)) .getDrawable().setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + + if(isBalanceHidden) + { + double value = currency.getValue() * currency.getBalance(); + double percentage = value / totalValue * 100; + + view.findViewById(R.id.currencyPortfolioDominance).setVisibility(View.VISIBLE); + ((ProgressBar) view.findViewById(R.id.currencyPortfolioDominance)).setProgress((int) Math.round(percentage)); + ((ProgressBar) view.findViewById(R.id.currencyPortfolioDominance)).getIndeterminateDrawable().setColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_ATOP); + } + else + { + view.findViewById(R.id.currencyPortfolioDominance).setVisibility(View.GONE); + } } private void collapseView(View view) diff --git a/app/src/main/res/layout/cardview_currency.xml b/app/src/main/res/layout/cardview_currency.xml index ba92896..3ebaaa1 100644 --- a/app/src/main/res/layout/cardview_currency.xml +++ b/app/src/main/res/layout/cardview_currency.xml @@ -13,7 +13,7 @@ android:layout_margin="10dp" android:clickable="false" android:backgroundTint="@color/listBackground2" - app:cardCornerRadius="8dp" + app:cardCornerRadius="2dp" app:layout_constraintBottom_toBottomOf="parent"> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a8bb5c0..f885ec0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -12,10 +12,7 @@ General - Enable social recommendations - Recommendations for people to contact - based on your message history - + Hide balance Display name John Smith diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index 36569d6..264c219 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -1,14 +1,13 @@ + android:defaultValue="false" + android:key="hide_balance" + android:title="@string/pref_title_hide_balance" /> - + android:title="@string/pref_title_display_name" />--> - + android:title="@string/pref_title_add_friends_to_messages" />--> diff --git a/app/src/main/res/xml/pref_headers.xml b/app/src/main/res/xml/pref_headers.xml index 5ca4a5f..be8b1af 100644 --- a/app/src/main/res/xml/pref_headers.xml +++ b/app/src/main/res/xml/pref_headers.xml @@ -2,6 +2,11 @@ +
+
--> + + From 4193fc0709dfc4595c26e5b65c94dda42ba35db5 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Fri, 6 Apr 2018 15:01:07 +0200 Subject: [PATCH 15/34] Add cardview animation --- .../Activities/CurrencySelectionActivity.java | 6 +- .../coinfolio/Activities/HomeActivity.java | 1 + ...yAdapter.java => CurrencyListAdapter.java} | 4 +- .../LayoutManagers/HomeLayoutGenerator.java | 98 +++++++++++------ .../res/drawable/drop_shadow_cardview.xml | 5 + .../expand_collapse_button_animation.xml | 5 + app/src/main/res/layout/cardview_currency.xml | 100 ++++++++---------- .../res/layout/content_currency_summary.xml | 3 +- app/src/main/res/values/colors.xml | 4 +- app/src/main/res/values/dimens.xml | 2 + 10 files changed, 133 insertions(+), 95 deletions(-) rename app/src/main/java/com/nauk/coinfolio/LayoutManagers/{CurrencyAdapter.java => CurrencyListAdapter.java} (96%) create mode 100644 app/src/main/res/drawable/drop_shadow_cardview.xml create mode 100644 app/src/main/res/drawable/expand_collapse_button_animation.xml diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencySelectionActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencySelectionActivity.java index 5d431a5..0a7efbd 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencySelectionActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencySelectionActivity.java @@ -13,7 +13,7 @@ import android.widget.ListView; import android.widget.SearchView; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; -import com.nauk.coinfolio.LayoutManagers.CurrencyAdapter; +import com.nauk.coinfolio.LayoutManagers.CurrencyListAdapter; import com.nauk.coinfolio.R; import java.util.ArrayList; @@ -22,7 +22,7 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear private String[] currencySymbols; private String[] currencyNames; - private CurrencyAdapter adapter; + private CurrencyListAdapter adapter; private ListView listView; private android.widget.Filter filter; @@ -75,7 +75,7 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear currencyArrayList.add(new Currency(currencyNames[i], currencySymbols[i])); } - adapter = new CurrencyAdapter(this, currencyArrayList); + adapter = new CurrencyListAdapter(this, currencyArrayList); } private void setupList() 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 f89f283..bbb22c3 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -6,6 +6,7 @@ import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; +import android.graphics.drawable.AnimationDrawable; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; diff --git a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyAdapter.java b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyListAdapter.java similarity index 96% rename from app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyAdapter.java rename to app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyListAdapter.java index 166ede8..404440e 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyAdapter.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyListAdapter.java @@ -17,12 +17,12 @@ import java.util.ArrayList; * Created by Guitoune on 17/01/2018. */ -public class CurrencyAdapter extends ArrayAdapter { +public class CurrencyListAdapter extends ArrayAdapter { private ArrayList tempCurrency, suggestions; private Context context; - public CurrencyAdapter(Context context, ArrayList objects) { + public CurrencyListAdapter(Context context, ArrayList objects) { super(context, android.R.layout.simple_list_item_1, objects); this.tempCurrency = new ArrayList(objects); this.suggestions = new ArrayList(objects); 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 f946862..70de870 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java @@ -5,9 +5,12 @@ import android.content.Intent; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; +import android.support.v7.widget.CardView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; +import android.view.animation.Animation; +import android.view.animation.Transformation; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; @@ -53,33 +56,24 @@ public class HomeLayoutGenerator { view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - if(view.findViewById(R.id.LineChartView).getVisibility() == View.VISIBLE || view.findViewById(R.id.errorTextView).getVisibility() == View.VISIBLE) + if(view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE) { collapseView(view); } else { - extendView(currency, view); + extendView(view); } } }); updateCardViewInfos(view, currency, totalValue, isBalanceHidden); - view.findViewById(R.id.errorTextView).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class); - intent.putExtra("currency", currency); - context.getApplicationContext().startActivity(intent); - } - }); - setupLineChart(view, currency); if(isExtended) { - extendView(currency, view); + extendView(view); } else { @@ -91,6 +85,60 @@ public class HomeLayoutGenerator { return view; } + public static void expand(final View v) { + v.measure(CardView.LayoutParams.MATCH_PARENT, CardView.LayoutParams.WRAP_CONTENT); + final int targetHeight = v.getMeasuredHeight(); + + // Older versions of android (pre API 21) cancel animations for views with a height of 0. + v.getLayoutParams().height = 1; + v.setVisibility(View.VISIBLE); + Animation a = new Animation() + { + @Override + protected void applyTransformation(float interpolatedTime, Transformation t) { + v.getLayoutParams().height = interpolatedTime == 1 + ? CardView.LayoutParams.WRAP_CONTENT + : (int)(targetHeight * interpolatedTime); + v.requestLayout(); + } + + @Override + public boolean willChangeBounds() { + return true; + } + }; + + // 1dp/ms + a.setDuration((int)(targetHeight / v.getContext().getResources().getDisplayMetrics().density)); + v.startAnimation(a); + } + + public static void collapse(final View v) { + final int initialHeight = v.getMeasuredHeight(); + + Animation a = new Animation() + { + @Override + protected void applyTransformation(float interpolatedTime, Transformation t) { + if(interpolatedTime == 1){ + v.setVisibility(View.GONE); + }else{ + v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime); + v.requestLayout(); + } + } + + @Override + public boolean willChangeBounds() { + return true; + } + }; + + // 1dp/ms + a.setDuration((int)(initialHeight / v.getContext().getResources().getDisplayMetrics().density)); + v.startAnimation(a); + } + private void setupLineChart(View view, final Currency currency) { LineChart lineChart = view.findViewById(R.id.LineChartView); @@ -159,31 +207,13 @@ public class HomeLayoutGenerator { private void collapseView(View view) { - view.findViewById(R.id.separationLayout).setVisibility(View.GONE); - view.findViewById(R.id.frameLayoutChart).setVisibility(View.GONE); - view.findViewById(R.id.LineChartView).setVisibility(View.GONE); - view.findViewById(R.id.errorTextView).setVisibility(View.GONE); - view.findViewById(R.id.detailsArrow).setVisibility(View.GONE); + collapse(view.findViewById(R.id.collapsableLayout)); } - private void extendView(Currency currency, View view) + private void extendView(View view) { - view.findViewById(R.id.separationLayout).setVisibility(View.VISIBLE); - view.findViewById(R.id.detailsArrow).setVisibility(View.VISIBLE); - view.findViewById(R.id.frameLayoutChart).setVisibility(View.VISIBLE); - - if(currency.getHistoryMinutes() != null) - { - view.findViewById(R.id.LineChartView).setVisibility(View.VISIBLE); - view.findViewById(R.id.LineChartView).invalidate(); - view.findViewById(R.id.errorTextView).setVisibility(View.GONE); - } - else - { - view.findViewById(R.id.LineChartView).setVisibility(View.GONE); - view.findViewById(R.id.errorTextView).setVisibility(View.VISIBLE); - } - + expand(view.findViewById(R.id.collapsableLayout)); + view.findViewById(R.id.LineChartView).invalidate(); } private List getAxisBorders(Currency currency) diff --git a/app/src/main/res/drawable/drop_shadow_cardview.xml b/app/src/main/res/drawable/drop_shadow_cardview.xml new file mode 100644 index 0000000..e5fbdff --- /dev/null +++ b/app/src/main/res/drawable/drop_shadow_cardview.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/expand_collapse_button_animation.xml b/app/src/main/res/drawable/expand_collapse_button_animation.xml new file mode 100644 index 0000000..45c0a19 --- /dev/null +++ b/app/src/main/res/drawable/expand_collapse_button_animation.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/cardview_currency.xml b/app/src/main/res/layout/cardview_currency.xml index 3ebaaa1..cebcffb 100644 --- a/app/src/main/res/layout/cardview_currency.xml +++ b/app/src/main/res/layout/cardview_currency.xml @@ -12,7 +12,8 @@ android:layout_height="wrap_content" android:layout_margin="10dp" android:clickable="false" - android:backgroundTint="@color/listBackground2" + android:backgroundTint="@color/cardview_background" + android:elevation="@dimen/cardview_elevation" app:cardCornerRadius="2dp" app:layout_constraintBottom_toBottomOf="parent"> @@ -127,66 +128,57 @@ + android:visibility="gone" + android:orientation="vertical"> - - - + android:layout_height="wrap_content" + android:layout_margin="5dp"> + + + + + + + + + + + + + + - - - - - - - - - - - - diff --git a/app/src/main/res/layout/content_currency_summary.xml b/app/src/main/res/layout/content_currency_summary.xml index 6d0a96d..a811fe6 100644 --- a/app/src/main/res/layout/content_currency_summary.xml +++ b/app/src/main/res/layout/content_currency_summary.xml @@ -5,7 +5,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" - android:layout_marginBottom="50dp"> + android:layout_marginBottom="50dp" + android:background="@color/summary_background"> #000046 #FF999999 #FFF44336 - #FF4CAF50 + #FF4CAF50#FBFCFF --> @@ -34,4 +34,6 @@ #FFF44336 #FF4CAF50 #FFFFFFFF + #FFFFFFFF + #FBFCFF \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index bf14994..5ebce76 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -17,4 +17,6 @@ 250dp 1dp + + 8dp From 8b3db9b25d27625940417022321e69a731934304 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Fri, 6 Apr 2018 22:04:58 +0200 Subject: [PATCH 16/34] Crash... --- .../coinfolio/Activities/HomeActivity.java | 8 ++-- ...utGenerator.java => CurrencyCardView.java} | 38 +++++-------------- 2 files changed, 13 insertions(+), 33 deletions(-) rename app/src/main/java/com/nauk/coinfolio/LayoutManagers/{HomeLayoutGenerator.java => CurrencyCardView.java} (92%) 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 bbb22c3..1e988ba 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -48,7 +48,7 @@ import com.nauk.coinfolio.DataManagers.BalanceManager; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.MarketCapManager; import com.nauk.coinfolio.DataManagers.PreferencesManager; -import com.nauk.coinfolio.LayoutManagers.HomeLayoutGenerator; +import com.nauk.coinfolio.LayoutManagers.CurrencyCardView; import com.nauk.coinfolio.R; import java.io.IOException; @@ -76,7 +76,6 @@ import java.util.Locale; public class HomeActivity extends AppCompatActivity { private PreferencesManager preferencesManager; - private HomeLayoutGenerator layoutGenerator; private BalanceManager balanceManager; private MarketCapManager marketCapManager; @@ -118,7 +117,6 @@ public class HomeActivity extends AppCompatActivity { //Objects initialization preferencesManager = new PreferencesManager(this); - layoutGenerator = new HomeLayoutGenerator(this); balanceManager = new BalanceManager(this); marketCapManager = new MarketCapManager(this); handler = new Handler(); @@ -424,7 +422,7 @@ public class HomeActivity extends AppCompatActivity { if(!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001 || currency.getHistoryMinutes() == null)) { - currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden())); + currencyLayout.addView(new CurrencyCardView(this, currencyLayout).getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden())); } } @@ -831,7 +829,7 @@ public class HomeActivity extends AppCompatActivity { Currency currency = balanceManager.getTotalBalance().get(i); if(!currency.getSymbol().equals("USD") && (currency.getBalance() * currency.getValue()) > 0.001) { - currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden())); + currencyLayout.addView(new CurrencyCardView(getApplicationContext(), currencyLayout).getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden())); } } } diff --git a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyCardView.java similarity index 92% rename from app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java rename to app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyCardView.java index 70de870..45de5fc 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyCardView.java @@ -5,13 +5,17 @@ import android.content.Intent; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; +import android.os.Bundle; import android.support.v7.widget.CardView; +import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.Transformation; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; @@ -40,18 +44,21 @@ import static java.lang.Math.abs; * Created by Tiji on 05/01/2018. */ -public class HomeLayoutGenerator { +public class CurrencyCardView extends CardView { android.content.Context context; + private LinearLayout rootLayout; - public HomeLayoutGenerator(Context context) + public CurrencyCardView(Context context, LinearLayout rootLayout) { + super(context); this.context = context; + this.rootLayout = rootLayout; } public View getInfoLayout(final Currency currency, boolean isExtended, float totalValue, boolean isBalanceHidden) { - View view = LayoutInflater.from(context).inflate(R.layout.cardview_currency, null); + View view = LayoutInflater.from(context).inflate(R.layout.cardview_currency, rootLayout, true); view.setOnClickListener(new View.OnClickListener() { @Override @@ -216,31 +223,6 @@ public class HomeLayoutGenerator { view.findViewById(R.id.LineChartView).invalidate(); } - private List getAxisBorders(Currency currency) - { - List borders = new ArrayList<>(); - - List dataChartList = currency.getHistoryMinutes(); - - borders.add(0, currency.getHistoryMinutes().get(0).getOpen()); - borders.add(1, currency.getHistoryMinutes().get(0).getOpen()); - - for(int i = 0; i < dataChartList.size(); i++) - { - if(borders.get(0) > dataChartList.get(i).getOpen()) - { - borders.set(0, dataChartList.get(i).getOpen()); - } - - if(borders.get(1) < dataChartList.get(i).getOpen()) - { - borders.set(1, dataChartList.get(i).getOpen()); - } - } - - return borders; - } - private void updateColor(View view, Currency currency) { if(currency.getDayFluctuationPercentage() > 0) From bff5b583533b56dd044305e024b128d375a2cc8a Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Sun, 8 Apr 2018 02:25:03 +0200 Subject: [PATCH 17/34] Fix and improvement -Add hide balance feature for cardview -Fix color arrow changing color for every cardview --- .../coinfolio/Activities/HomeActivity.java | 18 +- .../CurrencyCardViewAdapter.java | 173 ++++++++++ .../LayoutManagers/CurrencyViewHolder.java | 50 +++ ...CardView.java => HomeLayoutGenerator.java} | 45 +-- .../SummaryCurrencyCardView.java | 304 ++++++++++++++++++ app/src/main/res/layout/cardview_currency.xml | 43 ++- .../res/layout/content_currency_summary.xml | 2 +- 7 files changed, 594 insertions(+), 41 deletions(-) create mode 100644 app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyCardViewAdapter.java create mode 100644 app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyViewHolder.java rename app/src/main/java/com/nauk/coinfolio/LayoutManagers/{CurrencyCardView.java => HomeLayoutGenerator.java} (87%) create mode 100644 app/src/main/java/com/nauk/coinfolio/LayoutManagers/SummaryCurrencyCardView.java 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 1e988ba..791d9de 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -6,20 +6,18 @@ import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; -import android.graphics.drawable.AnimationDrawable; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.Looper; -import android.support.annotation.NonNull; import android.support.design.widget.AppBarLayout; -import android.support.design.widget.BottomNavigationView; import android.support.design.widget.CollapsingToolbarLayout; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.AppCompatActivity; import android.support.v7.graphics.Palette; +import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.text.SpannableString; import android.util.Log; @@ -48,7 +46,8 @@ import com.nauk.coinfolio.DataManagers.BalanceManager; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.MarketCapManager; import com.nauk.coinfolio.DataManagers.PreferencesManager; -import com.nauk.coinfolio.LayoutManagers.CurrencyCardView; +import com.nauk.coinfolio.LayoutManagers.HomeLayoutGenerator; +import com.nauk.coinfolio.LayoutManagers.SummaryCurrencyCardView; import com.nauk.coinfolio.R; import java.io.IOException; @@ -95,6 +94,7 @@ public class HomeActivity extends AppCompatActivity { private Handler handler; private Runnable updateRunnable; private ViewFlipper viewFlipper; + private HomeLayoutGenerator layoutGenerator; private HashMap dominantCurrenciesColors; @@ -149,6 +149,8 @@ public class HomeActivity extends AppCompatActivity { viewFlipper = findViewById(R.id.viewFlipperSummary); viewFlipper.setDisplayedChild(1); + layoutGenerator = new HomeLayoutGenerator(this); + ImageButton addCurrencyButton = findViewById(R.id.floatingAddButton); ImageButton detailsButton = findViewById(R.id.switch_button); ImageButton settingsButton = findViewById(R.id.settings_button); @@ -422,7 +424,9 @@ public class HomeActivity extends AppCompatActivity { if(!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001 || currency.getHistoryMinutes() == null)) { - currencyLayout.addView(new CurrencyCardView(this, currencyLayout).getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden())); + //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())); } } @@ -829,7 +833,9 @@ 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 CurrencyCardView(getApplicationContext(), currencyLayout).getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden())); + //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/LayoutManagers/CurrencyCardViewAdapter.java b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyCardViewAdapter.java new file mode 100644 index 0000000..1315313 --- /dev/null +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyCardViewAdapter.java @@ -0,0 +1,173 @@ +package com.nauk.coinfolio.LayoutManagers; + +import android.content.Context; +import android.content.Intent; +import android.graphics.Color; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ProgressBar; + +import com.github.mikephil.charting.charts.LineChart; +import com.github.mikephil.charting.data.Entry; +import com.github.mikephil.charting.data.LineData; +import com.github.mikephil.charting.data.LineDataSet; +import com.nauk.coinfolio.Activities.CurrencyDetailsActivity; +import com.nauk.coinfolio.Activities.HomeActivity; +import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; +import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart; +import com.nauk.coinfolio.R; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import static java.lang.Math.abs; + +/** + * Created by Tiji on 07/04/2018. + */ + +public class CurrencyCardViewAdapter extends RecyclerView.Adapter { + + List currencies; + Context context; + boolean isBalanceHidden; + float totalValue; + + public CurrencyCardViewAdapter(Context context, List currencies, boolean isExtended, float totalValue, boolean isBalanceHidden) + { + this.context = context; + this.currencies = currencies; + this.totalValue = totalValue; + this.isBalanceHidden = isBalanceHidden; + } + + @NonNull + @Override + public CurrencyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_currency, parent, false); + return new CurrencyViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull CurrencyViewHolder holder, int position) { + holder.currencyIcon.setImageBitmap(currencies.get(position).getIcon()); + holder.currencyNameTextView.setText(currencies.get(position).getName()); + holder.currencySymbolTextView.setText(context.getResources().getString(R.string.currencySymbolPlaceholder, currencies.get(position).getSymbol())); + holder.currencyOwnedTextView.setText(context.getResources().getString(R.string.currencyBalancePlaceholder, numberConformer(currencies.get(position).getBalance()), currencies.get(position).getSymbol())); + holder.currencyValueOwnedTextView.setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currencies.get(position).getValue() * currencies.get(position).getBalance()))); + holder.currencyValueTextView.setText(context.getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(currencies.get(position).getValue()))); + holder.currencyFluctuationPercentageTextView.setText(currencies.get(position).getName()); + holder.currencyNameTextView.setText(context.getResources().getString(R.string.currencyPercentagePlaceholder, numberConformer(currencies.get(position).getDayFluctuationPercentage()))); + holder.currencyFluctuationTextView.setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currencies.get(position).getDayFluctuation()))); + holder.detailsArrow.getDrawable().setColorFilter(new PorterDuffColorFilter(currencies.get(position).getChartColor(), PorterDuff.Mode.SRC_IN)); + + if(isBalanceHidden) + { + double value = currencies.get(position).getValue() * currencies.get(position).getBalance(); + double percentage = value / totalValue * 100; + + holder.dominancePercentageProgrressBar.setVisibility(View.VISIBLE); + holder.dominancePercentageProgrressBar.setProgress((int) Math.round(percentage)); + holder.dominancePercentageProgrressBar.getIndeterminateDrawable().setColorFilter(currencies.get(position).getChartColor(), PorterDuff.Mode.SRC_ATOP); + } + else + { + holder.dominancePercentageProgrressBar.setVisibility(View.GONE); + } + } + + @Override + public int getItemCount() { + return 0; + } + + private void setupLineChart(View view, final Currency currency) + { + LineChart lineChart = view.findViewById(R.id.LineChartView); + + lineChart.setDrawGridBackground(false); + lineChart.setDrawBorders(false); + lineChart.setDrawMarkers(false); + lineChart.setDoubleTapToZoomEnabled(false); + lineChart.setPinchZoom(false); + lineChart.setScaleEnabled(false); + lineChart.setDragEnabled(false); + lineChart.getDescription().setEnabled(false); + lineChart.getAxisLeft().setEnabled(false); + lineChart.getAxisRight().setEnabled(false); + lineChart.getLegend().setEnabled(false); + lineChart.getXAxis().setEnabled(false); + lineChart.setViewPortOffsets(0, 0, 0, 0); + lineChart.setData(generateData(currency)); + + /*lineChart.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(HomeActivity.class, CurrencyDetailsActivity.class); + intent.putExtra("currency", currency); + context.getApplicationContext().startActivity(intent); + } + });*/ + } + + private LineData generateData(Currency currency) + { + LineDataSet dataSet; + List dataChartList = currency.getHistoryMinutes(); + ArrayList values = new ArrayList<>(); + + for(int i = 0; i < dataChartList.size(); i+=10) + { + values.add(new Entry(i, (float) dataChartList.get(i).getOpen())); + } + + dataSet = new LineDataSet(values, "History"); + dataSet.setDrawIcons(false); + dataSet.setColor(currency.getChartColor()); + dataSet.setLineWidth(1); + dataSet.setDrawFilled(true); + dataSet.setFillColor(getColorWithAplha(currency.getChartColor(), 0.5f)); + dataSet.setFormLineWidth(1); + dataSet.setFormSize(15); + dataSet.setDrawCircles(false); + dataSet.setDrawValues(false); + dataSet.setHighlightEnabled(false); + + return new LineData(dataSet); + } + + private int getColorWithAplha(int color, float ratio) + { + int transColor; + int alpha = Math.round(Color.alpha(color) * ratio); + int r = Color.red(color); + int g = Color.green(color); + int b = Color.blue(color); + + transColor = Color.argb(alpha, r, g, b); + + return transColor ; + } + + private String numberConformer(double number) + { + String str; + + if(abs(number) > 1) + { + str = String.format( Locale.UK, "%.2f", number); + } + else + { + str = String.format( Locale.UK, "%.4f", number); + } + + return str; + } +} diff --git a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyViewHolder.java b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyViewHolder.java new file mode 100644 index 0000000..5d1d434 --- /dev/null +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyViewHolder.java @@ -0,0 +1,50 @@ +package com.nauk.coinfolio.LayoutManagers; + +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.ProgressBar; +import android.widget.TextView; + +import com.github.mikephil.charting.charts.LineChart; +import com.nauk.coinfolio.R; + +/** + * Created by Tiji on 07/04/2018. + */ + +public class CurrencyViewHolder extends RecyclerView.ViewHolder { + + protected ProgressBar dominancePercentageProgrressBar; + protected ImageView currencyIcon; + protected TextView currencyNameTextView; + protected TextView currencySymbolTextView; + protected TextView currencyValueTextView; + protected TextView currencyOwnedTextView; + protected TextView currencyValueOwnedTextView; + protected TextView currencyFluctuationPercentageTextView; + protected TextView currencyFluctuationTextView; + protected LinearLayout collapsableLayout; + protected LineChart lineChart; + protected ImageView detailsArrow; + + public CurrencyViewHolder(View v) + { + super(v); + + dominancePercentageProgrressBar = v.findViewById(R.id.currencyPortfolioDominance); + currencyIcon = v.findViewById(R.id.currencyIcon); + currencyNameTextView = v.findViewById(R.id.currencyNameTextView); + currencySymbolTextView = v.findViewById(R.id.currencySymbolTextView); + currencyValueTextView = v.findViewById(R.id.currencyValueTextView); + currencyOwnedTextView = v.findViewById(R.id.currencyOwnedTextView); + currencyValueOwnedTextView = v.findViewById(R.id.currencyValueOwnedTextView); + currencyFluctuationPercentageTextView = v.findViewById(R.id.currencyFluctuationPercentageTextView); + currencyFluctuationTextView = v.findViewById(R.id.currencyFluctuationTextView); + collapsableLayout = v.findViewById(R.id.collapsableLayout); + lineChart = v.findViewById(R.id.LineChartView); + detailsArrow = v.findViewById(R.id.detailsArrow); + } + +} diff --git a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyCardView.java b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java similarity index 87% rename from app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyCardView.java rename to app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java index 45de5fc..2b9e0e7 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyCardView.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java @@ -5,24 +5,16 @@ import android.content.Intent; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; -import android.os.Bundle; +import android.graphics.drawable.Drawable; import android.support.v7.widget.CardView; -import android.support.v7.widget.RecyclerView; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.Transformation; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; -import com.db.chart.model.ChartSet; -import com.db.chart.model.LineSet; -import com.db.chart.renderer.AxisRenderer; -import com.db.chart.view.LineChartView; import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.LineData; @@ -32,9 +24,8 @@ import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart; import com.nauk.coinfolio.R; +import java.text.DecimalFormat; import java.util.ArrayList; -import java.util.Calendar; -import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -44,21 +35,18 @@ import static java.lang.Math.abs; * Created by Tiji on 05/01/2018. */ -public class CurrencyCardView extends CardView { +public class HomeLayoutGenerator { - android.content.Context context; - private LinearLayout rootLayout; + private android.content.Context context; - public CurrencyCardView(Context context, LinearLayout rootLayout) + public HomeLayoutGenerator(Context context) { - super(context); this.context = context; - this.rootLayout = rootLayout; } public View getInfoLayout(final Currency currency, boolean isExtended, float totalValue, boolean isBalanceHidden) { - View view = LayoutInflater.from(context).inflate(R.layout.cardview_currency, rootLayout, true); + View view = LayoutInflater.from(context).inflate(R.layout.cardview_currency, null, true); view.setOnClickListener(new View.OnClickListener() { @Override @@ -194,21 +182,36 @@ public class CurrencyCardView extends CardView { .setText(context.getResources().getString(R.string.currencyPercentagePlaceholder, numberConformer(currency.getDayFluctuationPercentage()))); ((TextView) view.findViewById(R.id.currencyFluctuationTextView)) .setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getDayFluctuation()))); - ((ImageView) view.findViewById(R.id.detailsArrow)) - .getDrawable().setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + + Drawable arrowDrawable = ((ImageView) view.findViewById(R.id.detailsArrow)).getDrawable(); + arrowDrawable.mutate(); + arrowDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + arrowDrawable.invalidateSelf(); + + Drawable progressBarDrawable = ((ProgressBar) view.findViewById(R.id.currencyPortfolioDominance)).getProgressDrawable(); + progressBarDrawable.mutate(); + progressBarDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + progressBarDrawable.invalidateSelf(); 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)); - ((ProgressBar) view.findViewById(R.id.currencyPortfolioDominance)).getIndeterminateDrawable().setColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_ATOP); + + 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.percentageOwnedTextView).setVisibility(View.GONE); + view.findViewById(R.id.currencyOwnedInfoLayout).setVisibility(View.VISIBLE); } } diff --git a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/SummaryCurrencyCardView.java b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/SummaryCurrencyCardView.java new file mode 100644 index 0000000..eced15e --- /dev/null +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/SummaryCurrencyCardView.java @@ -0,0 +1,304 @@ +package com.nauk.coinfolio.LayoutManagers; + +import android.content.Context; +import android.content.Intent; +import android.graphics.Color; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; +import android.support.v7.widget.CardView; +import android.support.v7.widget.RecyclerView; +import android.util.AttributeSet; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.animation.Animation; +import android.view.animation.Transformation; +import android.widget.ImageView; +import android.widget.ProgressBar; +import android.widget.TextView; + +import com.github.mikephil.charting.charts.LineChart; +import com.github.mikephil.charting.data.Entry; +import com.github.mikephil.charting.data.LineData; +import com.github.mikephil.charting.data.LineDataSet; +import com.nauk.coinfolio.Activities.CurrencyDetailsActivity; +import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; +import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart; +import com.nauk.coinfolio.R; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import static java.lang.Math.abs; + +/** + * Created by Tiji on 06/04/2018. + */ + +public class SummaryCurrencyCardView extends CardView implements View.OnClickListener { + + public SummaryCurrencyCardView(Context context) + { + this(context, null, false, 0, false); + } + + public SummaryCurrencyCardView(Context context, final Currency currency, boolean isExtended, float totalValue, boolean isBalanceHidden) + { + super(context, null, 0); + + LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + inflater.inflate(R.layout.cardview_currency, this, true); + + setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Log.d("coinfolio", "Clicked"); + if(view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE) + { + collapseView(); + } + else + { + extendView(); + } + } + }); + + //updateCardViewInfos(currency, totalValue, isBalanceHidden); + updateCardViewInfos(currency, totalValue, true); + + setupLineChart(currency); + + if(isExtended) + { + extendView(); + } + else + { + collapseView(); + } + + updateColor(currency); + } + + @Override + public void onClick(View view) + { + Log.d("coinfolio", "Clicked"); + + if(view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE) + { + collapseView(); + } + else + { + extendView(); + } + } + + public static void expand(final View v) { + v.measure(CardView.LayoutParams.MATCH_PARENT, CardView.LayoutParams.WRAP_CONTENT); + final int targetHeight = v.getMeasuredHeight(); + + // Older versions of android (pre API 21) cancel animations for views with a height of 0. + v.getLayoutParams().height = 1; + v.setVisibility(View.VISIBLE); + Animation a = new Animation() + { + @Override + protected void applyTransformation(float interpolatedTime, Transformation t) { + v.getLayoutParams().height = interpolatedTime == 1 + ? CardView.LayoutParams.WRAP_CONTENT + : (int)(targetHeight * interpolatedTime); + v.requestLayout(); + } + + @Override + public boolean willChangeBounds() { + return true; + } + }; + + // 1dp/ms + a.setDuration((int)(targetHeight / v.getContext().getResources().getDisplayMetrics().density)); + v.startAnimation(a); + } + + public static void collapse(final View v) { + final int initialHeight = v.getMeasuredHeight(); + + Animation a = new Animation() + { + @Override + protected void applyTransformation(float interpolatedTime, Transformation t) { + if(interpolatedTime == 1){ + v.setVisibility(View.GONE); + }else{ + v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime); + v.requestLayout(); + } + } + + @Override + public boolean willChangeBounds() { + return true; + } + }; + + // 1dp/ms + a.setDuration((int)(initialHeight / v.getContext().getResources().getDisplayMetrics().density)); + v.startAnimation(a); + } + + private void setupLineChart(final Currency currency) + { + LineChart lineChart = findViewById(R.id.LineChartView); + + lineChart.setDrawGridBackground(false); + lineChart.setDrawBorders(false); + lineChart.setDrawMarkers(false); + lineChart.setDoubleTapToZoomEnabled(false); + lineChart.setPinchZoom(false); + lineChart.setScaleEnabled(false); + lineChart.setDragEnabled(false); + lineChart.getDescription().setEnabled(false); + lineChart.getAxisLeft().setEnabled(false); + lineChart.getAxisRight().setEnabled(false); + lineChart.getLegend().setEnabled(false); + lineChart.getXAxis().setEnabled(false); + lineChart.setViewPortOffsets(0, 0, 0, 0); + lineChart.setData(generateData(currency)); + + lineChart.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(getContext(), CurrencyDetailsActivity.class); + intent.putExtra("currency", currency); + getContext().startActivity(intent); + } + }); + } + + private void updateCardViewInfos(Currency currency, float totalValue, boolean isBalanceHidden) + { + ((ImageView) findViewById(R.id.currencyIcon)) + .setImageBitmap(currency.getIcon()); + ((TextView) findViewById(R.id.currencyNameTextView)) + .setText(currency.getName()); + ((TextView) findViewById(R.id.currencySymbolTextView)) + .setText(getResources().getString(R.string.currencySymbolPlaceholder, currency.getSymbol())); + ((TextView) findViewById(R.id.currencyOwnedTextView)) + .setText(getResources().getString(R.string.currencyBalancePlaceholder, numberConformer(currency.getBalance()), currency.getSymbol())); + ((TextView) findViewById(R.id.currencyValueOwnedTextView)) + .setText(getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getValue() * currency.getBalance()))); + + ((TextView) findViewById(R.id.currencyValueTextView)) + .setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(currency.getValue()))); + ((TextView) findViewById(R.id.currencyFluctuationPercentageTextView)) + .setText(getResources().getString(R.string.currencyPercentagePlaceholder, numberConformer(currency.getDayFluctuationPercentage()))); + ((TextView) findViewById(R.id.currencyFluctuationTextView)) + .setText(getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getDayFluctuation()))); + ((ImageView) findViewById(R.id.detailsArrow)) + .getDrawable().setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); + + if(isBalanceHidden) + { + double value = currency.getValue() * currency.getBalance(); + double percentage = value / totalValue * 100; + + findViewById(R.id.currencyPortfolioDominance).setVisibility(View.VISIBLE); + ((ProgressBar) findViewById(R.id.currencyPortfolioDominance)).setProgress((int) Math.round(percentage)); + ((ProgressBar) findViewById(R.id.currencyPortfolioDominance)).getIndeterminateDrawable().setColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_ATOP); + } + else + { + findViewById(R.id.currencyPortfolioDominance).setVisibility(View.GONE); + } + } + + private void collapseView() + { + collapse(findViewById(R.id.collapsableLayout)); + } + + private void extendView() + { + expand(findViewById(R.id.collapsableLayout)); + findViewById(R.id.LineChartView).invalidate(); + } + + private void updateColor(Currency currency) + { + if(currency.getDayFluctuationPercentage() > 0) + { + ((TextView) findViewById(R.id.currencyFluctuationPercentageTextView)) + .setTextColor(getResources().getColor(R.color.increase)); + ((TextView) findViewById(R.id.currencyFluctuationTextView)) + .setTextColor(getResources().getColor(R.color.increase)); + } + else + { + ((TextView) findViewById(R.id.currencyFluctuationPercentageTextView)) + .setTextColor(getResources().getColor(R.color.decrease)); + ((TextView) findViewById(R.id.currencyFluctuationTextView)) + .setTextColor(getResources().getColor(R.color.decrease)); + } + } + + private LineData generateData(Currency currency) + { + LineDataSet dataSet; + List dataChartList = currency.getHistoryMinutes(); + ArrayList values = new ArrayList<>(); + + for(int i = 0; i < dataChartList.size(); i+=10) + { + values.add(new Entry(i, (float) dataChartList.get(i).getOpen())); + } + + dataSet = new LineDataSet(values, "History"); + dataSet.setDrawIcons(false); + dataSet.setColor(currency.getChartColor()); + dataSet.setLineWidth(1); + dataSet.setDrawFilled(true); + dataSet.setFillColor(getColorWithAplha(currency.getChartColor(), 0.5f)); + dataSet.setFormLineWidth(1); + dataSet.setFormSize(15); + dataSet.setDrawCircles(false); + dataSet.setDrawValues(false); + dataSet.setHighlightEnabled(false); + + return new LineData(dataSet); + } + + private int getColorWithAplha(int color, float ratio) + { + int transColor; + int alpha = Math.round(Color.alpha(color) * ratio); + int r = Color.red(color); + int g = Color.green(color); + int b = Color.blue(color); + + transColor = Color.argb(alpha, r, g, b); + + return transColor ; + } + + private String numberConformer(double number) + { + String str; + + if(abs(number) > 1) + { + str = String.format( Locale.UK, "%.2f", number); + } + else + { + str = String.format( Locale.UK, "%.4f", number); + } + + return str; + } +} diff --git a/app/src/main/res/layout/cardview_currency.xml b/app/src/main/res/layout/cardview_currency.xml index cebcffb..3ebfcc7 100644 --- a/app/src/main/res/layout/cardview_currency.xml +++ b/app/src/main/res/layout/cardview_currency.xml @@ -86,27 +86,44 @@ android:orientation="horizontal"> - - + android:textSize="@dimen/cardViewSecondaryText" + android:visibility="gone"/> + + + + + + + + + android:orientation="vertical" /> Date: Sun, 8 Apr 2018 02:25:52 +0200 Subject: [PATCH 18/34] Remove unused class --- .../CurrencyCardViewAdapter.java | 173 ---------- .../LayoutManagers/CurrencyViewHolder.java | 50 --- .../SummaryCurrencyCardView.java | 304 ------------------ 3 files changed, 527 deletions(-) delete mode 100644 app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyCardViewAdapter.java delete mode 100644 app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyViewHolder.java delete mode 100644 app/src/main/java/com/nauk/coinfolio/LayoutManagers/SummaryCurrencyCardView.java diff --git a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyCardViewAdapter.java b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyCardViewAdapter.java deleted file mode 100644 index 1315313..0000000 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyCardViewAdapter.java +++ /dev/null @@ -1,173 +0,0 @@ -package com.nauk.coinfolio.LayoutManagers; - -import android.content.Context; -import android.content.Intent; -import android.graphics.Color; -import android.graphics.PorterDuff; -import android.graphics.PorterDuffColorFilter; -import android.support.annotation.NonNull; -import android.support.v7.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ProgressBar; - -import com.github.mikephil.charting.charts.LineChart; -import com.github.mikephil.charting.data.Entry; -import com.github.mikephil.charting.data.LineData; -import com.github.mikephil.charting.data.LineDataSet; -import com.nauk.coinfolio.Activities.CurrencyDetailsActivity; -import com.nauk.coinfolio.Activities.HomeActivity; -import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; -import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart; -import com.nauk.coinfolio.R; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -import static java.lang.Math.abs; - -/** - * Created by Tiji on 07/04/2018. - */ - -public class CurrencyCardViewAdapter extends RecyclerView.Adapter { - - List currencies; - Context context; - boolean isBalanceHidden; - float totalValue; - - public CurrencyCardViewAdapter(Context context, List currencies, boolean isExtended, float totalValue, boolean isBalanceHidden) - { - this.context = context; - this.currencies = currencies; - this.totalValue = totalValue; - this.isBalanceHidden = isBalanceHidden; - } - - @NonNull - @Override - public CurrencyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_currency, parent, false); - return new CurrencyViewHolder(view); - } - - @Override - public void onBindViewHolder(@NonNull CurrencyViewHolder holder, int position) { - holder.currencyIcon.setImageBitmap(currencies.get(position).getIcon()); - holder.currencyNameTextView.setText(currencies.get(position).getName()); - holder.currencySymbolTextView.setText(context.getResources().getString(R.string.currencySymbolPlaceholder, currencies.get(position).getSymbol())); - holder.currencyOwnedTextView.setText(context.getResources().getString(R.string.currencyBalancePlaceholder, numberConformer(currencies.get(position).getBalance()), currencies.get(position).getSymbol())); - holder.currencyValueOwnedTextView.setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currencies.get(position).getValue() * currencies.get(position).getBalance()))); - holder.currencyValueTextView.setText(context.getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(currencies.get(position).getValue()))); - holder.currencyFluctuationPercentageTextView.setText(currencies.get(position).getName()); - holder.currencyNameTextView.setText(context.getResources().getString(R.string.currencyPercentagePlaceholder, numberConformer(currencies.get(position).getDayFluctuationPercentage()))); - holder.currencyFluctuationTextView.setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currencies.get(position).getDayFluctuation()))); - holder.detailsArrow.getDrawable().setColorFilter(new PorterDuffColorFilter(currencies.get(position).getChartColor(), PorterDuff.Mode.SRC_IN)); - - if(isBalanceHidden) - { - double value = currencies.get(position).getValue() * currencies.get(position).getBalance(); - double percentage = value / totalValue * 100; - - holder.dominancePercentageProgrressBar.setVisibility(View.VISIBLE); - holder.dominancePercentageProgrressBar.setProgress((int) Math.round(percentage)); - holder.dominancePercentageProgrressBar.getIndeterminateDrawable().setColorFilter(currencies.get(position).getChartColor(), PorterDuff.Mode.SRC_ATOP); - } - else - { - holder.dominancePercentageProgrressBar.setVisibility(View.GONE); - } - } - - @Override - public int getItemCount() { - return 0; - } - - private void setupLineChart(View view, final Currency currency) - { - LineChart lineChart = view.findViewById(R.id.LineChartView); - - lineChart.setDrawGridBackground(false); - lineChart.setDrawBorders(false); - lineChart.setDrawMarkers(false); - lineChart.setDoubleTapToZoomEnabled(false); - lineChart.setPinchZoom(false); - lineChart.setScaleEnabled(false); - lineChart.setDragEnabled(false); - lineChart.getDescription().setEnabled(false); - lineChart.getAxisLeft().setEnabled(false); - lineChart.getAxisRight().setEnabled(false); - lineChart.getLegend().setEnabled(false); - lineChart.getXAxis().setEnabled(false); - lineChart.setViewPortOffsets(0, 0, 0, 0); - lineChart.setData(generateData(currency)); - - /*lineChart.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(HomeActivity.class, CurrencyDetailsActivity.class); - intent.putExtra("currency", currency); - context.getApplicationContext().startActivity(intent); - } - });*/ - } - - private LineData generateData(Currency currency) - { - LineDataSet dataSet; - List dataChartList = currency.getHistoryMinutes(); - ArrayList values = new ArrayList<>(); - - for(int i = 0; i < dataChartList.size(); i+=10) - { - values.add(new Entry(i, (float) dataChartList.get(i).getOpen())); - } - - dataSet = new LineDataSet(values, "History"); - dataSet.setDrawIcons(false); - dataSet.setColor(currency.getChartColor()); - dataSet.setLineWidth(1); - dataSet.setDrawFilled(true); - dataSet.setFillColor(getColorWithAplha(currency.getChartColor(), 0.5f)); - dataSet.setFormLineWidth(1); - dataSet.setFormSize(15); - dataSet.setDrawCircles(false); - dataSet.setDrawValues(false); - dataSet.setHighlightEnabled(false); - - return new LineData(dataSet); - } - - private int getColorWithAplha(int color, float ratio) - { - int transColor; - int alpha = Math.round(Color.alpha(color) * ratio); - int r = Color.red(color); - int g = Color.green(color); - int b = Color.blue(color); - - transColor = Color.argb(alpha, r, g, b); - - return transColor ; - } - - private String numberConformer(double number) - { - String str; - - if(abs(number) > 1) - { - str = String.format( Locale.UK, "%.2f", number); - } - else - { - str = String.format( Locale.UK, "%.4f", number); - } - - return str; - } -} diff --git a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyViewHolder.java b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyViewHolder.java deleted file mode 100644 index 5d1d434..0000000 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyViewHolder.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.nauk.coinfolio.LayoutManagers; - -import android.support.v7.widget.RecyclerView; -import android.view.View; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.ProgressBar; -import android.widget.TextView; - -import com.github.mikephil.charting.charts.LineChart; -import com.nauk.coinfolio.R; - -/** - * Created by Tiji on 07/04/2018. - */ - -public class CurrencyViewHolder extends RecyclerView.ViewHolder { - - protected ProgressBar dominancePercentageProgrressBar; - protected ImageView currencyIcon; - protected TextView currencyNameTextView; - protected TextView currencySymbolTextView; - protected TextView currencyValueTextView; - protected TextView currencyOwnedTextView; - protected TextView currencyValueOwnedTextView; - protected TextView currencyFluctuationPercentageTextView; - protected TextView currencyFluctuationTextView; - protected LinearLayout collapsableLayout; - protected LineChart lineChart; - protected ImageView detailsArrow; - - public CurrencyViewHolder(View v) - { - super(v); - - dominancePercentageProgrressBar = v.findViewById(R.id.currencyPortfolioDominance); - currencyIcon = v.findViewById(R.id.currencyIcon); - currencyNameTextView = v.findViewById(R.id.currencyNameTextView); - currencySymbolTextView = v.findViewById(R.id.currencySymbolTextView); - currencyValueTextView = v.findViewById(R.id.currencyValueTextView); - currencyOwnedTextView = v.findViewById(R.id.currencyOwnedTextView); - currencyValueOwnedTextView = v.findViewById(R.id.currencyValueOwnedTextView); - currencyFluctuationPercentageTextView = v.findViewById(R.id.currencyFluctuationPercentageTextView); - currencyFluctuationTextView = v.findViewById(R.id.currencyFluctuationTextView); - collapsableLayout = v.findViewById(R.id.collapsableLayout); - lineChart = v.findViewById(R.id.LineChartView); - detailsArrow = v.findViewById(R.id.detailsArrow); - } - -} diff --git a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/SummaryCurrencyCardView.java b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/SummaryCurrencyCardView.java deleted file mode 100644 index eced15e..0000000 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/SummaryCurrencyCardView.java +++ /dev/null @@ -1,304 +0,0 @@ -package com.nauk.coinfolio.LayoutManagers; - -import android.content.Context; -import android.content.Intent; -import android.graphics.Color; -import android.graphics.PorterDuff; -import android.graphics.PorterDuffColorFilter; -import android.support.v7.widget.CardView; -import android.support.v7.widget.RecyclerView; -import android.util.AttributeSet; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.animation.Animation; -import android.view.animation.Transformation; -import android.widget.ImageView; -import android.widget.ProgressBar; -import android.widget.TextView; - -import com.github.mikephil.charting.charts.LineChart; -import com.github.mikephil.charting.data.Entry; -import com.github.mikephil.charting.data.LineData; -import com.github.mikephil.charting.data.LineDataSet; -import com.nauk.coinfolio.Activities.CurrencyDetailsActivity; -import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; -import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart; -import com.nauk.coinfolio.R; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -import static java.lang.Math.abs; - -/** - * Created by Tiji on 06/04/2018. - */ - -public class SummaryCurrencyCardView extends CardView implements View.OnClickListener { - - public SummaryCurrencyCardView(Context context) - { - this(context, null, false, 0, false); - } - - public SummaryCurrencyCardView(Context context, final Currency currency, boolean isExtended, float totalValue, boolean isBalanceHidden) - { - super(context, null, 0); - - LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - inflater.inflate(R.layout.cardview_currency, this, true); - - setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Log.d("coinfolio", "Clicked"); - if(view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE) - { - collapseView(); - } - else - { - extendView(); - } - } - }); - - //updateCardViewInfos(currency, totalValue, isBalanceHidden); - updateCardViewInfos(currency, totalValue, true); - - setupLineChart(currency); - - if(isExtended) - { - extendView(); - } - else - { - collapseView(); - } - - updateColor(currency); - } - - @Override - public void onClick(View view) - { - Log.d("coinfolio", "Clicked"); - - if(view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE) - { - collapseView(); - } - else - { - extendView(); - } - } - - public static void expand(final View v) { - v.measure(CardView.LayoutParams.MATCH_PARENT, CardView.LayoutParams.WRAP_CONTENT); - final int targetHeight = v.getMeasuredHeight(); - - // Older versions of android (pre API 21) cancel animations for views with a height of 0. - v.getLayoutParams().height = 1; - v.setVisibility(View.VISIBLE); - Animation a = new Animation() - { - @Override - protected void applyTransformation(float interpolatedTime, Transformation t) { - v.getLayoutParams().height = interpolatedTime == 1 - ? CardView.LayoutParams.WRAP_CONTENT - : (int)(targetHeight * interpolatedTime); - v.requestLayout(); - } - - @Override - public boolean willChangeBounds() { - return true; - } - }; - - // 1dp/ms - a.setDuration((int)(targetHeight / v.getContext().getResources().getDisplayMetrics().density)); - v.startAnimation(a); - } - - public static void collapse(final View v) { - final int initialHeight = v.getMeasuredHeight(); - - Animation a = new Animation() - { - @Override - protected void applyTransformation(float interpolatedTime, Transformation t) { - if(interpolatedTime == 1){ - v.setVisibility(View.GONE); - }else{ - v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime); - v.requestLayout(); - } - } - - @Override - public boolean willChangeBounds() { - return true; - } - }; - - // 1dp/ms - a.setDuration((int)(initialHeight / v.getContext().getResources().getDisplayMetrics().density)); - v.startAnimation(a); - } - - private void setupLineChart(final Currency currency) - { - LineChart lineChart = findViewById(R.id.LineChartView); - - lineChart.setDrawGridBackground(false); - lineChart.setDrawBorders(false); - lineChart.setDrawMarkers(false); - lineChart.setDoubleTapToZoomEnabled(false); - lineChart.setPinchZoom(false); - lineChart.setScaleEnabled(false); - lineChart.setDragEnabled(false); - lineChart.getDescription().setEnabled(false); - lineChart.getAxisLeft().setEnabled(false); - lineChart.getAxisRight().setEnabled(false); - lineChart.getLegend().setEnabled(false); - lineChart.getXAxis().setEnabled(false); - lineChart.setViewPortOffsets(0, 0, 0, 0); - lineChart.setData(generateData(currency)); - - lineChart.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(getContext(), CurrencyDetailsActivity.class); - intent.putExtra("currency", currency); - getContext().startActivity(intent); - } - }); - } - - private void updateCardViewInfos(Currency currency, float totalValue, boolean isBalanceHidden) - { - ((ImageView) findViewById(R.id.currencyIcon)) - .setImageBitmap(currency.getIcon()); - ((TextView) findViewById(R.id.currencyNameTextView)) - .setText(currency.getName()); - ((TextView) findViewById(R.id.currencySymbolTextView)) - .setText(getResources().getString(R.string.currencySymbolPlaceholder, currency.getSymbol())); - ((TextView) findViewById(R.id.currencyOwnedTextView)) - .setText(getResources().getString(R.string.currencyBalancePlaceholder, numberConformer(currency.getBalance()), currency.getSymbol())); - ((TextView) findViewById(R.id.currencyValueOwnedTextView)) - .setText(getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getValue() * currency.getBalance()))); - - ((TextView) findViewById(R.id.currencyValueTextView)) - .setText(getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(currency.getValue()))); - ((TextView) findViewById(R.id.currencyFluctuationPercentageTextView)) - .setText(getResources().getString(R.string.currencyPercentagePlaceholder, numberConformer(currency.getDayFluctuationPercentage()))); - ((TextView) findViewById(R.id.currencyFluctuationTextView)) - .setText(getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getDayFluctuation()))); - ((ImageView) findViewById(R.id.detailsArrow)) - .getDrawable().setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); - - if(isBalanceHidden) - { - double value = currency.getValue() * currency.getBalance(); - double percentage = value / totalValue * 100; - - findViewById(R.id.currencyPortfolioDominance).setVisibility(View.VISIBLE); - ((ProgressBar) findViewById(R.id.currencyPortfolioDominance)).setProgress((int) Math.round(percentage)); - ((ProgressBar) findViewById(R.id.currencyPortfolioDominance)).getIndeterminateDrawable().setColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_ATOP); - } - else - { - findViewById(R.id.currencyPortfolioDominance).setVisibility(View.GONE); - } - } - - private void collapseView() - { - collapse(findViewById(R.id.collapsableLayout)); - } - - private void extendView() - { - expand(findViewById(R.id.collapsableLayout)); - findViewById(R.id.LineChartView).invalidate(); - } - - private void updateColor(Currency currency) - { - if(currency.getDayFluctuationPercentage() > 0) - { - ((TextView) findViewById(R.id.currencyFluctuationPercentageTextView)) - .setTextColor(getResources().getColor(R.color.increase)); - ((TextView) findViewById(R.id.currencyFluctuationTextView)) - .setTextColor(getResources().getColor(R.color.increase)); - } - else - { - ((TextView) findViewById(R.id.currencyFluctuationPercentageTextView)) - .setTextColor(getResources().getColor(R.color.decrease)); - ((TextView) findViewById(R.id.currencyFluctuationTextView)) - .setTextColor(getResources().getColor(R.color.decrease)); - } - } - - private LineData generateData(Currency currency) - { - LineDataSet dataSet; - List dataChartList = currency.getHistoryMinutes(); - ArrayList values = new ArrayList<>(); - - for(int i = 0; i < dataChartList.size(); i+=10) - { - values.add(new Entry(i, (float) dataChartList.get(i).getOpen())); - } - - dataSet = new LineDataSet(values, "History"); - dataSet.setDrawIcons(false); - dataSet.setColor(currency.getChartColor()); - dataSet.setLineWidth(1); - dataSet.setDrawFilled(true); - dataSet.setFillColor(getColorWithAplha(currency.getChartColor(), 0.5f)); - dataSet.setFormLineWidth(1); - dataSet.setFormSize(15); - dataSet.setDrawCircles(false); - dataSet.setDrawValues(false); - dataSet.setHighlightEnabled(false); - - return new LineData(dataSet); - } - - private int getColorWithAplha(int color, float ratio) - { - int transColor; - int alpha = Math.round(Color.alpha(color) * ratio); - int r = Color.red(color); - int g = Color.green(color); - int b = Color.blue(color); - - transColor = Color.argb(alpha, r, g, b); - - return transColor ; - } - - private String numberConformer(double number) - { - String str; - - if(abs(number) > 1) - { - str = String.format( Locale.UK, "%.2f", number); - } - else - { - str = String.format( Locale.UK, "%.4f", number); - } - - return str; - } -} From b1c158291af57bd8bb9a89e38141334239e01989 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Sun, 8 Apr 2018 02:31:38 +0200 Subject: [PATCH 19/34] Fix hide balance switch button --- .../java/com/nauk/coinfolio/Activities/HomeActivity.java | 2 -- .../com/nauk/coinfolio/Activities/SettingsActivity.java | 9 ++++----- 2 files changed, 4 insertions(+), 7 deletions(-) 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 791d9de..8db816a 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -17,7 +17,6 @@ import android.support.design.widget.Snackbar; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.AppCompatActivity; import android.support.v7.graphics.Palette; -import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.text.SpannableString; import android.util.Log; @@ -47,7 +46,6 @@ import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.MarketCapManager; import com.nauk.coinfolio.DataManagers.PreferencesManager; import com.nauk.coinfolio.LayoutManagers.HomeLayoutGenerator; -import com.nauk.coinfolio.LayoutManagers.SummaryCurrencyCardView; import com.nauk.coinfolio.R; import java.io.IOException; 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 b1afeed..8614ce3 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java @@ -218,17 +218,16 @@ public class SettingsActivity extends AppCompatPreferenceActivity { ((SwitchPreference) findPreference("hide_balance")).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { - boolean isChecked = !((SwitchPreference) findPreference("hide_balance")).isChecked(); - - ((SwitchPreference) findPreference("hide_balance")).setChecked(isChecked); + boolean isChecked = ((SwitchPreference) findPreference("hide_balance")).isChecked(); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext()); - SharedPreferences.Editor editor = preference.getEditor(); + SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean("hide_balance", isChecked); editor.apply(); - return false; + + return isChecked; } }); } From 16c429d4155c7c2ab9aa900b8bb93094398cac7b Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Sun, 8 Apr 2018 02:48:39 +0200 Subject: [PATCH 20/34] Add update on exchange synchronization enabled/disabled --- .../coinfolio/Activities/HomeActivity.java | 8 +++-- .../Activities/SettingsActivity.java | 33 +++++++++++++++++++ .../DataManagers/PreferencesManager.java | 14 ++++++++ app/src/main/res/layout/cardview_currency.xml | 2 +- 4 files changed, 53 insertions(+), 4 deletions(-) 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 8db816a..e5ccc79 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -345,8 +345,7 @@ public class HomeActivity extends AppCompatActivity { //addTestWatchlistCardview(); - Intent intent = getIntent(); - updateAll(intent.getBooleanExtra("update", false)); + updateAll(preferencesManager.mustUpdate()); ((SpaceNavigationView) findViewById(R.id.space)).changeCenterButtonIcon(R.drawable.ic_view_list_white_24dp); } @@ -884,7 +883,10 @@ public class HomeActivity extends AppCompatActivity { @Override protected Void doInBackground(Void... params) { - Looper.prepare(); + if(Looper.myLooper() == null) + { + Looper.prepare(); + } balanceManager.sortCoins(); 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 8614ce3..f18d8a5 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/SettingsActivity.java @@ -225,6 +225,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean("hide_balance", isChecked); + editor.putBoolean("mustUpdate", true); editor.apply(); return isChecked; @@ -267,6 +268,38 @@ public class SettingsActivity extends AppCompatPreferenceActivity { bindPreferenceSummaryToValue(findPreference("hitbtc_privatekey")); bindPreferenceSummaryToValue(findPreference("binance_privatekey")); + ((SwitchPreference) findPreference("enable_hitbtc")).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + boolean isChecked = ((SwitchPreference) findPreference("enable_hitbtc")).isChecked(); + + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext()); + + SharedPreferences.Editor editor = preferences.edit(); + + editor.putBoolean("mustUpdate", true); + editor.apply(); + + return isChecked; + } + }); + + ((SwitchPreference) findPreference("enable_binance")).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + boolean isChecked = ((SwitchPreference) findPreference("enable_binance")).isChecked(); + + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext()); + + SharedPreferences.Editor editor = preferences.edit(); + + editor.putBoolean("mustUpdate", true); + editor.apply(); + + return isChecked; + } + }); + startFingerprintProtocol(); } diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java index b676291..775da59 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java @@ -91,4 +91,18 @@ public class PreferencesManager { editor.putBoolean("enable_binance", false); editor.apply(); } + + public boolean mustUpdate() + { + boolean mustUpdate = settingPreferences.getBoolean("mustUpdate", false); + + if(mustUpdate) + { + SharedPreferences.Editor editor = settingPreferences.edit(); + editor.putBoolean("mustUpdate", false); + editor.apply(); + } + + return mustUpdate; + } } diff --git a/app/src/main/res/layout/cardview_currency.xml b/app/src/main/res/layout/cardview_currency.xml index 3ebfcc7..3566074 100644 --- a/app/src/main/res/layout/cardview_currency.xml +++ b/app/src/main/res/layout/cardview_currency.xml @@ -91,7 +91,7 @@ android:layout_height="wrap_content" android:gravity="start" android:textColor="@color/secondaryTextViewColor" - android:textSize="@dimen/cardViewSecondaryText" + android:textSize="@dimen/cardViewMainText" android:visibility="gone"/> Date: Sun, 8 Apr 2018 02:53:57 +0200 Subject: [PATCH 21/34] Add auto update when adding/removing manual transaction --- .../coinfolio/Activities/CurrencyDetailsActivity.java | 4 ++++ .../Activities/RecordTransactionActivity.java | 6 +++++- .../coinfolio/DataManagers/PreferencesManager.java | 11 ++++++++--- 3 files changed, 17 insertions(+), 4 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 17ad8c4..596ef95 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -40,6 +40,7 @@ import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart; import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction; import com.nauk.coinfolio.DataManagers.DatabaseManager; +import com.nauk.coinfolio.DataManagers.PreferencesManager; import com.nauk.coinfolio.R; import java.text.DecimalFormat; @@ -71,6 +72,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private List dataChartList; private LineChart lineChart; private BarChart barChart; + private PreferencesManager preferencesManager; private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() { @@ -122,6 +124,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { currency = intent.getParcelableExtra("currency"); databaseManager = new DatabaseManager(this); + preferencesManager = new PreferencesManager(this); viewFlipper = findViewById(R.id.vfCurrencyDetails); transactionLayout = findViewById(R.id.listTransactions); @@ -664,6 +667,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { deleteLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { + preferencesManager.setMustUpdate(true); databaseManager.deleteTransactionFromId(Integer.parseInt(view.getTag().toString())); drawTransactionList(); hasBeenModified = true; diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java index a6ffcc1..59851ae 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java @@ -3,6 +3,7 @@ package com.nauk.coinfolio.Activities; import android.app.DatePickerDialog; import android.content.Intent; import android.os.Bundle; +import android.preference.PreferenceManager; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; @@ -13,6 +14,7 @@ import android.widget.TextView; import android.widget.TimePicker; import com.nauk.coinfolio.DataManagers.DatabaseManager; +import com.nauk.coinfolio.DataManagers.PreferencesManager; import com.nauk.coinfolio.R; import java.text.SimpleDateFormat; @@ -30,6 +32,7 @@ public class RecordTransactionActivity extends AppCompatActivity { private DatabaseManager databaseManager; private Calendar calendar; private SimpleDateFormat sdf; + private PreferencesManager preferenceManager; @Override protected void onCreate(Bundle savedInstanceState) { @@ -47,6 +50,7 @@ public class RecordTransactionActivity extends AppCompatActivity { calendar = Calendar.getInstance(); databaseManager = new DatabaseManager(this); + preferenceManager = new PreferencesManager(this); validateButton = findViewById(R.id.validateButton); amountTxtView = findViewById(R.id.currencyAmount); @@ -65,8 +69,8 @@ public class RecordTransactionActivity extends AppCompatActivity { @Override public void onClick(View view) { databaseManager.addCurrencyToManualCurrency(symbol, Double.parseDouble(amountTxtView.getText().toString()), calendar.getTime()); + preferenceManager.setMustUpdate(true); Intent intent = new Intent(RecordTransactionActivity.this, HomeActivity.class); - intent.putExtra("update", true); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(intent); finish(); diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java index 775da59..3c4a3bf 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/PreferencesManager.java @@ -92,15 +92,20 @@ public class PreferencesManager { editor.apply(); } + public void setMustUpdate(boolean mustUpdate) + { + SharedPreferences.Editor editor = settingPreferences.edit(); + editor.putBoolean("mustUpdate", mustUpdate); + editor.apply(); + } + public boolean mustUpdate() { boolean mustUpdate = settingPreferences.getBoolean("mustUpdate", false); if(mustUpdate) { - SharedPreferences.Editor editor = settingPreferences.edit(); - editor.putBoolean("mustUpdate", false); - editor.apply(); + setMustUpdate(false); } return mustUpdate; From 1bf8aea3d99ff4f34f3f8d3c0a052ea3c6e12a0a Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Sun, 8 Apr 2018 16:50:56 +0200 Subject: [PATCH 22/34] 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"/> Date: Sun, 8 Apr 2018 20:21:02 +0200 Subject: [PATCH 23/34] Complete hide balance feature and fix title updating method --- .../coinfolio/Activities/HomeActivity.java | 126 +++++++++--------- 1 file changed, 61 insertions(+), 65 deletions(-) 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 c6e1f80..349cbd4 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -82,7 +82,8 @@ public class HomeActivity extends AppCompatActivity { private long lastTimestamp; private boolean detailsChecker; private boolean isDetailed; - private float totalValue; + protected float totalValue; + protected float totalFluctuation; private CollapsingToolbarLayout toolbarLayout; private SwipeRefreshLayout refreshLayout; @@ -154,6 +155,10 @@ public class HomeActivity extends AppCompatActivity { ImageButton settingsButton = findViewById(R.id.settings_button); toolbarLayout.setForegroundGravity(Gravity.CENTER); + + totalValue = 0; + totalFluctuation = 0; + updateTitle(); //Events setup @@ -223,24 +228,53 @@ public class HomeActivity extends AppCompatActivity { setupDominantCurrenciesColors(); } - protected void updateTitle(float totalValue, float totalFluctuation) + protected void updateTitle() { - float totalFluctuationPercentage = totalFluctuation / (totalValue - totalFluctuation) *100; - - if(loadingDialog.isShowing()) - { - loadingDialog.dismiss(); - } + float totalFluctuationPercentage = totalFluctuation / (totalValue - totalFluctuation) * 100; 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, "0.00")); - toolbarSubtitle.setText(getResources().getString(R.string.currencyDollarPlaceholder, "0.00")); - toolbarSubtitle.setText("US$" + String.format("%.2f", totalFluctuation) + " (" + String.format("%.2f", totalFluctuationPercentage) + "%)"); + 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 + { + toolbarSubtitle.setText("US$" + String.format("%.2f", totalFluctuation) + " (" + String.format("%.2f", totalFluctuationPercentage) + "%)"); + } } } @@ -373,6 +407,8 @@ public class HomeActivity extends AppCompatActivity { private void displayBalance(boolean hideBalance) { + updateTitle(); + if(hideBalance) { for(int i = 0; i < currencyLayout.getChildCount(); i++) @@ -499,6 +535,9 @@ public class HomeActivity extends AppCompatActivity { coinCounter = 0; iconCounter = 0; detailsChecker = false; + + totalValue = 0; + totalFluctuation = 0; } private void getBitmapFromURL(String src, IconCallBack callBack) { @@ -569,11 +608,8 @@ public class HomeActivity extends AppCompatActivity { runOnUiThread(new Runnable() { @Override public void run() { - toolbarLayout.setTitle(getResources().getString(R.string.currencyDollarPlaceholder, "0.00")); - toolbarSubtitle.setText(getResources().getString(R.string.currencyDollarPlaceholder, "0.00")); - - toolbarSubtitle.setTextColor(-1275068417); + updateTitle(); } }); } @@ -814,10 +850,6 @@ public class HomeActivity extends AppCompatActivity { private class UiHeavyLoadCalculator extends AsyncTask { - private float totalValue; - private float totalFluctuation; - private float totalFluctuationPercentage; - @Override protected void onPreExecute() { @@ -825,7 +857,6 @@ public class HomeActivity extends AppCompatActivity { totalValue = 0; totalFluctuation = 0; - totalFluctuationPercentage = 0; } @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 protected Void doInBackground(Void... params) { @@ -940,11 +930,17 @@ public class HomeActivity extends AppCompatActivity { balanceManager.getTotalBalance().set(i, localCurrency); } - toolbarLayout.setTitle("US$" + String.format("%.2f", totalValue)); + runOnUiThread(new Runnable() { + @Override + public void run() { + updateTitle(); + } + }); - updateFluctuation(); - - updateTitle(); + if(loadingDialog.isShowing()) + { + loadingDialog.dismiss(); + } return null; } From d2a296a2ef11d69b9e80acb5bafc98d224a25606 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Sun, 8 Apr 2018 20:24:34 +0200 Subject: [PATCH 24/34] Fix "NaN%" title when switching from display to hide balance --- .../java/com/nauk/coinfolio/Activities/HomeActivity.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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 349cbd4..d2a3f9d 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -397,12 +397,9 @@ public class HomeActivity extends AppCompatActivity { super.onResume(); //addTestWatchlistCardview(); - - updateAll(preferencesManager.mustUpdate()); - displayBalance(preferencesManager.isBalanceHidden()); - //((SpaceNavigationView) findViewById(R.id.space)).changeCenterButtonIcon(R.drawable.ic_view_list_white_24dp); + updateAll(preferencesManager.mustUpdate()); } private void displayBalance(boolean hideBalance) From 0ab73ddc87151e97366a674bac404981e75daf31 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Mon, 9 Apr 2018 16:28:42 +0200 Subject: [PATCH 25/34] Add trade history from Binance --- .../Activities/CurrencyDetailsActivity.java | 92 +++++++++++++++++++ .../Activities/RecordTransactionActivity.java | 24 ++++- .../DataManagers/CurrencyData/Currency.java | 27 ++++++ .../CurrencyData/CurrencyDataRetriever.java | 43 ++++++++- .../CurrencyData/Transaction.java | 13 ++- .../DataManagers/DatabaseManager.java | 7 +- .../ExchangeManager/BinanceManager.java | 54 ++++++++++- .../res/layout/activity_currency_details.xml | 77 +++++++++------- app/src/main/res/layout/custom_trade_row.xml | 82 +++++++++++++++++ 9 files changed, 376 insertions(+), 43 deletions(-) create mode 100644 app/src/main/res/layout/custom_trade_row.xml 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 22775b8..325dc2a 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -8,9 +8,11 @@ import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; +import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.BottomNavigationView; +import android.support.design.widget.Snackbar; import android.support.v4.app.NavUtils; import android.support.v4.content.ContextCompat; import android.support.v7.app.ActionBar; @@ -25,6 +27,7 @@ import android.widget.LinearLayout; import android.widget.TextView; import android.widget.ViewFlipper; +import com.binance.api.client.domain.account.Trade; import com.daimajia.swipe.SwipeLayout; import com.github.mikephil.charting.charts.BarChart; import com.github.mikephil.charting.charts.LineChart; @@ -36,10 +39,12 @@ import com.github.mikephil.charting.data.LineData; import com.github.mikephil.charting.data.LineDataSet; import com.github.mikephil.charting.highlight.Highlight; import com.github.mikephil.charting.listener.OnChartValueSelectedListener; +import com.nauk.coinfolio.DataManagers.BalanceManager; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart; import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction; import com.nauk.coinfolio.DataManagers.DatabaseManager; +import com.nauk.coinfolio.DataManagers.ExchangeManager.BinanceManager; import com.nauk.coinfolio.DataManagers.PreferencesManager; import com.nauk.coinfolio.R; @@ -60,6 +65,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private ViewFlipper viewFlipper; private LinearLayout transactionLayout; + private LinearLayout tradeLayout; private DatabaseManager databaseManager; //private String symbol; private Currency currency; @@ -73,6 +79,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private LineChart lineChart; private BarChart barChart; private PreferencesManager preferencesManager; + private BinanceManager binanceManager; private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() { @@ -128,8 +135,10 @@ public class CurrencyDetailsActivity extends AppCompatActivity { viewFlipper = findViewById(R.id.vfCurrencyDetails); transactionLayout = findViewById(R.id.listTransactions); + tradeLayout = findViewById(R.id.listTrades); lineChart = findViewById(R.id.chartPriceView); barChart = findViewById(R.id.chartVolumeView); + binanceManager = new BinanceManager(preferencesManager.getBinancePublicKey(), preferencesManager.getBinancePrivateKey()); ((BottomNavigationView) findViewById(R.id.navigation_details)).getMenu().getItem(1).setEnabled(false); @@ -145,6 +154,9 @@ public class CurrencyDetailsActivity extends AppCompatActivity { navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); hasBeenModified = false; + + TradeUpdater updater = new TradeUpdater(); + updater.execute(); } private void setupActionBar() @@ -644,6 +656,39 @@ public class CurrencyDetailsActivity extends AppCompatActivity { return transColor; } + private void drawTradeList(List trades, String pairSymbol) + { + findViewById(R.id.tradeProgressBar).setVisibility(View.GONE); + + tradeLayout.removeAllViews(); + + for(int i = trades.size()-1; i >= 0; i--) + { + View view = LayoutInflater.from(this).inflate(R.layout.custom_trade_row, null); + TextView amountTxtView = view.findViewById(R.id.amountPurchased); + TextView purchasedPrice = view.findViewById(R.id.purchasedPrice); + TextView tradePair = view.findViewById(R.id.pair); + TextView dateTxtView = view.findViewById(R.id.tradeDate); + View tradeIndicator = view.findViewById(R.id.tradeIndicator); + + if(trades.get(i).isBuyer()) + { + tradeIndicator.setBackgroundColor(getColor(R.color.green)); + } + else + { + tradeIndicator.setBackgroundColor(getColor(R.color.red)); + } + + amountTxtView.setText(String.valueOf(trades.get(i).getQty())); + purchasedPrice.setText(trades.get(i).getPrice()); + dateTxtView.setText(getDate(trades.get(i).getTime())); + tradePair.setText(currency.getSymbol() + "/" + pairSymbol); + + tradeLayout.addView(view); + } + } + private void drawTransactionList() { transactionLayout.removeAllViews(); @@ -723,6 +768,53 @@ public class CurrencyDetailsActivity extends AppCompatActivity { }); } + private class TradeUpdater extends AsyncTask + { + @Override + protected void onPreExecute() + { + super.onPreExecute(); + + findViewById(R.id.tradeProgressBar).setVisibility(View.VISIBLE); + } + + @Override + protected void onProgressUpdate(Integer... values) + { + super.onProgressUpdate(values); + } + + @Override + protected Void doInBackground(Void... params) + { + binanceManager.updateTrades(new BinanceManager.BinanceCallBack() { + @Override + public void onSuccess() { + final List trades = binanceManager.getTrades(); + + runOnUiThread(new Runnable() { + @Override + public void run() { + drawTradeList(trades, "ETH"); + } + }); + } + + @Override + public void onError(String error) { + + } + }, currency.getSymbol()); + + return null; + } + + @Override + protected void onPostExecute(Void result) + { + + } + } } /*for(int i = 0; i < dataChartList.size(); i++) {*/ diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java index 59851ae..50e34a2 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/RecordTransactionActivity.java @@ -13,6 +13,7 @@ import android.widget.EditText; import android.widget.TextView; import android.widget.TimePicker; +import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.DatabaseManager; import com.nauk.coinfolio.DataManagers.PreferencesManager; import com.nauk.coinfolio.R; @@ -33,6 +34,8 @@ public class RecordTransactionActivity extends AppCompatActivity { private Calendar calendar; private SimpleDateFormat sdf; private PreferencesManager preferenceManager; + private EditText purchasedPrice; + private Currency currency; @Override protected void onCreate(Bundle savedInstanceState) { @@ -49,13 +52,17 @@ public class RecordTransactionActivity extends AppCompatActivity { calendar = Calendar.getInstance(); + currency = new Currency(coin, symbol); + databaseManager = new DatabaseManager(this); preferenceManager = new PreferencesManager(this); validateButton = findViewById(R.id.validateButton); amountTxtView = findViewById(R.id.currencyAmount); purchasedDate = findViewById(R.id.purchaseDate); + purchasedPrice = findViewById(R.id.purchasePrice); + //purchasedPrice.setText(); purchasedDate.setText(sdf.format(calendar.getTime())); purchasedDate.setOnClickListener(new View.OnClickListener() { @@ -68,7 +75,7 @@ public class RecordTransactionActivity extends AppCompatActivity { validateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - databaseManager.addCurrencyToManualCurrency(symbol, Double.parseDouble(amountTxtView.getText().toString()), calendar.getTime()); + databaseManager.addCurrencyToManualCurrency(symbol, Double.parseDouble(amountTxtView.getText().toString()), calendar.getTime(), purchasedPrice.getText().toString()); preferenceManager.setMustUpdate(true); Intent intent = new Intent(RecordTransactionActivity.this, HomeActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); @@ -76,6 +83,13 @@ public class RecordTransactionActivity extends AppCompatActivity { finish(); } }); + + currency.getTimestampPrice(this, new Currency.PriceCallBack() { + @Override + public void onSuccess(String price) { + purchasedPrice.setText(price); + } + }, calendar.getTimeInMillis() / 1000); } private void createDatePicker() @@ -108,6 +122,14 @@ public class RecordTransactionActivity extends AppCompatActivity { calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minute); purchasedDate.setText(sdf.format(calendar.getTime())); + + currency.getTimestampPrice(RecordTransactionActivity.this, new Currency.PriceCallBack() { + @Override + public void onSuccess(String price) { + purchasedPrice.setText(price); + } + }, calendar.getTimeInMillis() / 1000); + Log.d("coinfolio", "Time : " + calendar.getTimeInMillis()); } }, calendar.get(Calendar.HOUR_OF_DAY), diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Currency.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Currency.java index 5befeb7..e84e742 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Currency.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Currency.java @@ -63,6 +63,21 @@ public class Currency implements Parcelable { this.symbol = symbol; } + public void getTimestampPrice(android.content.Context context, final PriceCallBack callBack, long timestamp) + { + dataRetriver = new CurrencyDataRetriever(context); + + dataRetriver.getPriceTimestamp(symbol, new CurrencyDataRetriever.DataChartCallBack() { + @Override + public void onSuccess(List dataChart) {} + + @Override + public void onSuccess(String price) { + callBack.onSuccess(price); + } + }, timestamp); + } + public void updateHistoryMinutes(android.content.Context context, final CurrencyCallBack callBack) { dataRetriver = new CurrencyDataRetriever(context); @@ -84,6 +99,9 @@ public class Currency implements Parcelable { callBack.onSuccess(Currency.this); } + + @Override + public void onSuccess(String result){} }, CurrencyDataRetriever.MINUTES); } @@ -97,6 +115,9 @@ public class Currency implements Parcelable { callBack.onSuccess(Currency.this); } + + @Override + public void onSuccess(String price) {} }, CurrencyDataRetriever.HOURS); } @@ -110,6 +131,9 @@ public class Currency implements Parcelable { callBack.onSuccess(Currency.this); } + + @Override + public void onSuccess(String price) {} }, CurrencyDataRetriever.DAYS); } @@ -237,6 +261,9 @@ public class Currency implements Parcelable { void onSuccess(Currency currency); } + public interface PriceCallBack { + void onSuccess(String price); + } @Override public int describeContents() { diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java index 2ffb89d..f4681bf 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataRetriever.java @@ -1,5 +1,6 @@ package com.nauk.coinfolio.DataManagers.CurrencyData; +import android.provider.ContactsContract; import android.util.Log; import com.android.volley.Request; @@ -42,6 +43,36 @@ public class CurrencyDataRetriever { requestQueue = Volley.newRequestQueue(context); } + private void getPriceTimestamp(final String symbolCurrencyFrom, String symbolCurrencyTo, final DataChartCallBack callBack, long timestamp) + { + final String requestUrl = "https://min-api.cryptocompare.com/data/pricehistorical?fsym=" + symbolCurrencyFrom + "&tsyms=" + symbolCurrencyTo + "&ts=" + timestamp; + + StringRequest stringRequest = new StringRequest(Request.Method.GET, requestUrl, + new Response.Listener() { + @Override + public void onResponse(String response) { + Log.d("coinfolio", response + " " + requestUrl); + callBack.onSuccess(processPriceTimestampResult(response)); + } + }, + new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + + } + }); + + requestQueue.add(stringRequest); + } + + private String processPriceTimestampResult(String result) + { + result = result.substring(result.lastIndexOf(':')+1); + result = result.substring(0, result.indexOf('}')); + + return result; + } + private void updateHistory(final String symbolCurrencyFrom, String symbolCyrrencyTo, final DataChartCallBack callBack, int timeUnit) { String requestUrl = getRequestUrl(timeUnit, symbolCurrencyFrom, symbolCyrrencyTo); @@ -56,7 +87,7 @@ public class CurrencyDataRetriever { new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { - callBack.onSuccess(null); + callBack.onSuccess((List) null); } }); @@ -134,11 +165,16 @@ public class CurrencyDataRetriever { return new CurrencyDataChart(timestamp, close, high, low, open, volumeFrom, volumeTo); } - void updateHistory(String symbolCurrencyFrom, final DataChartCallBack callBack, int timeUnit) + public void getPriceTimestamp(String symbolCurrencyFrom, final DataChartCallBack callBack, long timestamp) + { + getPriceTimestamp(symbolCurrencyFrom, "USD", callBack, timestamp); + } + + public void updateHistory(String symbolCurrencyFrom, final DataChartCallBack callBack, int timeUnit) { if(symbolCurrencyFrom.equals("USD")) { - callBack.onSuccess(null); + callBack.onSuccess((List) null); } else { @@ -148,5 +184,6 @@ public class CurrencyDataRetriever { public interface DataChartCallBack { void onSuccess(List dataChart); + void onSuccess(String price); } } diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Transaction.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Transaction.java index 420092a..507cfa2 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Transaction.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/Transaction.java @@ -13,12 +13,13 @@ public class Transaction { private double purchasedPrice; private boolean isMined; - public Transaction(int transactionId, String symbol, double amount, long timestamp) + public Transaction(int transactionId, String symbol, double amount, long timestamp, double purchasedPrice) { this.transactionId = transactionId; this.symbol = symbol; this.amount = amount; this.timestamp = timestamp; + this.purchasedPrice = purchasedPrice; } public int getTransactionId() { @@ -49,4 +50,14 @@ public class Transaction { public void setAmount(double amount) { this.amount = amount; } + + public void setPurchasedPrice(double purchasedPrice) + { + this.purchasedPrice = purchasedPrice; + } + + public double getPurchasedPrice() + { + return purchasedPrice; + } } diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java index 01a1b4f..a804607 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java @@ -53,7 +53,7 @@ public class DatabaseManager extends SQLiteOpenHelper{ + KEY_CURRENCY_NAME + " VARCHAR(45)," + KEY_CURRENCY_BALANCE + " TEXT," + KEY_CURRENCY_DATE + " TEXT," - + KEY_CURRENCY_PURCHASED_PRICE + " TEXT," + + KEY_CURRENCY_PURCHASED_PRICE + " REAL," + KEY_CURRENCY_IS_MINED + " INTEGER" + ");"); @@ -76,7 +76,7 @@ public class DatabaseManager extends SQLiteOpenHelper{ onCreate(db); } - public void addCurrencyToManualCurrency(String symbol, double balance, Date date) + public void addCurrencyToManualCurrency(String symbol, double balance, Date date, String purchasedPrice) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); @@ -84,6 +84,7 @@ public class DatabaseManager extends SQLiteOpenHelper{ values.put(KEY_CURRENCY_SYMBOL, symbol); values.put(KEY_CURRENCY_BALANCE, balance); values.put(KEY_CURRENCY_DATE, date.getTime()); + values.put(KEY_CURRENCY_PURCHASED_PRICE, purchasedPrice); //values.put(KEY_CURRENCY_PURCHASED_PRICE, something); db.insert(TABLE_MANUAL_CURRENCIES, null, values); @@ -120,7 +121,7 @@ public class DatabaseManager extends SQLiteOpenHelper{ while(resultatList.moveToNext()) { - transactionList.add(new Transaction(resultatList.getInt(0), resultatList.getString(1), resultatList.getDouble(3), resultatList.getLong(4))); + transactionList.add(new Transaction(resultatList.getInt(0), resultatList.getString(1), resultatList.getDouble(3), resultatList.getLong(4), resultatList.getLong(5))); } resultatList.close(); diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java index 07d9d15..a6270ec 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java @@ -1,9 +1,12 @@ package com.nauk.coinfolio.DataManagers.ExchangeManager; +import android.util.Log; + import com.binance.api.client.BinanceApiClientFactory; import com.binance.api.client.BinanceApiRestClient; import com.binance.api.client.domain.account.Account; import com.binance.api.client.domain.account.AssetBalance; +import com.binance.api.client.domain.account.Trade; import com.binance.api.client.exception.BinanceApiException; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; @@ -21,6 +24,7 @@ public class BinanceManager { private String privateKey; private List balance; + private List trades; public BinanceManager(String publicKey, String privateKey) { @@ -53,9 +57,52 @@ public class BinanceManager { } } - public void getTrades() + public void updateTrades(BinanceCallBack callBack, String symbol) { + List totalTrades = new ArrayList<>(); + updateTrades(null, symbol, "BTC"); + totalTrades.addAll(trades); + + updateTrades(null, symbol, "ETH"); + totalTrades.addAll(trades); + + updateTrades(null, symbol, "USDT"); + totalTrades.addAll(trades); + + trades = totalTrades; + + callBack.onSuccess(); + } + + public void updateTrades(BinanceCallBack callBack, String symbol, String pairSymbol) + { + BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(publicKey, privateKey); + BinanceApiRestClient client = factory.newRestClient(); + + Log.d("coinfolio", symbol + pairSymbol); + + trades = new ArrayList<>(); + + if(!symbol.equals(pairSymbol)) + { + try { + trades = client.getMyTrades(symbol + pairSymbol); + + } catch (BinanceApiException e) { + try { + trades = client.getMyTrades(pairSymbol + symbol); + + } catch (BinanceApiException f) { + f.printStackTrace(); + } + } + } + + if(callBack != null) + { + callBack.onSuccess(); + } } public void setPublicKey(String publicKey) @@ -73,6 +120,11 @@ public class BinanceManager { return balance; } + public List getTrades() + { + return trades; + } + public interface BinanceCallBack { void onSuccess(); void onError(String error); diff --git a/app/src/main/res/layout/activity_currency_details.xml b/app/src/main/res/layout/activity_currency_details.xml index 3bbb8fa..fa9d673 100644 --- a/app/src/main/res/layout/activity_currency_details.xml +++ b/app/src/main/res/layout/activity_currency_details.xml @@ -329,60 +329,69 @@ android:layout_gravity="center" android:background="@drawable/circular_progress_bar" /> - + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From f1a4a03a5a854c6aee4b315bb0e58ce36c95bd32 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Tue, 10 Apr 2018 13:57:46 +0200 Subject: [PATCH 26/34] Fix and features - Fix symbol bug when selecting form ETH|BTC|USDT currencies from Binance - Add candlestick chart in detail activity --- .../Activities/CurrencyDetailsActivity.java | 189 ++++++++++++++---- .../CurrencyData/CurrencyDataChart.java | 20 ++ .../ExchangeManager/BinanceManager.java | 29 ++- .../res/layout/activity_currency_details.xml | 31 ++- app/src/main/res/values/colors.xml | 2 + 5 files changed, 215 insertions(+), 56 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 325dc2a..460cb8e 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -10,14 +10,13 @@ import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Bundle; +import android.preference.SwitchPreference; import android.support.annotation.NonNull; import android.support.design.widget.BottomNavigationView; -import android.support.design.widget.Snackbar; import android.support.v4.app.NavUtils; import android.support.v4.content.ContextCompat; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; -import android.util.Log; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.MotionEvent; @@ -30,16 +29,19 @@ import android.widget.ViewFlipper; import com.binance.api.client.domain.account.Trade; import com.daimajia.swipe.SwipeLayout; import com.github.mikephil.charting.charts.BarChart; +import com.github.mikephil.charting.charts.CandleStickChart; import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.data.BarData; import com.github.mikephil.charting.data.BarDataSet; import com.github.mikephil.charting.data.BarEntry; +import com.github.mikephil.charting.data.CandleData; +import com.github.mikephil.charting.data.CandleDataSet; +import com.github.mikephil.charting.data.CandleEntry; import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.LineData; import com.github.mikephil.charting.data.LineDataSet; import com.github.mikephil.charting.highlight.Highlight; import com.github.mikephil.charting.listener.OnChartValueSelectedListener; -import com.nauk.coinfolio.DataManagers.BalanceManager; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart; import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction; @@ -54,6 +56,7 @@ import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -77,10 +80,16 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private final static int YEAR = 4; private List dataChartList; private LineChart lineChart; + private CandleStickChart candleStickChart; private BarChart barChart; private PreferencesManager preferencesManager; private BinanceManager binanceManager; + private boolean displayLineChart; + + private Button lineChartButton; + private Button candleStickChartButton; + private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() { @@ -133,13 +142,44 @@ public class CurrencyDetailsActivity extends AppCompatActivity { databaseManager = new DatabaseManager(this); preferencesManager = new PreferencesManager(this); + displayLineChart = true; + viewFlipper = findViewById(R.id.vfCurrencyDetails); transactionLayout = findViewById(R.id.listTransactions); tradeLayout = findViewById(R.id.listTrades); lineChart = findViewById(R.id.chartPriceView); + candleStickChart = findViewById(R.id.chartCandleStickView); barChart = findViewById(R.id.chartVolumeView); + lineChartButton = findViewById(R.id.lineChartButton); + candleStickChartButton = findViewById(R.id.candleStickChartButton); binanceManager = new BinanceManager(preferencesManager.getBinancePublicKey(), preferencesManager.getBinancePrivateKey()); + lineChartButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + lineChartButton.setEnabled(false); + candleStickChartButton.setEnabled(true); + + lineChart.setVisibility(View.VISIBLE); + candleStickChart.setVisibility(View.GONE); + + displayLineChart = true; + } + }); + + candleStickChartButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + lineChartButton.setEnabled(true); + candleStickChartButton.setEnabled(false); + + lineChart.setVisibility(View.GONE); + candleStickChart.setVisibility(View.VISIBLE); + + displayLineChart = false; + } + }); + ((BottomNavigationView) findViewById(R.id.navigation_details)).getMenu().getItem(1).setEnabled(false); setupActionBar(); @@ -147,6 +187,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity { drawTransactionList(); initializeButtons(); + initializeLineChart(lineChart); + initializeCandleStickChart(candleStickChart); updateChartTab(DAY, 1); @@ -225,6 +267,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private void updateCharts(Button button) { findViewById(R.id.chartPriceView).setVisibility(View.GONE); + findViewById(R.id.chartCandleStickView).setVisibility(View.GONE); findViewById(R.id.chartVolumeView).setVisibility(View.GONE); findViewById(R.id.progressLayoutChart).setVisibility(View.VISIBLE); @@ -325,8 +368,22 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private void updateChartTab(int timeUnit, int amount) { updateChartsData(timeUnit, amount); - drawPriceChart(); + drawPriceLineChart(); + drawPriceCandleStickChart(); + + if(displayLineChart) + { + findViewById(R.id.chartPriceView).setVisibility(View.VISIBLE); + findViewById(R.id.progressLayoutChart).setVisibility(View.GONE); + } + else + { + findViewById(R.id.chartCandleStickView).setVisibility(View.VISIBLE); + findViewById(R.id.progressLayoutChart).setVisibility(View.GONE); + } + drawVolumeChart(); + updateGeneralData(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY()); } private void updateChartsData(int timeUnit, int amount) @@ -399,11 +456,14 @@ public class CurrencyDetailsActivity extends AppCompatActivity { barChart.setFitBars(true); } - private void drawPriceChart() + private void drawPriceCandleStickChart() { - initializeLineChart(lineChart); + candleStickChart.setData(generatePriceCandleStickChartSet()); + } - lineChart.setData(generatePriceChartSet()); + private void drawPriceLineChart() + { + lineChart.setData(generatePriceLineChartSet()); lineChart.getAxisLeft().setAxisMinValue(lineChart.getData().getYMin()); lineChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { @@ -424,11 +484,19 @@ public class CurrencyDetailsActivity extends AppCompatActivity { return toucheEvent(motionEvent); } }); + } - updateGeneralData(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY()); - - findViewById(R.id.chartPriceView).setVisibility(View.VISIBLE); - findViewById(R.id.progressLayoutChart).setVisibility(View.GONE); + private void initializeCandleStickChart(CandleStickChart candleStickChart) + { + candleStickChart.setDrawGridBackground(false); + candleStickChart.setDrawBorders(false); + candleStickChart.setDrawMarkers(true); + candleStickChart.getDescription().setEnabled(false); + candleStickChart.getAxisLeft().setEnabled(true); + candleStickChart.getAxisRight().setEnabled(true); + candleStickChart.getLegend().setEnabled(false); + candleStickChart.getXAxis().setEnabled(true); + candleStickChart.setViewPortOffsets(0, 0, 0, 0); } private void initializeLineChart(LineChart lineChart) @@ -472,8 +540,11 @@ public class CurrencyDetailsActivity extends AppCompatActivity { timestampPlaceholder = getResources().getString(R.string.timestampPlaceholder, date); ((TextView) findViewById(R.id.volumeHightlight)).setText(volumePlaceholder); + findViewById(R.id.volumeHightlight).setVisibility(View.VISIBLE); ((TextView) findViewById(R.id.priceHightlight)).setText(pricePlaceholder); + findViewById(R.id.priceHightlight).setVisibility(View.VISIBLE); ((TextView) findViewById(R.id.timestampHightlight)).setText(timestampPlaceholder); + findViewById(R.id.timestampHightlight).setVisibility(View.VISIBLE); } @@ -492,9 +563,12 @@ public class CurrencyDetailsActivity extends AppCompatActivity { private void hideDataIndicators() { - ((TextView) findViewById(R.id.volumeHightlight)).setText("\n"); - ((TextView) findViewById(R.id.priceHightlight)).setText("\n"); - ((TextView) findViewById(R.id.timestampHightlight)).setText("\n"); + ((TextView) findViewById(R.id.volumeHightlight)).setText(".\n."); + findViewById(R.id.volumeHightlight).setVisibility(View.INVISIBLE); + ((TextView) findViewById(R.id.priceHightlight)).setText(".\n."); + findViewById(R.id.priceHightlight).setVisibility(View.INVISIBLE); + ((TextView) findViewById(R.id.timestampHightlight)).setText(".\n."); + findViewById(R.id.timestampHightlight).setVisibility(View.INVISIBLE); } private String getDate(long timeStamp){ @@ -558,7 +632,43 @@ public class CurrencyDetailsActivity extends AppCompatActivity { return str; } - private LineData generatePriceChartSet() + private CandleData generatePriceCandleStickChartSet() + { + CandleDataSet dataSet; + ArrayList values = new ArrayList<>(); + + int offsetRange = (int) Math.floor(dataChartList.size() / 200); + + if(offsetRange < 1) + { + offsetRange = 1; + } + + for(int i = 0, j = 0; i < dataChartList.size(); i+= offsetRange, j++) + { + values.add(new CandleEntry(j, (float) dataChartList.get(i).getHigh() + , (float) dataChartList.get(i).getLow() + , (float) dataChartList.get(i).getOpen() + , (float) dataChartList.get(i).getClose())); + } + + dataSet = new CandleDataSet(values, "History"); + dataSet.setDrawIcons(false); + dataSet.setDrawValues(false); + dataSet.setDecreasingColor(getColor(R.color.decreaseCandle)); + dataSet.setShowCandleBar(true); + dataSet.setShadowColorSameAsCandle(true); + dataSet.setDecreasingPaintStyle(Paint.Style.FILL); + dataSet.setIncreasingColor(getColor(R.color.increaseCandle)); + dataSet.setIncreasingPaintStyle(Paint.Style.STROKE); + dataSet.setNeutralColor(getColor(R.color.increaseCandle)); + dataSet.setHighLightColor(getColor(R.color.colorAccent)); + dataSet.setDrawHorizontalHighlightIndicator(false); + + return new CandleData(dataSet); + } + + private LineData generatePriceLineChartSet() { LineDataSet dataSet; ArrayList values = new ArrayList<>(); @@ -656,36 +766,39 @@ public class CurrencyDetailsActivity extends AppCompatActivity { return transColor; } - private void drawTradeList(List trades, String pairSymbol) + private void drawTradeList(HashMap> trades) { findViewById(R.id.tradeProgressBar).setVisibility(View.GONE); tradeLayout.removeAllViews(); - for(int i = trades.size()-1; i >= 0; i--) + for(String key : trades.keySet()) { - View view = LayoutInflater.from(this).inflate(R.layout.custom_trade_row, null); - TextView amountTxtView = view.findViewById(R.id.amountPurchased); - TextView purchasedPrice = view.findViewById(R.id.purchasedPrice); - TextView tradePair = view.findViewById(R.id.pair); - TextView dateTxtView = view.findViewById(R.id.tradeDate); - View tradeIndicator = view.findViewById(R.id.tradeIndicator); - - if(trades.get(i).isBuyer()) + for(int i = trades.get(key).size()-1; i >= 0; i--) { - tradeIndicator.setBackgroundColor(getColor(R.color.green)); - } - else - { - tradeIndicator.setBackgroundColor(getColor(R.color.red)); - } + View view = LayoutInflater.from(this).inflate(R.layout.custom_trade_row, null); + TextView amountTxtView = view.findViewById(R.id.amountPurchased); + TextView purchasedPrice = view.findViewById(R.id.purchasedPrice); + TextView tradePair = view.findViewById(R.id.pair); + TextView dateTxtView = view.findViewById(R.id.tradeDate); + View tradeIndicator = view.findViewById(R.id.tradeIndicator); - amountTxtView.setText(String.valueOf(trades.get(i).getQty())); - purchasedPrice.setText(trades.get(i).getPrice()); - dateTxtView.setText(getDate(trades.get(i).getTime())); - tradePair.setText(currency.getSymbol() + "/" + pairSymbol); + if(trades.get(key).get(i).isBuyer()) + { + tradeIndicator.setBackgroundColor(getColor(R.color.green)); + } + else + { + tradeIndicator.setBackgroundColor(getColor(R.color.red)); + } - tradeLayout.addView(view); + amountTxtView.setText(String.valueOf(trades.get(key).get(i).getQty())); + purchasedPrice.setText(trades.get(key).get(i).getPrice()); + dateTxtView.setText(getDate(trades.get(key).get(i).getTime())); + tradePair.setText(currency.getSymbol() + "/" + key); + + tradeLayout.addView(view); + } } } @@ -790,12 +903,12 @@ public class CurrencyDetailsActivity extends AppCompatActivity { binanceManager.updateTrades(new BinanceManager.BinanceCallBack() { @Override public void onSuccess() { - final List trades = binanceManager.getTrades(); + final HashMap> trades = binanceManager.getTrades(); runOnUiThread(new Runnable() { @Override public void run() { - drawTradeList(trades, "ETH"); + drawTradeList(trades); } }); } diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java index 2ca5f20..4173c5e 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/CurrencyData/CurrencyDataChart.java @@ -53,6 +53,26 @@ public class CurrencyDataChart implements Parcelable { return timestamp; } + public void setClose(double close) { + this.close = close; + } + + public double getHigh() { + return high; + } + + public void setHigh(double high) { + this.high = high; + } + + public double getLow() { + return low; + } + + public void setLow(double low) { + this.low = low; + } + @Override public int describeContents() { return 0; diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java index a6270ec..1832661 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/ExchangeManager/BinanceManager.java @@ -11,6 +11,7 @@ import com.binance.api.client.exception.BinanceApiException; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -24,7 +25,7 @@ public class BinanceManager { private String privateKey; private List balance; - private List trades; + private HashMap> trades; public BinanceManager(String publicKey, String privateKey) { @@ -59,39 +60,33 @@ public class BinanceManager { public void updateTrades(BinanceCallBack callBack, String symbol) { - List totalTrades = new ArrayList<>(); + trades = new HashMap<>(); - updateTrades(null, symbol, "BTC"); - totalTrades.addAll(trades); + trades.put("BTC", updateTrades(null, symbol, "BTC")); - updateTrades(null, symbol, "ETH"); - totalTrades.addAll(trades); + trades.put("ETH", updateTrades(null, symbol, "ETH")); - updateTrades(null, symbol, "USDT"); - totalTrades.addAll(trades); - - trades = totalTrades; + trades.put("USDT", updateTrades(null, symbol, "USDT")); callBack.onSuccess(); } - public void updateTrades(BinanceCallBack callBack, String symbol, String pairSymbol) + public List updateTrades(BinanceCallBack callBack, String symbol, String pairSymbol) { + List presentTrades = new ArrayList<>(); BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(publicKey, privateKey); BinanceApiRestClient client = factory.newRestClient(); Log.d("coinfolio", symbol + pairSymbol); - trades = new ArrayList<>(); - if(!symbol.equals(pairSymbol)) { try { - trades = client.getMyTrades(symbol + pairSymbol); + presentTrades = client.getMyTrades(symbol + pairSymbol); } catch (BinanceApiException e) { try { - trades = client.getMyTrades(pairSymbol + symbol); + presentTrades = client.getMyTrades(pairSymbol + symbol); } catch (BinanceApiException f) { f.printStackTrace(); @@ -103,6 +98,8 @@ public class BinanceManager { { callBack.onSuccess(); } + + return presentTrades; } public void setPublicKey(String publicKey) @@ -120,7 +117,7 @@ public class BinanceManager { return balance; } - public List getTrades() + public HashMap> getTrades() { return trades; } diff --git a/app/src/main/res/layout/activity_currency_details.xml b/app/src/main/res/layout/activity_currency_details.xml index fa9d673..e13d831 100644 --- a/app/src/main/res/layout/activity_currency_details.xml +++ b/app/src/main/res/layout/activity_currency_details.xml @@ -18,11 +18,33 @@ android:layout_height="match_parent" android:orientation="vertical"> + + +