Update Home fragment in DetailsActivity

This commit is contained in:
Tanguy Herbron 2018-05-14 02:01:28 +02:00
parent 0ab4cb15a1
commit a5f2d9a1fd
12 changed files with 755 additions and 22 deletions

BIN
.idea/caches/build_file_checksums.ser generated Normal file

Binary file not shown.

29
.idea/codeStyles/Project.xml generated Normal file
View File

@ -0,0 +1,29 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<Objective-C-extensions>
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="h" fileNamingConvention="NONE" />
<pair source="c" header="h" fileNamingConvention="NONE" />
</extensions>
</Objective-C-extensions>
</code_scheme>
</component>

4
.idea/gradle.xml generated
View File

@ -3,9 +3,9 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="C:\Program Files\Android\Android Studio\gradle\gradle-4.1" />
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-4.1" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />

2
.idea/misc.xml generated
View File

@ -24,7 +24,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -19,34 +19,36 @@ android {
}
}
}
sourceSets {
main.java.srcDirs += 'src/main/binance/src'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:cardview-v7:27.1.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.mcxiaoke.volley:library:1.0.19'
implementation 'com.diogobernardino:williamchart:2.5.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:27.1.0'
implementation 'com.android.support:palette-v7:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:palette-v7:27.1.1'
implementation 'com.daimajia.swipelayout:library:1.2.0@aar'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.8.5'
implementation 'com.fasterxml.jackson.core:jackson-core:2.8.5'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.8.5'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-jackson:2.2.0'
implementation 'com.squareup.retrofit2:converter-jackson:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0'
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'
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'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation files('../libs/binance-api.jar')
}

View File

@ -239,8 +239,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
updateChartTab(DAY, 1);
hasBeenModified = false;
Drawable tradeDrawable = ((ProgressBar) findViewById(R.id.loadingIndicator)).getIndeterminateDrawable();

View File

@ -1,25 +1,72 @@
package com.nauk.moodl.Activities.DetailsActivityFragments;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
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.moodl.Activities.CurrencyDetailsActivity;
import com.nauk.moodl.DataManagers.CurrencyData.Currency;
import com.nauk.moodl.DataManagers.CurrencyData.CurrencyDataChart;
import com.nauk.moodl.DataManagers.PreferencesManager;
import com.nauk.moodl.PlaceholderManager;
import com.nauk.moodl.R;
import java.util.ArrayList;
import java.util.List;
import static android.icu.text.DateTimePatternGenerator.DAY;
import static com.nauk.moodl.MoodlBox.getDateFromTimestamp;
import static com.nauk.moodl.MoodlBox.numberConformer;
/**
* Created by Tiji on 13/05/2018.
*/
public class Home extends Fragment {
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 View view;
private Currency currency;
private LineChart lineChart;
private CandleStickChart candleStickChart;
private BarChart barChart;
private List<CurrencyDataChart> dataChartList;
private PreferencesManager preferencesManager;
private boolean displayLineChart;
private Button lineChartButton;
private Button candleStickChartButton;
@Nullable
@Override
@ -29,6 +76,618 @@ public class Home extends Fragment {
currency = getActivity().getIntent().getParcelableExtra("currency");
lineChart = view.findViewById(R.id.chartPriceView);
candleStickChart = view.findViewById(R.id.chartCandleStickView);
lineChartButton = view.findViewById(R.id.lineChartButton);
candleStickChartButton = view.findViewById(R.id.candleStickChartButton);
barChart = view.findViewById(R.id.chartVolumeView);
preferencesManager = new PreferencesManager(getContext());
displayLineChart = true;
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;
}
});
initializeButtons();
initializeLineChart(lineChart);
initializeCandleStickChart(candleStickChart);
updateChartTab(DAY, 1);
return view;
}
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)
{
lineChart.setDrawGridBackground(false);
lineChart.setDrawBorders(false);
lineChart.setDrawMarkers(true);
lineChart.setDoubleTapToZoomEnabled(true);
lineChart.setPinchZoom(true);
lineChart.setScaleEnabled(false);
lineChart.setDragEnabled(true);
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);
}
private void initializeButtons()
{
LinearLayout buttonLayout = view.findViewById(R.id.layoutChartButtons);
for(int i = 0; i < buttonLayout.getChildCount(); i++)
{
final Button button = (Button) buttonLayout.getChildAt(i);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
buttonEvent(v);
}
});
}
}
private void buttonEvent(View v)
{
v.setEnabled(false);
v.setElevation(convertDpToPx(8));
LinearLayout buttonLayout = (LinearLayout) v.getParent();
for(int i = 0; i < buttonLayout.getChildCount(); i++)
{
Button button = (Button) buttonLayout.getChildAt(i);
if(button != v)
{
button.setEnabled(true);
button.setElevation(convertDpToPx(2));
}
}
updateCharts((Button) v);
}
private void updateCharts(Button button)
{
view.findViewById(R.id.chartPriceView).setVisibility(View.GONE);
view.findViewById(R.id.chartCandleStickView).setVisibility(View.GONE);
view.findViewById(R.id.chartVolumeView).setVisibility(View.GONE);
view.findViewById(R.id.progressLayoutChart).setVisibility(View.VISIBLE);
String interval = button.getText().toString().substring(button.getText().toString().length()-2);
switch (interval)
{
case "1h":
currency.updateHistoryMinutes(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
@Override
public void onSuccess(Currency currency) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
updateChartTab(Home.HOUR, 1);
}
});
}
});
break;
case "3h":
currency.updateHistoryMinutes(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
@Override
public void onSuccess(Currency currency) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
updateChartTab(Home.HOUR, 3);
}
});
}
});
break;
case "1d":
currency.updateHistoryMinutes(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
@Override
public void onSuccess(Currency currency) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
updateChartTab(Home.DAY, 1);
}
});
}
});
break;
case "3d":
currency.updateHistoryHours(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
@Override
public void onSuccess(Currency currency) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
updateChartTab(Home.DAY, 3);
}
});
}
});
break;
case "1w":
currency.updateHistoryHours(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
@Override
public void onSuccess(Currency currency) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
updateChartTab(Home.WEEK, 11);
}
});
}
});
break;
case "1M":
currency.updateHistoryHours(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
@Override
public void onSuccess(Currency currency) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
updateChartTab(Home.MONTH, 1);
}
});
}
});
break;
case "3M":
currency.updateHistoryDays(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
@Override
public void onSuccess(Currency currency) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
updateChartTab(Home.MONTH, 3);
}
});
}
});
break;
case "6M":
currency.updateHistoryDays(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
@Override
public void onSuccess(Currency currency) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
updateChartTab(Home.MONTH, 6);
}
});
}
});
break;
case "1y":
currency.updateHistoryDays(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
@Override
public void onSuccess(Currency currency) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
updateChartTab(Home.YEAR, 1);
}
});
}
});
break;
}
}
private float convertDpToPx(float dp)
{
return dp * this.getResources().getDisplayMetrics().density;
}
private void updateChartTab(int timeUnit, int amount)
{
updateChartsData(timeUnit, amount);
drawPriceLineChart();
drawPriceCandleStickChart();
if(displayLineChart)
{
view.findViewById(R.id.chartPriceView).setVisibility(View.VISIBLE);
view.findViewById(R.id.progressLayoutChart).setVisibility(View.GONE);
}
else
{
view.findViewById(R.id.chartCandleStickView).setVisibility(View.VISIBLE);
view.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 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) view.findViewById(R.id.txtViewPriceStart)).setText(PlaceholderManager.getValueString(numberConformer(start), getContext()));
((TextView) view.findViewById(R.id.txtViewPriceNow)).setText(PlaceholderManager.getValueString(numberConformer(end), getContext()));
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) view.findViewById(R.id.totalVolume)).setText(PlaceholderManager.getValueString(numberConformer(totalVolume), getContext()));
((TextView) view.findViewById(R.id.highestPrice)).setText(PlaceholderManager.getValueString(numberConformer(highestPrice), getContext()));
((TextView) view.findViewById(R.id.lowestPrice)).setText(PlaceholderManager.getValueString(numberConformer(lowestPrice), getContext()));
}
private void updateFluctuation(float start, float end)
{
float fluctuation = end - start;
float percentageFluctuation = (fluctuation / start * 100);
if(percentageFluctuation < 0)
{
((TextView) view.findViewById(R.id.txtViewPercentage)).setTextColor(getResources().getColor(R.color.red));
}
else
{
((TextView) view.findViewById(R.id.txtViewPercentage)).setTextColor(getResources().getColor(R.color.green));
}
((TextView) view.findViewById(R.id.txtViewPercentage)).setText(getResources().getString(R.string.currencyPercentagePlaceholder, numberConformer(percentageFluctuation)));
}
private void drawVolumeChart()
{
initializeBarChart(barChart);
barChart.setData(generateVolumeChartSet());
barChart.animateY(1000);
barChart.invalidate();
view.findViewById(R.id.chartVolumeView).setVisibility(View.VISIBLE);
}
private BarData generateVolumeChartSet()
{
BarDataSet dataSet;
ArrayList<BarEntry> values = new ArrayList<>();
int offset = (int) Math.floor(dataChartList.size() / 200);
if(offset < 1)
{
offset = 1;
}
for(int i = 0, j = 0; i < dataChartList.size(); i += offset, j++)
{
values.add(new BarEntry(j, (float) dataChartList.get(j).getVolumeTo()));
}
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 void initializeBarChart(BarChart barChart)
{
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.setHighlightFullBarEnabled(true);
barChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, Highlight h) {
barChartValueSelected(e);
}
@Override
public void onNothingSelected() {
}
});
barChart.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return toucheEvent(motionEvent);
}
});
}
private void barChartValueSelected(Entry e)
{
int index = barChart.getData().getDataSets().get(0).getEntryIndex((BarEntry) e);
lineChart.highlightValue(lineChart.getData().getDataSets().get(0).getEntryForIndex(index).getX(), lineChart.getData().getDataSets().get(0).getEntryForIndex(index).getY(), 0);
generatePlaceHoldersFromIndex(index);
}
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();
}
return false;
}
private void hideDataIndicators()
{
((TextView) view.findViewById(R.id.volumeHightlight)).setText(".\n.");
view.findViewById(R.id.volumeHightlight).setVisibility(View.INVISIBLE);
((TextView) view.findViewById(R.id.priceHightlight)).setText(".\n.");
view.findViewById(R.id.priceHightlight).setVisibility(View.INVISIBLE);
((TextView) view.findViewById(R.id.timestampHightlight)).setText(".\n.");
view.findViewById(R.id.timestampHightlight).setVisibility(View.INVISIBLE);
}
private void drawPriceLineChart()
{
lineChart.setData(generatePriceLineChartSet());
lineChart.getAxisLeft().setAxisMinValue(lineChart.getData().getYMin());
lineChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, Highlight h) {
lineChartValueSelected(e);
}
@Override
public void onNothingSelected() {
}
});
lineChart.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return toucheEvent(motionEvent);
}
});
}
private void lineChartValueSelected(Entry e)
{
int index = lineChart.getData().getDataSets().get(0).getEntryIndex(e);
barChart.highlightValue(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getX(), 0, index);
generatePlaceHoldersFromIndex(index);
}
private void generatePlaceHoldersFromIndex(int index)
{
String date;
String volumePlaceholder;
String pricePlaceholder;
String timestampPlaceholder;
if(dataChartList.size() > 200)
{
date = getDateFromTimestamp(dataChartList.get((int) Math.floor(dataChartList.size() / 200) * index).getTimestamp() * 1000);
}
else
{
date = getDateFromTimestamp(dataChartList.get(index).getTimestamp() * 1000);
}
volumePlaceholder = PlaceholderManager.getVolumeString(numberConformer(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY()), getContext());
pricePlaceholder = PlaceholderManager.getPriceString(numberConformer((lineChart.getHighlighted())[0].getY()), getContext());
timestampPlaceholder = PlaceholderManager.getTimestampString(date, getContext());
((TextView) view.findViewById(R.id.volumeHightlight)).setText(volumePlaceholder);
view.findViewById(R.id.volumeHightlight).setVisibility(View.VISIBLE);
((TextView) view.findViewById(R.id.priceHightlight)).setText(pricePlaceholder);
view.findViewById(R.id.priceHightlight).setVisibility(View.VISIBLE);
((TextView) view.findViewById(R.id.timestampHightlight)).setText(timestampPlaceholder);
view.findViewById(R.id.timestampHightlight).setVisibility(View.VISIBLE);
}
private LineData generatePriceLineChartSet()
{
LineDataSet dataSet;
ArrayList<Entry> 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 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());
return new LineData(dataSet);
}
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 drawPriceCandleStickChart()
{
candleStickChart.setData(generatePriceCandleStickChartSet());
}
private CandleData generatePriceCandleStickChartSet()
{
CandleDataSet dataSet;
ArrayList<CandleEntry> 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(getContext().getColor(R.color.decreaseCandle));
dataSet.setShowCandleBar(true);
dataSet.setShadowColorSameAsCandle(true);
dataSet.setDecreasingPaintStyle(Paint.Style.FILL);
dataSet.setIncreasingColor(getContext().getColor(R.color.increaseCandle));
dataSet.setIncreasingPaintStyle(Paint.Style.STROKE);
dataSet.setNeutralColor(getContext().getColor(R.color.increaseCandle));
dataSet.setHighLightColor(getContext().getColor(R.color.colorAccent));
dataSet.setDrawHorizontalHighlightIndicator(false);
return new CandleData(dataSet);
}
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;
}
}
}

View File

@ -1,6 +1,7 @@
package com.nauk.moodl.LayoutManagers;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -30,8 +31,9 @@ public class CurrencyListAdapter extends ArrayAdapter<Currency> {
this.context = context;
}
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent)
public View getView(int position, View convertView, @NonNull ViewGroup parent)
{
Currency currency = getItem(position);
@ -58,6 +60,7 @@ public class CurrencyListAdapter extends ArrayAdapter<Currency> {
return convertView;
}
@NonNull
@Override
public Filter getFilter() {
return myFilter;

View File

@ -0,0 +1,42 @@
package com.nauk.moodl.LayoutManagers;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
/**
* Created by Administrator on 14/05/2018.
*/
public class CustomViewPager extends ViewPager {
private boolean enabled;
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
this.enabled = false;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (this.enabled) {
return super.onTouchEvent(event);
}
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (this.enabled) {
return super.onInterceptTouchEvent(event);
}
return false;
}
public void setPagingEnabled(boolean enabled) {
this.enabled = enabled;
}
}

View File

@ -6,7 +6,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.nauk.moodl.Activities.CurrencyDetailsActivity">
<android.support.v4.view.ViewPager
<com.nauk.moodl.LayoutManagers.CustomViewPager
android:id="@+id/vfCurrencyDetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -659,7 +659,7 @@
</LinearLayout>
</android.support.v4.view.ViewPager>
</com.nauk.moodl.LayoutManagers.CustomViewPager>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation_details"

View File

@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.2'
// NOTE: Do not place your application dependencies here; they belong

View File

@ -1,6 +1,6 @@
#Mon Dec 25 21:39:15 CET 2017
#Sun May 13 20:31:16 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip