From: Damyan Ivanov Date: Fri, 19 Apr 2019 15:18:43 +0000 (+0300) Subject: profile list: react on clicking on different parts of the profile row X-Git-Tag: v0.10.0~93 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=aef08f9dbd6b28d320dec8b1f1a51dc1e2c344d6;p=mobile-ledger.git profile list: react on clicking on different parts of the profile row notable the color tag and the space on the left --- 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; } } }