]> git.ktnx.net Git - mobile-ledger.git/commitdiff
rework comment show/hide/blur with colors instead of alpha
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 13 May 2020 18:36:01 +0000 (21:36 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 14 May 2020 17:39:53 +0000 (17:39 +0000)
alpha interferes with layout animations

app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java
app/src/main/res/layout/new_transaction_row.xml

index d92a4c69d542aaef4496ac002d4de7b6a80aed9e..efb7b52256871d7714a297cdad08b8d92f6f2dcb 100644 (file)
@@ -97,17 +97,17 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
     //TODO multiple amounts with different currencies per posting
     NewTransactionItemHolder(@NonNull View itemView, NewTransactionItemsAdapter adapter) {
         super(itemView);
-        tvAccount = itemView.findViewById(R.id.account_row_acc_name);
-        tvComment = itemView.findViewById(R.id.comment);
+        lAccount = itemView.findViewById(R.id.ntr_account);
+        tvAccount = lAccount.findViewById(R.id.account_row_acc_name);
+        tvComment = lAccount.findViewById(R.id.comment);
         tvTransactionComment = itemView.findViewById(R.id.transaction_comment);
         new TextViewClearHelper().attachToTextView((EditText) tvComment);
-        commentButton = itemView.findViewById(R.id.comment_button);
+        commentButton = lAccount.findViewById(R.id.comment_button);
         tvAmount = itemView.findViewById(R.id.account_row_acc_amounts);
         tvCurrency = itemView.findViewById(R.id.currency);
         tvDate = itemView.findViewById(R.id.new_transaction_date);
         tvDescription = itemView.findViewById(R.id.new_transaction_description);
         lHead = itemView.findViewById(R.id.ntr_data);
-        lAccount = itemView.findViewById(R.id.ntr_account);
         lPadding = itemView.findViewById(R.id.ntr_padding);
         final View commentLayout = itemView.findViewById(R.id.comment_layout);
         final View transactionCommentLayout =
@@ -124,7 +124,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
             tvComment.requestFocus();
         });
 
-        itemView.findViewById(R.id.transaction_comment_button)
+        transactionCommentLayout.findViewById(R.id.comment_button)
                 .setOnClickListener(v -> {
                     tvTransactionComment.setVisibility(View.VISIBLE);
                     tvTransactionComment.requestFocus();
@@ -398,23 +398,22 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
             ConstraintLayout.LayoutParams accountParams =
                     (ConstraintLayout.LayoutParams) tvAccount.getLayoutParams();
             if (show) {
-                commentLayout.setVisibility(View.VISIBLE);
-
                 accountParams.endToStart = ConstraintLayout.LayoutParams.UNSET;
                 accountParams.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
 
                 amountLayoutParams.topToTop = ConstraintLayout.LayoutParams.UNSET;
                 amountLayoutParams.topToBottom = tvAccount.getId();
+
+                commentLayout.setVisibility(View.VISIBLE);
             }
             else {
-                commentLayout.setVisibility(View.GONE);
-
                 accountParams.endToStart = amountLayout.getId();
                 accountParams.endToEnd = ConstraintLayout.LayoutParams.UNSET;
 
                 amountLayoutParams.topToBottom = ConstraintLayout.LayoutParams.UNSET;
                 amountLayoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
 
+                commentLayout.setVisibility(View.GONE);
             }
 
             tvAccount.setLayoutParams(accountParams);
@@ -424,15 +423,22 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
         };
     }
     private void commentFocusChanged(View layout, TextView textView, boolean hasFocus) {
-        layout.setAlpha(hasFocus ? 1f : 0.5f);
-        textView.setTypeface(null, hasFocus ? Typeface.NORMAL : Typeface.ITALIC);
-        if (hasFocus)
+        int textColor;
+        if (hasFocus) {
+            textColor = Colors.defaultTextColor;
+            textView.setTypeface(null, Typeface.NORMAL);
             textView.setHint(R.string.transaction_account_comment_hint);
-        else
+        }
+        else {
+            textColor = Colors.defaultTextColorDisabled;
+            textView.setTypeface(null, Typeface.ITALIC);
             textView.setHint("");
+            if (Misc.isEmptyOrNull(textView.getText())) {
+                textView.setVisibility(View.INVISIBLE);
+            }
+        }
+        textView.setTextColor(textColor);
 
-        if (!hasFocus && Misc.isEmptyOrNull(textView.getText()))
-            textView.setVisibility(View.INVISIBLE);
     }
     private void updateCurrencyPositionAndPadding(Currency.Position position, boolean hasGap) {
         ConstraintLayout.LayoutParams amountLP =
index 44d902e032240c3dcea046416fc0f6bb35dfbc67..ca1889eef97e8370a0faca6d320e232ad2b3b851 100644 (file)
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:animateLayoutChanges="false"
+    android:animateLayoutChanges="true"
     android:orientation="vertical">
 
     <androidx.constraintlayout.widget.ConstraintLayout
         android:id="@+id/ntr_data"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:animateLayoutChanges="true"
         android:orientation="horizontal">
 
         <EditText
             android:id="@+id/transaction_comment_layout"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
-            android:alpha="0.50"
             app:layout_constraintEnd_toEndOf="parent"
             app:layout_constraintStart_toStartOf="parent"
             app:layout_constraintTop_toBottomOf="@id/new_transaction_description">
 
             <TextView
-                android:id="@+id/transaction_comment_button"
+                android:id="@+id/comment_button"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:background="@drawable/ic_comment_gray_24dp"
@@ -99,7 +99,7 @@
                 android:inputType="text"
                 android:visibility="invisible"
                 app:layout_constraintEnd_toEndOf="parent"
-                app:layout_constraintStart_toEndOf="@id/transaction_comment_button"
+                app:layout_constraintStart_toEndOf="@id/comment_button"
                 app:layout_constraintTop_toTopOf="parent" />
         </androidx.constraintlayout.widget.ConstraintLayout>
 
             android:id="@+id/comment_layout"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
-            android:alpha="0.50"
             app:layout_constraintEnd_toStartOf="@id/amount_layout"
             app:layout_constraintStart_toStartOf="parent"
             app:layout_constraintTop_toBottomOf="@id/account_row_acc_name">
 
             <TextView
-                android:id="@+id/comment_button"
+                android:id="@id/comment_button"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:background="@drawable/ic_comment_gray_24dp"