Add per currency chart display | Click on card to collapse/extend view | Click on chart to open details
This commit is contained in:
parent
88d426b0b8
commit
3af7cf8e9c
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -24,7 +24,7 @@
|
||||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
@ -15,6 +15,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.graphics.Palette;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.Menu;
|
||||
@ -237,8 +238,7 @@ public class HomeActivity extends AppCompatActivity {
|
||||
|
||||
private void adaptView()
|
||||
{
|
||||
if(isDetailed)
|
||||
{
|
||||
|
||||
currencyLayout.removeAllViews();
|
||||
|
||||
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
|
||||
@ -248,21 +248,10 @@ 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, true));
|
||||
currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed));
|
||||
}
|
||||
}
|
||||
|
||||
//currencyLayout.addView(layoutGenerator.getInfoLayout(balanceManager.getTotalBalance().get(0), true));
|
||||
}
|
||||
else
|
||||
{
|
||||
/*for(int i = 0; i < currencyLayout.getChildCount(); i++)
|
||||
{
|
||||
currencyLayout.getChildAt(i).findViewWithTag("chart_layout").setVisibility(View.GONE);
|
||||
currencyLayout.getChildAt(i).findViewWithTag("separator_layout").setVisibility(View.GONE);
|
||||
}*/
|
||||
}
|
||||
|
||||
updateViewButtonIcon();
|
||||
}
|
||||
|
||||
@ -301,6 +290,8 @@ public class HomeActivity extends AppCompatActivity {
|
||||
private void getBitmapFromURL(String src, IconCallBack callBack) {
|
||||
Bitmap result;
|
||||
|
||||
Log.d("coinfolio", "Downloading bitmap");
|
||||
|
||||
try {
|
||||
java.net.URL url = new java.net.URL(src);
|
||||
HttpURLConnection connection = (HttpURLConnection) url
|
||||
@ -321,12 +312,17 @@ public class HomeActivity extends AppCompatActivity {
|
||||
{
|
||||
iconCounter++;
|
||||
|
||||
Log.d("coinfolio", "Icon ++");
|
||||
|
||||
if(balanceManager.getTotalBalance() != null)
|
||||
{
|
||||
if(iconCounter == balanceManager.getTotalBalance().size() - 1)
|
||||
{
|
||||
Log.d("coinfolio", "1");
|
||||
if(coinCounter == balanceManager.getTotalBalance().size() - 1 && detailsChecker)
|
||||
{
|
||||
Log.d("coinfolio", "Loading heavy");
|
||||
|
||||
UiHeavyLoadCalculator uiHeavyLoadCalculator = new UiHeavyLoadCalculator();
|
||||
uiHeavyLoadCalculator.execute();
|
||||
}
|
||||
@ -389,6 +385,8 @@ public class HomeActivity extends AppCompatActivity {
|
||||
|
||||
private void countCoins(boolean isCoin, boolean isDetails)
|
||||
{
|
||||
Log.d("coinfolio", "Coin++ " + coinCounter + " " + balanceManager.getTotalBalance().size());
|
||||
|
||||
if(isCoin)
|
||||
{
|
||||
coinCounter++;
|
||||
@ -409,6 +407,8 @@ public class HomeActivity extends AppCompatActivity {
|
||||
|
||||
if(balanceManager.getIconUrl(localCurrency.getSymbol()) != null)
|
||||
{
|
||||
Log.d("coinfolio", "Downloading bitmap");
|
||||
|
||||
getBitmapFromURL(balanceManager.getIconUrl(localCurrency.getSymbol()), new IconCallBack() {
|
||||
@Override
|
||||
public void onSuccess(Bitmap bitmapIcon) {
|
||||
@ -622,6 +622,7 @@ public class HomeActivity extends AppCompatActivity {
|
||||
|
||||
if(balanceManager.getTotalBalance().size() > 0)
|
||||
{
|
||||
|
||||
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
|
||||
{
|
||||
balance.get(i).updateHistoryMinutes(getApplicationContext(), new Currency.CurrencyCallBack() {
|
||||
|
@ -6,7 +6,10 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
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.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -14,6 +17,7 @@ import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
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;
|
||||
@ -22,12 +26,16 @@ import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
|
||||
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart;
|
||||
import com.nauk.coinfolio.R;
|
||||
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static java.lang.Math.abs;
|
||||
import static java.lang.Math.floorDiv;
|
||||
import static java.lang.Math.floorMod;
|
||||
import static java.lang.Math.incrementExact;
|
||||
import static java.sql.Types.NULL;
|
||||
|
||||
@ -49,15 +57,21 @@ public class HomeLayoutGenerator {
|
||||
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.cardview_currency, null);
|
||||
|
||||
|
||||
|
||||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
view.animate();
|
||||
/*view.animate();
|
||||
Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class);
|
||||
intent.putExtra("currency", currency);
|
||||
context.getApplicationContext().startActivity(intent);
|
||||
context.getApplicationContext().startActivity(intent);*/
|
||||
if(view.findViewById(R.id.LineChartView).getVisibility() == View.VISIBLE || view.findViewById(R.id.errorTextView).getVisibility() == View.VISIBLE)
|
||||
{
|
||||
collapseView(view);
|
||||
}
|
||||
else
|
||||
{
|
||||
extendView(currency, view);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -78,12 +92,98 @@ public class HomeLayoutGenerator {
|
||||
.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));
|
||||
|
||||
List<Double> borders = getAxisBorders(currency);
|
||||
LineChartView chartView = (LineChartView) view.findViewById(R.id.LineChartView);
|
||||
|
||||
chartView.setAxisBorderValues(borders.get(0).floatValue(), borders.get(1).floatValue())
|
||||
.setYLabels(AxisRenderer.LabelPosition.NONE)
|
||||
.setYAxis(false)
|
||||
.setXAxis(false)
|
||||
.setVisibility(View.VISIBLE);
|
||||
|
||||
chartView.addData(generateChartSet(currency));
|
||||
|
||||
chartView.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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
private void extendView(Currency currency, 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)
|
||||
{
|
||||
((LineChartView) view.findViewById(R.id.LineChartView)).setVisibility(View.VISIBLE);
|
||||
((LineChartView) view.findViewById(R.id.LineChartView)).show();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<Double> getAxisBorders(Currency currency)
|
||||
{
|
||||
List<Double> borders = new ArrayList<>();
|
||||
|
||||
List<CurrencyDataChart> 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)
|
||||
@ -102,6 +202,54 @@ public class HomeLayoutGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
private ChartSet generateChartSet(Currency currency)
|
||||
{
|
||||
List<CurrencyDataChart> dataChartList = currency.getHistoryMinutes();
|
||||
LineSet lineSet = new LineSet();
|
||||
int counter = 0;
|
||||
Calendar calendar = Calendar.getInstance(Locale.FRANCE);
|
||||
String hour;
|
||||
String minute;
|
||||
|
||||
for(int i = 0; i < dataChartList.size(); i+=10)
|
||||
{
|
||||
if(counter == 30)
|
||||
{
|
||||
calendar.setTimeInMillis(dataChartList.get(i).getTimestamp()*1000);
|
||||
|
||||
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());
|
||||
counter = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
counter++;
|
||||
lineSet.addPoint("", (float) dataChartList.get(i).getOpen());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
lineSet.setSmooth(true);
|
||||
lineSet.setThickness(4);
|
||||
lineSet.setFill(getColorWithAplha(currency.getChartColor(), 0.5f));
|
||||
lineSet.setColor(currency.getChartColor());
|
||||
|
||||
return lineSet;
|
||||
}
|
||||
|
||||
public CardView getInfoLayout(final Currency currency)
|
||||
//public CardView getInfoLayout(int index)
|
||||
{
|
||||
|
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="48dp"
|
||||
android:height="48dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M8.59,16.34l4.58,-4.59 -4.58,-4.59L10,5.75l6,6 -6,6z" />
|
||||
</vector>
|
@ -56,8 +56,7 @@
|
||||
android:id="@+id/switch_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/quick_button"
|
||||
android:visibility="gone"/>
|
||||
android:text="@string/quick_button"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -5,15 +5,14 @@
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
android:focusable="true"
|
||||
android:paddingBottom="4dp">
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:clickable="false"
|
||||
android:padding="10dp"
|
||||
app:cardCornerRadius="8dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent">
|
||||
|
||||
@ -21,7 +20,6 @@
|
||||
android:id="@+id/mainLinear"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dp"
|
||||
android:clickable="false"
|
||||
android:orientation="vertical"
|
||||
android:tag="mainLinear">
|
||||
@ -30,6 +28,7 @@
|
||||
android:id="@+id/currencyInfoLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
@ -124,8 +123,7 @@
|
||||
android:id="@+id/separationLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_margin="5dp"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextView
|
||||
@ -144,18 +142,38 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.db.chart.view.LineChartView
|
||||
<FrameLayout
|
||||
android:id="@+id/frameLayoutChart"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="500dp"
|
||||
android:layout_height="@dimen/cardViewChartSize"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:visibility="gone">
|
||||
|
||||
<com.db.chart.view.LineChartView
|
||||
android:id="@+id/LineChartView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/cardViewChartSize"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/errorTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="500dp"
|
||||
android:layout_height="@dimen/cardViewChartSize"
|
||||
android:gravity="center"
|
||||
android:text="Error"
|
||||
android:visibility="gone" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/detailsArrow"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_keyboard_arrow_right_grey_48dp"
|
||||
android:visibility="gone"
|
||||
android:layout_gravity="center_vertical|end"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
|
@ -1,6 +1,7 @@
|
||||
<resources>
|
||||
<dimen name="cardViewMainText">15sp</dimen>
|
||||
<dimen name="cardViewSecondaryText">12sp</dimen>
|
||||
<dimen name="cardViewChartSize">150dp</dimen>
|
||||
|
||||
<dimen name="app_bar_height">180dp</dimen>
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
|
Loading…
Reference in New Issue
Block a user