diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser
new file mode 100644
index 0000000..3fe4c64
Binary files /dev/null and b/.idea/caches/build_file_checksums.ser differ
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..30aa626
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 40b0348..cbbf71c 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -3,9 +3,9 @@
-
+
diff --git a/app/build.gradle b/app/build.gradle
index 3abb9cc..27778f8 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -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')
}
diff --git a/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java b/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java
index 7e16ae8..e26aa77 100644
--- a/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java
+++ b/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java
@@ -239,8 +239,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
updateChartTab(DAY, 1);
-
-
hasBeenModified = false;
Drawable tradeDrawable = ((ProgressBar) findViewById(R.id.loadingIndicator)).getIndeterminateDrawable();
diff --git a/app/src/main/java/com/nauk/moodl/Activities/DetailsActivityFragments/Home.java b/app/src/main/java/com/nauk/moodl/Activities/DetailsActivityFragments/Home.java
index 914ece7..dede4c7 100644
--- a/app/src/main/java/com/nauk/moodl/Activities/DetailsActivityFragments/Home.java
+++ b/app/src/main/java/com/nauk/moodl/Activities/DetailsActivityFragments/Home.java
@@ -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 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 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 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 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;
+ }
+ }
+
}
diff --git a/app/src/main/java/com/nauk/moodl/LayoutManagers/CurrencyListAdapter.java b/app/src/main/java/com/nauk/moodl/LayoutManagers/CurrencyListAdapter.java
index 7fa3814..1ba7287 100644
--- a/app/src/main/java/com/nauk/moodl/LayoutManagers/CurrencyListAdapter.java
+++ b/app/src/main/java/com/nauk/moodl/LayoutManagers/CurrencyListAdapter.java
@@ -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 {
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 {
return convertView;
}
+ @NonNull
@Override
public Filter getFilter() {
return myFilter;
diff --git a/app/src/main/java/com/nauk/moodl/LayoutManagers/CustomViewPager.java b/app/src/main/java/com/nauk/moodl/LayoutManagers/CustomViewPager.java
new file mode 100644
index 0000000..8553dad
--- /dev/null
+++ b/app/src/main/java/com/nauk/moodl/LayoutManagers/CustomViewPager.java
@@ -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;
+ }
+}
diff --git a/app/src/main/res/layout/activity_currency_details.xml b/app/src/main/res/layout/activity_currency_details.xml
index d21c3ff..4fdc996 100644
--- a/app/src/main/res/layout/activity_currency_details.xml
+++ b/app/src/main/res/layout/activity_currency_details.xml
@@ -6,7 +6,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.nauk.moodl.Activities.CurrencyDetailsActivity">
-
-
+