Switching summary card generation to xml inflater

This commit is contained in:
Tanguy Herbron 2018-02-07 17:12:02 +01:00
parent b41ce1d9c4
commit 88d426b0b8
7 changed files with 124 additions and 38 deletions

2
.idea/misc.xml generated
View File

@ -24,7 +24,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -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<CardView> cardList = new ArrayList<>();
final List<View> 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);

View File

@ -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);

View File

@ -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"/>
</LinearLayout>

View File

@ -1,24 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:clickable="true"
android:focusable="true">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:layout_margin="10dp"
android:layout_marginBottom="8dp"
android:clickable="false"
android:padding="10dp"
app:cardCornerRadius="8dp"
android:layout_margin="10dp">
app:layout_constraintBottom_toBottomOf="parent">
<LinearLayout
android:id="@+id/mainLinear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:clickable="false"
android:orientation="vertical"
android:tag="mainLinear"
android:layout_margin="10dp"
android:clickable="false">
android:tag="mainLinear">
<LinearLayout
android:id="@+id/currencyInfoLayout"
@ -36,31 +42,33 @@
android:id="@+id/currencyIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"/>
android:layout_margin="1dp" />
<TextView
android:id="@+id/currencyNameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/mainText"
android:layout_gravity="center_vertical"
android:gravity="start"
android:textColor="@color/mainTextViewColor"
android:gravity="left"/>
android:textSize="@dimen/cardViewMainText" />
<TextView
android:id="@+id/currencySymbolTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/secondaryText"
android:layout_marginStart="2dp"
android:gravity="left"
android:textColor="@color/secondaryTextViewColor"
android:gravity="left"/>
android:textSize="@dimen/cardViewSecondaryText" />
<TextView
android:id="@+id/currencyValueTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/mainText"
android:gravity="right"
android:textColor="@color/secondaryTextViewColor"
android:gravity="right"/>
android:textSize="@dimen/cardViewMainText" />
</LinearLayout>
@ -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" />
<TextView
android:id="@+id/currencyValueOwnedTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/secondaryText"
android:layout_marginStart="2dp"
android:gravity="left"
android:textColor="@color/secondaryTextViewColor"
android:gravity="left"/>
android:textSize="@dimen/cardViewSecondaryText" />
<LinearLayout
android:id="@+id/secondaryLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="right">
android:gravity="right"
android:orientation="horizontal">
<TextView
android:id="@+id/currencyFluctuationPercentageTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/mainText"/>
android:textSize="@dimen/cardViewMainText" />
<TextView
android:id="@+id/currencyFluctuationTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/secondaryText"/>
android:textSize="@dimen/cardViewSecondaryText" />
</LinearLayout>
@ -114,17 +125,18 @@
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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Day history"
android:textSize="@dimen/secondaryText"/>
android:textSize="@dimen/cardViewSecondaryText" />
<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_height="1dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
@ -140,8 +152,8 @@
<TextView
android:layout_width="match_parent"
android:layout_height="500dp"
android:text="Error"
android:gravity="center"
android:text="Error"
android:visibility="gone" />
</LinearLayout>

View File

@ -1,4 +1,7 @@
<resources>
<dimen name="cardViewMainText">15sp</dimen>
<dimen name="cardViewSecondaryText">12sp</dimen>
<dimen name="app_bar_height">180dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="text_margin">16dp</dimen>

View File

@ -131,4 +131,12 @@
<string name="button3m">3M</string>
<string name="button6m">6M</string>
<string name="button1y">1y</string>
<!--Cardview placeholders-->
<string name="currencySymbolPlaceholder">(%1$s)</string>
<string name="currencyBalancePlaceholder">%1$s%2$s</string>
<string name="currencyDollarParenthesisPlaceholder">(US$%1$s)</string>
<string name="currencyDollarPlaceholder">US$%1$s</string>
<string name="currencyPercentagePlaceholder">%1$s%%</string>
</resources>