Details Activity data interface rework

This commit is contained in:
Tanguy Herbron 2018-04-04 15:41:28 +02:00
parent e9cbbd7b27
commit 360c41751e
5 changed files with 202 additions and 28 deletions

View File

@ -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'

View File

@ -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)

View File

@ -154,44 +154,160 @@
</LinearLayout>
<!--<ScrollView
android:id="@+id/svCharts"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ScrollView>-->
<LinearLayout
android:id="@+id/llCharts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="0.16">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Beginning price"
android:layout_weight="0.75"/>
<TextView
android:id="@+id/txtViewPriceStart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:gravity="center"/>
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:layout_weight="0.25"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/separationLineSize"
android:background="@color/separationLine"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="0.16">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Current price"
android:layout_weight="0.75"/>
<TextView
android:id="@+id/txtViewPriceNow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:gravity="center"/>
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:layout_weight="0.25"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/separationLineSize"
android:background="@color/separationLine"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="0.16">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Delta"
android:layout_weight="0.75"/>
<TextView
android:id="@+id/txtViewPercentage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:gravity="center"/>
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:layout_weight="0.25"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/separationLineSize"
android:background="@color/separationLine"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="0.16">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Total volume"
android:layout_weight="0.75"/>
<TextView
android:id="@+id/totalVolume"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:layout_weight="0.25" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/separationLineSize"
android:background="@color/separationLine"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="0.16">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Highest price"
android:layout_weight="0.75" />
<TextView
android:id="@+id/highestPrice"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:layout_weight="0.25" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/separationLineSize"
android:background="@color/separationLine"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="0.16">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Lowest price"
android:layout_weight="0.75"/>
<TextView
android:id="@+id/lowestPrice"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:layout_weight="0.25" />
</LinearLayout>

View File

@ -134,7 +134,7 @@
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_height="@dimen/separationLineSize"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"

View File

@ -16,5 +16,5 @@
<dimen name="fingerprint_dialog_height">125dp</dimen>
<dimen name="fingerprint_dialog_width">250dp</dimen>
<dimen name="testOutline">1dp</dimen>
<dimen name="separationLineSize">1dp</dimen>
</resources>