]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java
more animations when collapsing profile list and when starting/editting list edit
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / profiles / ProfilesRecyclerViewAdapter.java
index ddefc65c3a66cc64848b651bd208d60a1ba09d99..8ee0dd96c696c5a299a52cdfe38a4b034f7b3a40 100644 (file)
@@ -23,6 +23,8 @@ import android.graphics.drawable.ColorDrawable;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.animation.Animation;
+import android.view.animation.AnimationUtils;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
@@ -38,6 +40,7 @@ import java.util.Collections;
 import java.util.Observer;
 
 import androidx.annotation.NonNull;
 import java.util.Observer;
 
 import androidx.annotation.NonNull;
+import androidx.constraintlayout.widget.ConstraintLayout;
 import androidx.recyclerview.widget.ItemTouchHelper;
 import androidx.recyclerview.widget.RecyclerView;
 
 import androidx.recyclerview.widget.ItemTouchHelper;
 import androidx.recyclerview.widget.RecyclerView;
 
@@ -67,7 +70,8 @@ public class ProfilesRecyclerViewAdapter
                                   @NonNull RecyclerView.ViewHolder target) {
                 Data.profiles.blockNotifications();
                 try {
                                   @NonNull RecyclerView.ViewHolder target) {
                 Data.profiles.blockNotifications();
                 try {
-                    Collections.swap(Data.profiles, viewHolder.getAdapterPosition(), target.getAdapterPosition());
+                    Collections.swap(Data.profiles, viewHolder.getAdapterPosition(),
+                            target.getAdapterPosition());
                     MobileLedgerProfile.storeProfilesOrder();
                     notifyItemMoved(viewHolder.getAdapterPosition(), target.getAdapterPosition());
                 }
                     MobileLedgerProfile.storeProfilesOrder();
                     notifyItemMoved(viewHolder.getAdapterPosition(), target.getAdapterPosition());
                 }
@@ -125,6 +129,14 @@ public class ProfilesRecyclerViewAdapter
 
         context.startActivity(intent);
     }
 
         context.startActivity(intent);
     }
+    private void onProfileRowClicked(View v) {
+        if (editingProfiles.get()) return;
+        MobileLedgerProfile profile = (MobileLedgerProfile) v.getTag();
+        if (profile == null)
+            throw new IllegalStateException("Profile row without associated profile");
+        debug("profiles", "Setting profile to " + profile.getName());
+        Data.setCurrentProfile(profile);
+    }
     @NonNull
     @Override
     public ProfileListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
     @NonNull
     @Override
     public ProfileListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
@@ -132,13 +144,14 @@ public class ProfilesRecyclerViewAdapter
                 .inflate(R.layout.profile_list_content, parent, false);
         ProfileListViewHolder holder = new ProfileListViewHolder(view);
 
                 .inflate(R.layout.profile_list_content, parent, false);
         ProfileListViewHolder holder = new ProfileListViewHolder(view);
 
+        holder.mRow.setOnClickListener(this::onProfileRowClicked);
         holder.mTitle.setOnClickListener(v -> {
             View row = (View) v.getParent();
         holder.mTitle.setOnClickListener(v -> {
             View row = (View) v.getParent();
-            MobileLedgerProfile profile = (MobileLedgerProfile) row.getTag();
-            if (profile == null)
-                throw new IllegalStateException("Profile row without associated profile");
-            debug("profiles", "Setting profile to " + profile.getName());
-            Data.setCurrentProfile(profile);
+            onProfileRowClicked(row);
+        });
+        holder.mColorTag.setOnClickListener(v -> {
+            View row = (View) v.getParent().getParent();
+            onProfileRowClicked(row);
         });
         holder.mTitle.setOnLongClickListener(v -> {
             flipEditingProfiles();
         });
         holder.mTitle.setOnLongClickListener(v -> {
             flipEditingProfiles();
@@ -183,12 +196,26 @@ public class ProfilesRecyclerViewAdapter
         holder.itemView
                 .setBackground(sameProfile ? new ColorDrawable(Colors.tableRowDarkBG) : null);
         if (editingProfiles.get()) {
         holder.itemView
                 .setBackground(sameProfile ? new ColorDrawable(Colors.tableRowDarkBG) : null);
         if (editingProfiles.get()) {
+            boolean wasHidden = holder.mEditButton.getVisibility() == View.GONE;
             holder.mRearrangeHandle.setVisibility(View.VISIBLE);
             holder.mEditButton.setVisibility(View.VISIBLE);
             holder.mRearrangeHandle.setVisibility(View.VISIBLE);
             holder.mEditButton.setVisibility(View.VISIBLE);
+            if (wasHidden) {
+                Animation a = AnimationUtils
+                        .loadAnimation(holder.mRearrangeHandle.getContext(), R.anim.fade_in);
+                holder.mRearrangeHandle.startAnimation(a);
+                holder.mEditButton.startAnimation(a);
+            }
         }
         else {
         }
         else {
+            boolean wasShown = holder.mEditButton.getVisibility() == View.VISIBLE;
             holder.mRearrangeHandle.setVisibility(View.INVISIBLE);
             holder.mEditButton.setVisibility(View.GONE);
             holder.mRearrangeHandle.setVisibility(View.INVISIBLE);
             holder.mEditButton.setVisibility(View.GONE);
+            if (wasShown) {
+                Animation a = AnimationUtils
+                        .loadAnimation(holder.mRearrangeHandle.getContext(), R.anim.fade_out);
+                holder.mRearrangeHandle.startAnimation(a);
+                holder.mEditButton.startAnimation(a);
+            }
         }
     }
     @Override
         }
     }
     @Override
@@ -203,6 +230,7 @@ public class ProfilesRecyclerViewAdapter
         final TextView mTitle, mColorTag;
         final LinearLayout tagAndHandleLayout;
         final ImageView mRearrangeHandle;
         final TextView mTitle, mColorTag;
         final LinearLayout tagAndHandleLayout;
         final ImageView mRearrangeHandle;
+        final ConstraintLayout mRow;
 
         ProfileListViewHolder(View view) {
             super(view);
 
         ProfileListViewHolder(View view) {
             super(view);
@@ -211,6 +239,7 @@ public class ProfilesRecyclerViewAdapter
             mColorTag = view.findViewById(R.id.colorTag);
             mRearrangeHandle = view.findViewById(R.id.profile_list_rearrange_handle);
             tagAndHandleLayout = view.findViewById(R.id.handle_and_tag);
             mColorTag = view.findViewById(R.id.colorTag);
             mRearrangeHandle = view.findViewById(R.id.profile_list_rearrange_handle);
             tagAndHandleLayout = view.findViewById(R.id.handle_and_tag);
+            mRow = (ConstraintLayout) view;
         }
     }
 }
         }
     }
 }