Add per currency fluctuation and currency icon in the detail activity

This commit is contained in:
Tanguy Herbron 2018-03-15 12:30:30 +01:00
parent 1ca4db4b24
commit 2422618400
6 changed files with 115 additions and 5 deletions

View File

@ -1,17 +1,27 @@
package com.nauk.coinfolio.Activities; package com.nauk.coinfolio.Activities;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView; import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.NavUtils; import android.support.v4.app.NavUtils;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.ViewFlipper; import android.widget.ViewFlipper;
@ -28,6 +38,7 @@ import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction;
import com.nauk.coinfolio.DataManagers.DatabaseManager; import com.nauk.coinfolio.DataManagers.DatabaseManager;
import com.nauk.coinfolio.R; import com.nauk.coinfolio.R;
import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
@ -129,7 +140,21 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
chartLayout.addView(errorTextView, 0); chartLayout.addView(errorTextView, 0);
} }
setTitle(currency.getName()); setTitle(" " + currency.getName());
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME |
ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_USE_LOGO);
Bitmap result = Bitmap.createBitmap(150, 150, currency.getIcon().getConfig());
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(ContextCompat.getColor(this, R.color.white));
Canvas canvas = new Canvas(result);
canvas.drawCircle(result.getHeight()/2, result.getWidth()/2, 75, paint);
canvas.drawBitmap(Bitmap.createScaledBitmap(currency.getIcon(), 100, 100, false), result.getHeight()/2 - 50, result.getWidth()/2 - 50, null);
getSupportActionBar().setIcon(new BitmapDrawable(Bitmap.createScaledBitmap(result, 120, 120, false)));
BottomNavigationView navigation = findViewById(R.id.navigation_details); BottomNavigationView navigation = findViewById(R.id.navigation_details);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
@ -306,6 +331,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
chartView.setFadingEdgeLength(15); chartView.setFadingEdgeLength(15);
chartView.setLongClickable(true); chartView.setLongClickable(true);
updateFluctuation(lineSet);
findViewById(R.id.chartView).setVisibility(View.VISIBLE); findViewById(R.id.chartView).setVisibility(View.VISIBLE);
findViewById(R.id.progressLayoutChart).setVisibility(View.GONE); findViewById(R.id.progressLayoutChart).setVisibility(View.GONE);
@ -313,6 +340,31 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
chartView.show(new Animation().fromAlpha(0)); chartView.show(new Animation().fromAlpha(0));
} }
private void updateFluctuation(LineSet lineSet)
{
float fluctuation = lineSet.getEntry(lineSet.size() - 1).getValue() - lineSet.getEntry(0).getValue();
float percentageFluctuation = (float) (fluctuation / lineSet.getEntry(0).getValue() * 100);
/*
dayFluctuation = historyMinutes.get(historyMinutes.size() - 1).getOpen() - historyMinutes.get(0).getOpen();
dayFluctuationPercentage = (float) (dayFluctuation / historyMinutes.get(0).getOpen() * 100);
*/
if(percentageFluctuation < 0)
{
((TextView) findViewById(R.id.txtViewPercentage)).setTextColor(getResources().getColor(R.color.red));
}
else
{
((TextView) findViewById(R.id.txtViewPercentage)).setTextColor(getResources().getColor(R.color.green));
}
((TextView) findViewById(R.id.txtViewPriceStart)).setText("$" + lineSet.getEntry(0).getValue());
((TextView) findViewById(R.id.txtViewPriceNow)).setText("$" + lineSet.getEntry(lineSet.size() - 1).getValue());
((TextView) findViewById(R.id.txtViewPercentage)).setText(percentageFluctuation + "%");
}
private LineSet generateChartSet(int timeUnit, int amount) private LineSet generateChartSet(int timeUnit, int amount)
{ {
List<CurrencyDataChart> dataChartList = new ArrayList<>(); List<CurrencyDataChart> dataChartList = new ArrayList<>();

View File

@ -46,6 +46,7 @@ import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.PieData; import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet; import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry; import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.PercentFormatter;
import com.github.mikephil.charting.utils.ColorTemplate; import com.github.mikephil.charting.utils.ColorTemplate;
import com.luseen.spacenavigation.SpaceItem; import com.luseen.spacenavigation.SpaceItem;
import com.luseen.spacenavigation.SpaceNavigationView; import com.luseen.spacenavigation.SpaceNavigationView;
@ -304,8 +305,12 @@ public class HomeActivity extends AppCompatActivity {
nav.changeCurrentItem(-1); nav.changeCurrentItem(-1);
findViewById(R.id.toolbar_layout).setFocusable(true); findViewById(R.id.toolbar_layout).setFocusable(true);
findViewById(R.id.nestedScrollViewLayout).setNestedScrollingEnabled(true);
((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(true, true); ((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(true, true);
findViewById(R.id.nestedScrollViewLayout).setNestedScrollingEnabled(true);
findViewById(R.id.app_bar).setEnabled(true);
findViewById(R.id.toolbar_layout).setNestedScrollingEnabled(true);
findViewById(R.id.coordinatorLayout).setNestedScrollingEnabled(true);
findViewById(R.id.switch_button).setVisibility(View.VISIBLE); findViewById(R.id.switch_button).setVisibility(View.VISIBLE);
@ -317,12 +322,16 @@ public class HomeActivity extends AppCompatActivity {
((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide(); ((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide();
((SpaceNavigationView) findViewById(R.id.space)).setCentreButtonIcon(R.drawable.ic_view_list_white_24dp); ((SpaceNavigationView) findViewById(R.id.space)).setCentreButtonIcon(R.drawable.ic_view_list_white_24dp);
//0 : Unknown //0 : Watchlist
//1 : Market cap //1 : Market cap
findViewById(R.id.toolbar_layout).setFocusable(false); findViewById(R.id.toolbar_layout).setFocusable(false);
((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(false, true); ((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(false, true);
findViewById(R.id.nestedScrollViewLayout).setNestedScrollingEnabled(false); findViewById(R.id.nestedScrollViewLayout).setNestedScrollingEnabled(false);
findViewById(R.id.app_bar).setEnabled(false);
findViewById(R.id.toolbar_layout).setNestedScrollingEnabled(false);
findViewById(R.id.coordinatorLayout).setNestedScrollingEnabled(false);
findViewById(R.id.switch_button).setVisibility(View.GONE); findViewById(R.id.switch_button).setVisibility(View.GONE);
@ -592,6 +601,8 @@ public class HomeActivity extends AppCompatActivity {
set.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); set.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
set.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); set.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
PieData data = new PieData(set); PieData data = new PieData(set);
data.setValueTextSize(10);
data.setValueFormatter(new PercentFormatter());
pieChart.setData(data); pieChart.setData(data);
pieChart.setDrawSlicesUnderHole(false); pieChart.setDrawSlicesUnderHole(false);

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:pathData="M12,12m-8,0a8,8 0,1 1,16 0a8,8 0,1 1,-16 0"
android:fillColor="#ffffff"/>
</vector>

View File

@ -114,12 +114,48 @@
</LinearLayout> </LinearLayout>
<ScrollView <!--<ScrollView
android:id="@+id/svCharts" android:id="@+id/svCharts"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
</ScrollView> </ScrollView>-->
<LinearLayout
android:id="@+id/llCharts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/txtViewPriceStart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:gravity="center"/>
<TextView
android:id="@+id/txtViewPriceNow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:gravity="center"/>
<TextView
android:id="@+id/txtViewPercentage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -8,6 +8,7 @@
tools:context="com.nauk.coinfolio.Activities.HomeActivity"> tools:context="com.nauk.coinfolio.Activities.HomeActivity">
<android.support.design.widget.CoordinatorLayout <android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">

View File

@ -33,4 +33,5 @@
<color name="buttonColor">#FFFFFFFF</color> <color name="buttonColor">#FFFFFFFF</color>
<color name="red">#FFF44336</color> <color name="red">#FFF44336</color>
<color name="green">#FF4CAF50</color> <color name="green">#FF4CAF50</color>
<color name="white">#FFFFFFFF</color>
</resources> </resources>