This commit is contained in:
Tanguy Herbron 2018-04-06 22:04:58 +02:00
parent 4193fc0709
commit 8b3db9b25d
2 changed files with 13 additions and 33 deletions

View File

@ -48,7 +48,7 @@ import com.nauk.coinfolio.DataManagers.BalanceManager;
import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
import com.nauk.coinfolio.DataManagers.MarketCapManager;
import com.nauk.coinfolio.DataManagers.PreferencesManager;
import com.nauk.coinfolio.LayoutManagers.HomeLayoutGenerator;
import com.nauk.coinfolio.LayoutManagers.CurrencyCardView;
import com.nauk.coinfolio.R;
import java.io.IOException;
@ -76,7 +76,6 @@ import java.util.Locale;
public class HomeActivity extends AppCompatActivity {
private PreferencesManager preferencesManager;
private HomeLayoutGenerator layoutGenerator;
private BalanceManager balanceManager;
private MarketCapManager marketCapManager;
@ -118,7 +117,6 @@ public class HomeActivity extends AppCompatActivity {
//Objects initialization
preferencesManager = new PreferencesManager(this);
layoutGenerator = new HomeLayoutGenerator(this);
balanceManager = new BalanceManager(this);
marketCapManager = new MarketCapManager(this);
handler = new Handler();
@ -424,7 +422,7 @@ public class HomeActivity extends AppCompatActivity {
if(!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001 || currency.getHistoryMinutes() == null))
{
currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden()));
currencyLayout.addView(new CurrencyCardView(this, currencyLayout).getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden()));
}
}
@ -831,7 +829,7 @@ public class HomeActivity extends AppCompatActivity {
Currency currency = balanceManager.getTotalBalance().get(i);
if(!currency.getSymbol().equals("USD") && (currency.getBalance() * currency.getValue()) > 0.001) {
currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden()));
currencyLayout.addView(new CurrencyCardView(getApplicationContext(), currencyLayout).getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden()));
}
}
}

View File

@ -5,13 +5,17 @@ import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
@ -40,18 +44,21 @@ import static java.lang.Math.abs;
* Created by Tiji on 05/01/2018.
*/
public class HomeLayoutGenerator {
public class CurrencyCardView extends CardView {
android.content.Context context;
private LinearLayout rootLayout;
public HomeLayoutGenerator(Context context)
public CurrencyCardView(Context context, LinearLayout rootLayout)
{
super(context);
this.context = context;
this.rootLayout = rootLayout;
}
public View getInfoLayout(final Currency currency, boolean isExtended, float totalValue, boolean isBalanceHidden)
{
View view = LayoutInflater.from(context).inflate(R.layout.cardview_currency, null);
View view = LayoutInflater.from(context).inflate(R.layout.cardview_currency, rootLayout, true);
view.setOnClickListener(new View.OnClickListener() {
@Override
@ -216,31 +223,6 @@ public class HomeLayoutGenerator {
view.findViewById(R.id.LineChartView).invalidate();
}
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)