overly long commodity lists fade to white and expand/collapse on click
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 28 Mar 2019 17:48:49 +0000 (19:48 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 28 Mar 2019 18:28:55 +0000 (20:28 +0200)
app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java
app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java
app/src/main/res/drawable-anydpi-v21/fade_down_white.xml [new file with mode: 0644]
app/src/main/res/layout/account_summary_row.xml

index 081b7bc..0e2ae25 100644 (file)
@@ -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;
     }
index bd71fd7..45a9666 100644 (file)
@@ -41,6 +41,7 @@ import androidx.recyclerview.widget.RecyclerView;
 
 public class AccountSummaryAdapter
         extends RecyclerView.Adapter<AccountSummaryAdapter.LedgerRowHolder> {
+    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();
 
index 9f2777b..2f65564 100644 (file)
@@ -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 (file)
index 0000000..63add29
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+  ~ Copyright © 2019 Damyan Ivanov.
+  ~ This file is part of MoLe.
+  ~ MoLe is free software: you can distribute it and/or modify it
+  ~ under the term of the GNU General Public License as published by
+  ~ the Free Software Foundation, either version 3 of the License, or
+  ~ (at your opinion), any later version.
+  ~
+  ~ MoLe is distributed in the hope that it will be useful,
+  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+  ~ GNU General Public License terms for details.
+  ~
+  ~ You should have received a copy of the GNU General Public License
+  ~ along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+  -->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+    <gradient
+        android:startColor="#40ffffff"
+        android:endColor="#FFffffff"
+        android:angle="270"
+        />
+</shape>
\ No newline at end of file
index 1fb4588..e976403 100644 (file)
         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" />
 
+    <FrameLayout
+        android:id="@+id/account_row_amounts_expander_container"
+        android:layout_width="0dp"
+        android:layout_height="12sp"
+        app:layout_constraintStart_toStartOf="@id/account_row_acc_amounts"
+        app:layout_constraintEnd_toEndOf="@id/account_row_acc_amounts"
+        app:layout_constraintBottom_toBottomOf="@id/account_row_acc_amounts"
+        android:background="@drawable/fade_down_white">
+
+        <!--<ImageView-->
+            <!--android:layout_gravity="center_vertical|end"-->
+            <!--android:id="@+id/account_row_amounts_expander"-->
+            <!--android:layout_width="20dp"-->
+            <!--android:layout_height="20dp"-->
+            <!--android:background="@drawable/ic_expand_more_black_24dp" />-->
+
+    </FrameLayout>
+
     <View
         android:id="@+id/account_summary_trailer"
         android:layout_width="match_parent"