From aef08f9dbd6b28d320dec8b1f1a51dc1e2c344d6 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Fri, 19 Apr 2019 18:18:43 +0300 Subject: [PATCH] profile list: react on clicking on different parts of the profile row notable the color tag and the space on the left --- .../profiles/ProfilesRecyclerViewAdapter.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java index ddefc65c..4531e9fa 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java @@ -38,6 +38,7 @@ import java.util.Collections; import java.util.Observer; import androidx.annotation.NonNull; +import androidx.constraintlayout.widget.ConstraintLayout; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; @@ -125,6 +126,13 @@ public class ProfilesRecyclerViewAdapter context.startActivity(intent); } + private void onProfileRowClicked(View v) { + 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) { @@ -132,13 +140,14 @@ public class ProfilesRecyclerViewAdapter .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(); - 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(); @@ -203,6 +212,7 @@ public class ProfilesRecyclerViewAdapter final TextView mTitle, mColorTag; final LinearLayout tagAndHandleLayout; final ImageView mRearrangeHandle; + final ConstraintLayout mRow; ProfileListViewHolder(View view) { super(view); @@ -211,6 +221,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); + mRow = (ConstraintLayout) view; } } } -- 2.39.2