"final" fixes on account list layout
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Tue, 9 Jun 2020 20:08:50 +0000 (20:08 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Tue, 9 Jun 2020 20:08:50 +0000 (20:08 +0000)
should work better on overly long account names or amounts

also shows the bottom trailer

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/layout/account_summary_row.xml
app/src/main/res/values/styles.xml

index 80036a6..2490ff3 100644 (file)
@@ -24,7 +24,6 @@ import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.widget.FrameLayout;
 import android.widget.ImageView;
 import android.widget.TextView;
 
@@ -59,9 +58,9 @@ public class AccountSummaryAdapter
                 ConstraintLayout.LayoutParams lp =
                         (ConstraintLayout.LayoutParams) holder.tvAccountName.getLayoutParams();
                 lp.setMarginStart(
-                        acc.getLevel() * rm.getDimensionPixelSize(R.dimen.thumb_row_height) / 2);
+                        acc.getLevel() * rm.getDimensionPixelSize(R.dimen.thumb_row_height) / 3);
                 holder.expanderContainer
-                        .setVisibility(acc.hasSubAccounts() ? View.VISIBLE : View.INVISIBLE);
+                        .setVisibility(acc.hasSubAccounts() ? View.VISIBLE : View.GONE);
                 holder.expanderContainer.setRotation(acc.isExpanded() ? 0 : 180);
                 int amounts = acc.getAmountCount();
                 if ((amounts > AMOUNT_LIMIT) && !acc.amountsExpanded()) {
@@ -101,7 +100,8 @@ public class AccountSummaryAdapter
 
     @Override
     public int getItemCount() {
-        return Data.accounts.size();
+        return Data.accounts.size() + (Data.profile.getValue()
+                                                   .isPostingPermitted() ? 1 : 0);
     }
     public void selectItem(int position) {
         try (LockHolder lh = Data.accounts.lockForWriting()) {
@@ -130,9 +130,9 @@ public class AccountSummaryAdapter
         TextView tvAccountName, tvAccountAmounts;
         ConstraintLayout row;
         View vTrailer;
-        FrameLayout expanderContainer;
+        View expanderContainer;
         ImageView expander;
-        FrameLayout accountExpanderContainer;
+        View accountExpanderContainer;
         public LedgerRowHolder(@NonNull View itemView) {
             super(itemView);
             this.row = itemView.findViewById(R.id.account_summary_row);
@@ -160,6 +160,7 @@ public class AccountSummaryAdapter
             tvAccountAmounts.setOnLongClickListener(this::onItemLongClick);
             expanderContainer.setOnLongClickListener(this::onItemLongClick);
             expander.setOnLongClickListener(this::onItemLongClick);
+            row.setOnLongClickListener(this::onItemLongClick);
         }
         private boolean onItemLongClick(View v) {
             MainActivity activity = (MainActivity) v.getContext();
@@ -170,22 +171,26 @@ public class AccountSummaryAdapter
                 case R.id.account_summary_row:
                     row = v;
                     break;
-                case R.id.account_root:
-                    row = v.findViewById(R.id.account_summary_row);
+                case R.id.account_row_acc_amounts:
+                case R.id.account_row_amounts_expander_container:
+                    row = (View) v.getParent();
                     break;
                 case R.id.account_row_acc_name:
-                case R.id.account_row_acc_amounts:
                 case R.id.account_expander_container:
-                    row = (View) v.getParent();
+                    row = (View) v.getParent()
+                                  .getParent();
                     break;
                 case R.id.account_expander:
-                    row = (View) v.getParent().getParent();
+                    row = (View) v.getParent()
+                                  .getParent()
+                                  .getParent();
                     break;
                 default:
-                    Log.e("error", String.format("Don't know how to handle long click on id %d", id));
+                    Log.e("error",
+                            String.format("Don't know how to handle long click on id %d", id));
                     return false;
             }
-            LedgerAccount acc = (LedgerAccount) row.findViewById(R.id.account_summary_row).getTag();
+            LedgerAccount acc = (LedgerAccount) row.getTag();
             builder.setTitle(acc.getName());
             builder.setItems(R.array.acc_ctx_menu, (dialog, which) -> {
                 switch (which) {
index 3f71e0a..360f300 100644 (file)
@@ -655,11 +655,21 @@ public class MainActivity extends ProfileThemedActivity {
     }
     public void onAccountSummaryRowViewClicked(View view) {
         ViewGroup row;
-        if (view.getId() == R.id.account_expander)
-            row = (ViewGroup) view.getParent()
-                                  .getParent();
-        else
-            row = (ViewGroup) view.getParent();
+        switch (view.getId()) {
+            case R.id.account_expander:
+                row = (ViewGroup) view.getParent()
+                                      .getParent()
+                                      .getParent();
+                break;
+            case R.id.account_expander_container:
+            case R.id.account_row_acc_name:
+                row = (ViewGroup) view.getParent()
+                                      .getParent();
+                break;
+            default:
+                row = (ViewGroup) view.getParent();
+                break;
+        }
 
         LedgerAccount acc = (LedgerAccount) row.getTag();
         switch (view.getId()) {
index 522c593..3283a2e 100644 (file)
   ~ You should have received a copy of the GNU General Public License
   ~ along with MoLe. If not, see <https://www.gnu.org/licenses/>.
   -->
-
-<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
-    xmlns:tools="http://schemas.android.com/tools"
-    android:id="@+id/account_summary_row"
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:longClickable="true"
     >
 
-    <TextView
-        android:id="@+id/account_row_acc_name"
-        style="@style/account_summary_account_name"
-        android:layout_width="wrap_content"
-        android:layout_height="0dp"
-        android:layout_weight="1"
-        android:gravity="center_vertical"
+    <androidx.constraintlayout.widget.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
+        xmlns:tools="http://schemas.android.com/tools"
+        android:id="@+id/account_summary_row"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
         android:longClickable="true"
-        android:onClick="onAccountSummaryRowViewClicked"
-        android:paddingStart="8dp"
-        android:text="Account name, a really long one. A very very very long one. It may even spawn on more than two lines -- three, four or more."
-        android:textAppearance="@android:style/TextAppearance.Material.Medium"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent"
-        tools:ignore="HardcodedText"
-        />
-
-    <FrameLayout
-        android:id="@+id/account_expander_container"
-        android:layout_width="@dimen/thumb_row_height"
-        android:layout_height="@dimen/thumb_row_height"
-        android:foregroundGravity="center_vertical"
         android:minHeight="@dimen/thumb_row_height"
-        android:onClick="onAccountSummaryRowViewClicked"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintStart_toEndOf="@id/account_row_acc_name"
-        app:layout_constraintTop_toTopOf="parent"
         >
+        <androidx.constraintlayout.widget.ConstraintLayout
+            android:id="@+id/account_name_layout"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toStartOf="@+id/account_row_acc_amounts"
+            app:layout_constraintHorizontal_chainStyle="spread_inside"
+            app:layout_constraintHorizontal_weight="3"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent"
+            >
+            <TextView
+                android:id="@+id/account_row_acc_name"
+                style="@style/account_summary_account_name"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginStart="8dp"
+                android:gravity="center_vertical"
+                android:longClickable="true"
+                android:onClick="onAccountSummaryRowViewClicked"
+                android:paddingStart="8dp"
+                android:text="AccountNameALongOne"
+                android:textAppearance="@android:style/TextAppearance.Material.Medium"
+                app:layout_constrainedWidth="true"
+                app:layout_constraintBottom_toBottomOf="parent"
+                app:layout_constraintEnd_toStartOf="@id/account_expander_container"
+                app:layout_constraintHorizontal_bias="0.0"
+                app:layout_constraintHorizontal_chainStyle="packed"
+                app:layout_constraintStart_toStartOf="parent"
+                app:layout_constraintTop_toTopOf="parent"
+                app:layout_constraintWidth_max="wrap"
+                app:layout_constraintWidth_percent=".67"
+                tools:ignore="HardcodedText"
+                />
+
+            <androidx.constraintlayout.widget.ConstraintLayout
+                android:id="@+id/account_expander_container"
+                android:layout_width="@dimen/thumb_row_height"
+                android:layout_height="@dimen/thumb_row_height"
+                android:foregroundGravity="center_vertical"
+                android:minHeight="@dimen/thumb_row_height"
+                android:onClick="onAccountSummaryRowViewClicked"
+                app:layout_constraintBottom_toBottomOf="@id/account_row_acc_name"
+                app:layout_constraintEnd_toEndOf="parent"
+                app:layout_constraintStart_toEndOf="@id/account_row_acc_name"
+                app:layout_constraintTop_toTopOf="@id/account_row_acc_name"
+                >
 
-        <ImageView
-            android:id="@+id/account_expander"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:layout_margin="8dp"
-            android:background="@drawable/ic_expand_less_black_24dp"
-            android:clickable="true"
+                <ImageView
+                    android:id="@+id/account_expander"
+                    android:layout_width="32dp"
+                    android:layout_height="32dp"
+                    android:background="@drawable/ic_expand_less_black_24dp"
+                    android:clickable="true"
+                    android:onClick="onAccountSummaryRowViewClicked"
+                    app:layout_constraintBottom_toBottomOf="parent"
+                    app:layout_constraintEnd_toEndOf="parent"
+                    app:layout_constraintStart_toStartOf="parent"
+                    app:layout_constraintTop_toTopOf="parent"
+                    />
+            </androidx.constraintlayout.widget.ConstraintLayout>
+        </androidx.constraintlayout.widget.ConstraintLayout>
+        <TextView
+            android:id="@+id/account_row_acc_amounts"
+            style="@style/account_summary_amounts"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="12dp"
+            android:layout_marginEnd="8dp"
+            android:gravity="center_vertical"
             android:onClick="onAccountSummaryRowViewClicked"
+            android:text="USD 123,45\n678,90\nIRAUSD -17 000.00"
+            android:textAppearance="@style/TextAppearance.AppCompat.Medium"
+            app:layout_constrainedWidth="true"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintHorizontal_weight="2"
+            app:layout_constraintStart_toEndOf="@id/account_name_layout"
+            app:layout_constraintTop_toTopOf="parent"
+            app:layout_constraintWidth_min="90sp"
+            tools:ignore="HardcodedText"
             />
-    </FrameLayout>
 
-    <TextView
-        android:id="@+id/account_row_filler1"
-        android:layout_width="0dp"
-        android:layout_height="match_parent"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toStartOf="@id/account_row_acc_amounts"
-        app:layout_constraintStart_toEndOf="@id/account_expander_container"
-        app:layout_constraintTop_toTopOf="parent"
-        />
-
-    <TextView
-        android:id="@+id/account_row_acc_amounts"
-        style="@style/account_summary_amounts"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        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:textAppearance="@style/TextAppearance.AppCompat.Medium"
-        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="18sp"
-        android:background="@drawable/fade_down_white"
-        app:layout_constraintBottom_toBottomOf="@id/account_row_acc_amounts"
-        app:layout_constraintEnd_toEndOf="@id/account_row_acc_amounts"
-        app:layout_constraintStart_toStartOf="@id/account_row_acc_amounts"
-        >
+        <FrameLayout
+            android:id="@+id/account_row_amounts_expander_container"
+            android:layout_width="0dp"
+            android:layout_height="18sp"
+            android:background="@drawable/fade_down_white"
+            app:layout_constraintBottom_toBottomOf="@id/account_row_acc_amounts"
+            app:layout_constraintEnd_toEndOf="@id/account_row_acc_amounts"
+            app:layout_constraintStart_toStartOf="@id/account_row_acc_amounts"
+            >
 
-    </FrameLayout>
+        </FrameLayout>
 
+    </androidx.constraintlayout.widget.ConstraintLayout>
     <View
         android:id="@+id/account_summary_trailer"
         android:layout_width="match_parent"
         android:layout_height="80dp"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent"
         />
-</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
+</FrameLayout>
index 9bd102f..b0c366d 100644 (file)
     </style>
 
     <style name="account_summary_account_name">
-        <item name="android:layout_width">wrap_content</item>
-        <item name="android:layout_height">wrap_content</item>
-        <item name="android:layout_weight">5</item>
     </style>
 
     <style name="account_summary_amounts">
-        <item name="android:layout_width">wrap_content</item>
-        <item name="android:layout_height">wrap_content</item>
-        <item name="android:layout_marginEnd">0dp</item>
-        <item name="android:layout_weight">1</item>
-        <item name="android:minWidth">60dp</item>
         <item name="android:textAlignment">viewEnd</item>
     </style>