From 88d426b0b86c9a5b1de849e709a74028f28f59a2 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Wed, 7 Feb 2018 17:12:02 +0100 Subject: [PATCH] Switching summary card generation to xml inflater --- .idea/misc.xml | 2 +- .../coinfolio/Activities/HomeActivity.java | 15 ++-- .../LayoutManagers/HomeLayoutGenerator.java | 61 +++++++++++++++- .../res/layout/activity_currency_summary.xml | 3 +- app/src/main/res/layout/cardview_currency.xml | 70 +++++++++++-------- app/src/main/res/values/dimens.xml | 3 + app/src/main/res/values/strings.xml | 8 +++ 7 files changed, 124 insertions(+), 38 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 3963879..75dac50 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -24,7 +24,7 @@ - + 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 f06a213..aa4ee96 100644 --- a/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/coinfolio/Activities/HomeActivity.java @@ -247,17 +247,20 @@ 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)); + currencyLayout.addView(layoutGenerator.getInfoLayout(currency, true)); } } + + //currencyLayout.addView(layoutGenerator.getInfoLayout(balanceManager.getTotalBalance().get(0), true)); } else { - for(int i = 0; i < currencyLayout.getChildCount(); i++) + /*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(); @@ -494,7 +497,7 @@ public class HomeActivity extends AppCompatActivity { @Override protected Void doInBackground(Void... params) { - final List cardList = new ArrayList<>(); + final List cardList = new ArrayList<>(); Looper.prepare(); @@ -522,12 +525,12 @@ public class HomeActivity extends AppCompatActivity { totalValue += localCurrency.getValue() * localCurrency.getBalance(); totalFluctuation += (localCurrency.getValue() * localCurrency.getBalance()) * (localCurrency.getDayFluctuationPercentage() / 100); - cardList.add(layoutGenerator.getInfoLayout(localCurrency)); + cardList.add(layoutGenerator.getInfoLayout(localCurrency, true)); } if(!localCurrency.getSymbol().equals("USD") && localCurrency.getHistoryMinutes() == null) { - cardList.add(layoutGenerator.getInfoLayout(localCurrency)); + cardList.add(layoutGenerator.getInfoLayout(localCurrency, true)); } balanceManager.getTotalBalance().set(i, localCurrency); diff --git a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java index 628dca1..cb9aaae 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java @@ -8,6 +8,7 @@ import android.graphics.Bitmap; import android.graphics.Color; import android.support.v7.widget.CardView; import android.view.Gravity; +import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; @@ -43,7 +44,65 @@ public class HomeLayoutGenerator { this.context = context; } - public CardView getInfoLayout(final Currency currency, boolean isExtended) + public View getInfoLayout(final Currency currency, boolean isExtended) + { + + View view = LayoutInflater.from(context).inflate(R.layout.cardview_currency, null); + + + + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + view.animate(); + Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class); + intent.putExtra("currency", currency); + context.getApplicationContext().startActivity(intent); + } + }); + + ((ImageView) view.findViewById(R.id.currencyIcon)) + .setImageBitmap(currency.getIcon()); + ((TextView) view.findViewById(R.id.currencyNameTextView)) + .setText(currency.getName()); + ((TextView) view.findViewById(R.id.currencySymbolTextView)) + .setText(context.getResources().getString(R.string.currencySymbolPlaceholder, currency.getSymbol())); + ((TextView) view.findViewById(R.id.currencyOwnedTextView)) + .setText(context.getResources().getString(R.string.currencyBalancePlaceholder, numberConformer(currency.getBalance()), currency.getSymbol())); + ((TextView) view.findViewById(R.id.currencyValueOwnedTextView)) + .setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getValue() * currency.getBalance()))); + + ((TextView) view.findViewById(R.id.currencyValueTextView)) + .setText(context.getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(currency.getValue()))); + ((TextView) view.findViewById(R.id.currencyFluctuationPercentageTextView)) + .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()))); + + updateColor(view, currency); + + return view; + } + + private void updateColor(View view, Currency currency) + { + if(currency.getDayFluctuationPercentage() > 0) + { + ((TextView) view.findViewById(R.id.currencyFluctuationPercentageTextView)) + .setTextColor(context.getResources().getColor(R.color.increase)); + ((TextView) view.findViewById(R.id.currencyFluctuationTextView)) + .setTextColor(context.getResources().getColor(R.color.increase)); + } + else + { + ((TextView) view.findViewById(R.id.currencyFluctuationPercentageTextView)) + .setTextColor(context.getResources().getColor(R.color.decrease)); + ((TextView) view.findViewById(R.id.currencyFluctuationTextView)) + .setTextColor(context.getResources().getColor(R.color.decrease)); + } + } + + public CardView getInfoLayout(final Currency currency) //public CardView getInfoLayout(int index) { CardView mainCard = new CardView(context); diff --git a/app/src/main/res/layout/activity_currency_summary.xml b/app/src/main/res/layout/activity_currency_summary.xml index 764889a..d961574 100644 --- a/app/src/main/res/layout/activity_currency_summary.xml +++ b/app/src/main/res/layout/activity_currency_summary.xml @@ -56,7 +56,8 @@ android:id="@+id/switch_button" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/quick_button"/> + android:text="@string/quick_button" + android:visibility="gone"/> diff --git a/app/src/main/res/layout/cardview_currency.xml b/app/src/main/res/layout/cardview_currency.xml index 09aee34..9f084d7 100644 --- a/app/src/main/res/layout/cardview_currency.xml +++ b/app/src/main/res/layout/cardview_currency.xml @@ -1,24 +1,30 @@ + android:layout_height="wrap_content" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:clickable="true" + android:focusable="true"> + app:layout_constraintBottom_toBottomOf="parent"> + android:tag="mainLinear"> + android:layout_margin="1dp" /> + android:textSize="@dimen/cardViewMainText" /> + android:textSize="@dimen/cardViewSecondaryText" /> + android:textSize="@dimen/cardViewMainText" /> @@ -74,34 +82,37 @@ android:id="@+id/currencyOwnedTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:textSize="@dimen/mainText" + android:gravity="left" android:textColor="@color/mainTextViewColor" - android:gravity="left" /> + android:textSize="@dimen/cardViewMainText" /> + android:textSize="@dimen/cardViewSecondaryText" /> + android:gravity="right" + android:orientation="horizontal"> + android:textSize="@dimen/cardViewMainText" /> + android:textSize="@dimen/cardViewSecondaryText" /> @@ -114,35 +125,36 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" - android:layout_marginRight="10dp"> + android:layout_marginRight="10dp" + android:visibility="gone"> + android:textSize="@dimen/cardViewSecondaryText" /> + android:background="@color/separationLine" /> + android:visibility="gone" /> + android:text="Error" + android:visibility="gone" /> diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 2960eca..40d6529 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,4 +1,7 @@ + 15sp + 12sp + 180dp 16dp 16dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0a530f8..aed0625 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -131,4 +131,12 @@ 3M 6M 1y + + + (%1$s) + %1$s%2$s + (US$%1$s) + US$%1$s + %1$s%% +