From 8b3db9b25d27625940417022321e69a731934304 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Fri, 6 Apr 2018 22:04:58 +0200 Subject: [PATCH] Crash... --- .../coinfolio/Activities/HomeActivity.java | 8 ++-- ...utGenerator.java => CurrencyCardView.java} | 38 +++++-------------- 2 files changed, 13 insertions(+), 33 deletions(-) rename app/src/main/java/com/nauk/coinfolio/LayoutManagers/{HomeLayoutGenerator.java => CurrencyCardView.java} (92%) diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java index bbb22c3..1e988ba 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -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())); } } } diff --git a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyCardView.java similarity index 92% rename from app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java rename to app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyCardView.java index 70de870..45de5fc 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/CurrencyCardView.java @@ -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 getAxisBorders(Currency currency) - { - List borders = new ArrayList<>(); - - List 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)