Currency parcelable for activity intent

This commit is contained in:
Tanguy Herbron 2018-02-01 20:38:57 +01:00
parent d0b92738d6
commit f17e3a0dc8
7 changed files with 233 additions and 34 deletions

View File

@ -14,7 +14,8 @@
<activity
android:name=".Activities.HomeActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
android:theme="@style/AppTheme.NoActionBar"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -23,12 +24,16 @@
</activity>
<activity
android:name=".Activities.SettingsActivity"
android:label="@string/title_activity_settings" />
<activity android:name=".Activities.CurrencySelectionActivity" />
<activity android:name=".Activities.RecordTransactionActivity" />
android:label="@string/title_activity_settings"
android:screenOrientation="portrait"/>
<activity android:name=".Activities.CurrencySelectionActivity"
android:screenOrientation="portrait" />
<activity android:name=".Activities.RecordTransactionActivity"
android:screenOrientation="portrait" />
<activity
android:name=".Activities.CurrencyDetailsActivity"
android:label="@string/title_activity_currency_details"></activity>
android:label="@string/title_activity_currency_details"
android:screenOrientation="portrait"/>
</application>
</manifest>

View File

@ -1,6 +1,8 @@
package com.nauk.coinfolio.Activities;
import android.content.ContentValues;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
@ -17,7 +19,10 @@ import android.widget.ViewFlipper;
import com.daimajia.swipe.SwipeLayout;
import com.db.chart.model.LineSet;
import com.db.chart.renderer.AxisRenderer;
import com.db.chart.view.LineChartView;
import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart;
import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction;
import com.nauk.coinfolio.DataManagers.DatabaseManager;
import com.nauk.coinfolio.R;
@ -38,7 +43,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
private LinearLayout transactionLayout;
private LinearLayout chartLayout;
private DatabaseManager databaseManager;
private String symbol;
//private String symbol;
private Currency currency;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@ -67,7 +73,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
Intent intent = getIntent();
symbol = intent.getStringExtra("symbol");
//symbol = intent.getStringExtra("symbol");
currency = (Currency) intent.getParcelableExtra("currency");
databaseManager = new DatabaseManager(this);
@ -77,10 +84,14 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
drawTransactionList();
//drawChart();
drawChart();
setTitle(currency.getName());
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
Log.d("coinfolio", "Color received : " + currency.getChartColor());
}
private void drawChart()
@ -93,17 +104,102 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
Calendar calendar = Calendar.getInstance(Locale.FRANCE);
String hour;
String minute;
List<CurrencyDataChart> dataChartList = currency.getDayPriceHistory();
valMin = dataChartList.get(0).getOpen();
valMax = dataChartList.get(0).getOpen();
for(int i = 1; i < dataChartList.size(); i++)
{
if(valMax < dataChartList.get(i).getOpen())
{
valMax = dataChartList.get(i).getOpen();
}
if(valMin > dataChartList.get(i).getOpen())
{
valMin = dataChartList.get(i).getOpen();
}
}
if(valMax == valMin)
{
valMin = 0;
valMax *= 2;
}
chartView.setAxisBorderValues((float) valMin, (float) valMax);
chartView.setYLabels(AxisRenderer.LabelPosition.OUTSIDE);
chartView.setYAxis(false);
chartView.setXAxis(false);
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(getColorWitchAlpha(currency.getChartColor(), 0.5f));
lineSet.setColor(currency.getChartColor());
chartView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 500));
chartView.addData(lineSet);
chartLayout.addView(chartView);
Log.d("coinfolio", "Color : " + currency.getChartColor());
chartView.show();
}
private int getColorWitchAlpha(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 drawTransactionList()
{
transactionLayout.removeAllViews();
List<Transaction> transactionList = databaseManager.getCurrencyTransactions(symbol);
List<Transaction> transactionList = databaseManager.getCurrencyTransactions(currency.getSymbol());
for(int i = 0; i < transactionList.size(); i++)
{
Log.d("coinfoliobeta", "test");
View view = LayoutInflater.from(this).inflate(R.layout.custom_transaction_row, null);
TextView amountTxtView = view.findViewById(R.id.amountPurchased);
TextView valueTxtView = view.findViewById(R.id.puchasedValue);

View File

@ -234,23 +234,7 @@ public class HomeActivity extends AppCompatActivity {
if(!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001 || currency.getDayPriceHistory() == null))
{
if(currency.getIcon() != null)
{
Palette.Builder builder = Palette.from(currency.getIcon());
currency.setChartColor(builder.generate().getDominantColor(0));
//layoutGenerator.addCurrencyToList(currency);
currencyLayout.addView(layoutGenerator.getInfoLayout(currency, builder.generate().getDominantColor(0)));
//currencyLayout.addView(layoutGenerator.getInfoLayout(i));
}
else
{
//currency.setChartColor(12369084);
currencyLayout.addView(layoutGenerator.getInfoLayout(currency, 12369084));
//currencyLayout.addView(layoutGenerator.getInfoLayout(i));
}
currencyLayout.addView(layoutGenerator.getInfoLayout(currency, currency.getChartColor()));
}
}
}
@ -290,7 +274,7 @@ public class HomeActivity extends AppCompatActivity {
return null;
}
private void countCoins(boolean isCoin, boolean isIcon)
private void countCoins(boolean isCoin, boolean isDetails)
{
float totalValue = 0;
float totalFluctuation = 0;
@ -300,11 +284,17 @@ public class HomeActivity extends AppCompatActivity {
coinCounter++;
}
if(isIcon)
if(isDetails)
{
iconChecker = true;
}
for(int i = 0; i < coinCounter; i++)
{
balanceManager.getTotalBalance().get(i).setIcon(getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol())));
}
if(balanceManager.getTotalBalance() != null)
{
if(coinCounter == balanceManager.getTotalBalance().size()-1 && iconChecker)
@ -319,18 +309,37 @@ public class HomeActivity extends AppCompatActivity {
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
{
if(balanceManager.getTotalBalance().get(i).getIcon() != null)
{
//balanceManager.getTotalBalance().get(i).setIcon(getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol())));
Palette.Builder builder = Palette.from(balanceManager.getTotalBalance().get(i).getIcon());
balanceManager.getTotalBalance().get(i).setChartColor(builder.generate().getDominantColor(0));
//layoutGenerator.addCurrencyToList(currency);
//currencyLayout.addView(layoutGenerator.getInfoLayout(i));
}
else
{
//currency.setChartColor(12369084);
balanceManager.getTotalBalance().get(i).setChartColor(12369084);
//currencyLayout.addView(layoutGenerator.getInfoLayout(i));
}
if(!balanceManager.getTotalBalance().get(i).getSymbol().equals("USD") && (balanceManager.getTotalBalance().get(i).getBalance() * balanceManager.getTotalBalance().get(i).getValue()) > 0.001)
{
balanceManager.getTotalBalance().get(i).setName(balanceManager.getCurrencyName(balanceManager.getTotalBalance().get(i).getSymbol()));
totalValue += balanceManager.getTotalBalance().get(i).getValue() * balanceManager.getTotalBalance().get(i).getBalance();
totalFluctuation += (balanceManager.getTotalBalance().get(i).getValue() * balanceManager.getTotalBalance().get(i).getBalance()) * (balanceManager.getTotalBalance().get(i).getDayFluctuationPercentage() / 100);
balanceManager.getTotalBalance().get(i).setIcon(getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol())));
//balanceManager.getTotalBalance().get(i).setIcon(getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol())));
//currencyLayout.addView(layoutGenerator.getInfoLayout(i));
currencyLayout.addView(layoutGenerator.getInfoLayout(balanceManager.getTotalBalance().get(i), 0));
}
if(!balanceManager.getTotalBalance().get(i).getSymbol().equals("USD") && balanceManager.getTotalBalance().get(i).getDayPriceHistory() == null)
{
balanceManager.getTotalBalance().get(i).setIcon(getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol())));
//balanceManager.getTotalBalance().get(i).setIcon(getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol())));
//currencyLayout.addView(layoutGenerator.getInfoLayout(i));
currencyLayout.addView(layoutGenerator.getInfoLayout(balanceManager.getTotalBalance().get(i), 0));
}

View File

@ -268,6 +268,11 @@ public class BalanceManager {
return iconUrlList.get(symbol);
}
public String getCurrencyName(String symbol)
{
return coinList.get(symbol);
}
private void processDetailResult(String response, final IconCallBack callBack)
{
response = response.substring(response.indexOf("\"Data\"") + 7, response.lastIndexOf("},\"Type\":100}"));

View File

@ -1,7 +1,10 @@
package com.nauk.coinfolio.DataManagers.CurrencyData;
import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.ArrayList;
import java.util.List;
import static java.sql.Types.NULL;
@ -10,7 +13,7 @@ import static java.sql.Types.NULL;
* Created by Tiji on 25/12/2017.
*/
public class Currency {
public class Currency implements Parcelable {
private String name;
private String symbol;
@ -179,4 +182,47 @@ public class Currency {
void onSuccess(Currency currency);
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.name);
dest.writeString(this.symbol);
dest.writeDouble(this.value);
dest.writeDouble(this.balance);
dest.writeFloat(this.dayFluctuationPercentage);
dest.writeDouble(this.dayFluctuation);
dest.writeList(this.dayPriceHistory);
dest.writeParcelable(this.icon, flags);
dest.writeInt(this.chartColor);
}
protected Currency(Parcel in) {
this.name = in.readString();
this.symbol = in.readString();
this.value = in.readDouble();
this.balance = in.readDouble();
this.dayFluctuationPercentage = in.readFloat();
this.dayFluctuation = in.readDouble();
this.dayPriceHistory = new ArrayList<CurrencyDataChart>();
in.readList(this.dayPriceHistory, CurrencyDataChart.class.getClassLoader());
this.icon = in.readParcelable(Bitmap.class.getClassLoader());
this.chartColor = in.readInt();
}
public static final Parcelable.Creator<Currency> CREATOR = new Parcelable.Creator<Currency>() {
@Override
public Currency createFromParcel(Parcel source) {
return new Currency(source);
}
@Override
public Currency[] newArray(int size) {
return new Currency[size];
}
};
}

View File

@ -1,10 +1,13 @@
package com.nauk.coinfolio.DataManagers.CurrencyData;
import android.os.Parcel;
import android.os.Parcelable;
/**
* Created by Tiji on 05/01/2018.
*/
public class CurrencyDataChart {
public class CurrencyDataChart implements Parcelable {
long timestamp;
double close;
@ -35,4 +38,38 @@ public class CurrencyDataChart {
{
return timestamp;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(this.timestamp);
dest.writeDouble(this.close);
dest.writeDouble(this.high);
dest.writeDouble(this.low);
dest.writeDouble(this.open);
}
protected CurrencyDataChart(Parcel in) {
this.timestamp = in.readLong();
this.close = in.readDouble();
this.high = in.readDouble();
this.low = in.readDouble();
this.open = in.readDouble();
}
public static final Parcelable.Creator<CurrencyDataChart> CREATOR = new Parcelable.Creator<CurrencyDataChart>() {
@Override
public CurrencyDataChart createFromParcel(Parcel source) {
return new CurrencyDataChart(source);
}
@Override
public CurrencyDataChart[] newArray(int size) {
return new CurrencyDataChart[size];
}
};
}

View File

@ -78,7 +78,8 @@ public class HomeLayoutGenerator {
//switchingView(view);
view.animate();
Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class);
intent.putExtra("symbol", currency.getSymbol());
//intent.putExtra("symbol", currency.getSymbol());
intent.putExtra("currency", currency);
context.getApplicationContext().startActivity(intent);
}
});