From 360c41751e8a68f4fb35d0654e3b8fe7984e715f Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Wed, 4 Apr 2018 15:41:28 +0200 Subject: [PATCH] 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