From: Damyan Ivanov Date: Thu, 28 Mar 2019 17:48:49 +0000 (+0200) Subject: overly long commodity lists fade to white and expand/collapse on click X-Git-Tag: v0.9~58 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=1edf82b2b2e9c73897d115c23581eb581820264b;p=mobile-ledger.git overly long commodity lists fade to white and expand/collapse on click --- diff --git a/app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java b/app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java index 081b7bc9..0e2ae250 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java @@ -119,7 +119,7 @@ public class LedgerAccount { public void addAmount(float amount) { this.addAmount(amount, null); } - + public int getAmountCount() { return amounts.size(); } public String getAmountsString() { if ((amounts == null) || amounts.isEmpty()) return ""; @@ -132,7 +132,21 @@ public class LedgerAccount { return builder.toString(); } + public String getAmountsString(int limit) { + if ((amounts == null) || amounts.isEmpty()) return ""; + int included = 0; + StringBuilder builder = new StringBuilder(); + for (LedgerAmount amount : amounts) { + String amt = amount.toString(); + if (builder.length() > 0) builder.append('\n'); + builder.append(amt); + included++; + if (included == limit) break; + } + + return builder.toString(); + } public int getLevel() { return level; } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java index bd71fd74..45a96667 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java @@ -41,6 +41,7 @@ import androidx.recyclerview.widget.RecyclerView; public class AccountSummaryAdapter extends RecyclerView.Adapter { + public static final int AMOUNT_LIMIT = 3; private boolean selectionActive; AccountSummaryAdapter() { @@ -65,7 +66,15 @@ public class AccountSummaryAdapter holder.expanderContainer .setVisibility(acc.hasSubAccounts() ? View.VISIBLE : View.INVISIBLE); holder.expanderContainer.setRotation(acc.isExpanded() ? 0 : 180); - holder.tvAccountAmounts.setText(acc.getAmountsString()); + int amounts = acc.getAmountCount(); + if ((amounts > AMOUNT_LIMIT) && !acc.amountsExpanded()) { + holder.tvAccountAmounts.setText(acc.getAmountsString(AMOUNT_LIMIT)); + holder.accountExpanderContainer.setVisibility(View.VISIBLE); + } + else { + holder.tvAccountAmounts.setText(acc.getAmountsString()); + holder.accountExpanderContainer.setVisibility(View.GONE); + } if (acc.isHiddenByStar()) { holder.tvAccountName.setTypeface(null, Typeface.ITALIC); @@ -151,6 +160,7 @@ public class AccountSummaryAdapter View vTrailer; FrameLayout expanderContainer; ImageView expander; + FrameLayout accountExpanderContainer; public LedgerRowHolder(@NonNull View itemView) { super(itemView); this.row = itemView.findViewById(R.id.account_summary_row); @@ -160,6 +170,7 @@ public class AccountSummaryAdapter this.vTrailer = itemView.findViewById(R.id.account_summary_trailer); this.expanderContainer = itemView.findViewById(R.id.account_expander_container); this.expander = itemView.findViewById(R.id.account_expander); + this.accountExpanderContainer = itemView.findViewById(R.id.account_row_amounts_expander_container); MainActivity activity = (MainActivity) row.getContext(); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index 9f2777b2..2f65564a 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -643,7 +643,15 @@ public class MainActivity extends ProfileThemedActivity { } break; case R.id.account_row_acc_amounts: - showAccountTransactions(acc); + if (acc.getAmountCount() > AccountSummaryAdapter.AMOUNT_LIMIT) { + acc.toggleAmountsExpanded(); + DbOpQueue + .add("update accounts set amounts_expanded=? where name=? and profile=?", + new Object[]{acc.amountsExpanded(), acc.getName(), + Data.profile.get().getUuid() + }); + Data.accounts.triggerItemChangedNotification(acc); + } break; } } diff --git a/app/src/main/res/drawable-anydpi-v21/fade_down_white.xml b/app/src/main/res/drawable-anydpi-v21/fade_down_white.xml new file mode 100644 index 00000000..63add291 --- /dev/null +++ b/app/src/main/res/drawable-anydpi-v21/fade_down_white.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/account_summary_row.xml b/app/src/main/res/layout/account_summary_row.xml index 1fb4588c..e9764030 100644 --- a/app/src/main/res/layout/account_summary_row.xml +++ b/app/src/main/res/layout/account_summary_row.xml @@ -87,14 +87,32 @@ android:layout_marginEnd="8dp" android:layout_weight="0" android:gravity="center_vertical" + android:minWidth="@dimen/thumb_row_height" android:onClick="onAccountSummaryRowViewClicked" android:text="123,45\n678,90" - android:minWidth="@dimen/thumb_row_height" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" tools:ignore="HardcodedText" /> + + + + + + + + + + +