X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fprofiles%2FProfilesRecyclerViewAdapter.java;h=cef8d8fbf6803e71c08491bf4d5805b121473441;hb=20c03b7a5eb152d42fbbe9ecbaae27530563b398;hp=ac90ce3237a5b24128e187d33118d8fcb2c103e8;hpb=c27aa72c2c641bcd568692b4a20b125605cfb3b5;p=mobile-ledger.git 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 ac90ce32..cef8d8fb 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 @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Damyan Ivanov. + * Copyright © 2020 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -45,20 +45,19 @@ import net.ktnx.mobileledger.utils.Colors; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collections; -import java.util.Locale; import static net.ktnx.mobileledger.utils.Logger.debug; public class ProfilesRecyclerViewAdapter extends RecyclerView.Adapter { private static WeakReference instanceRef; + public final MutableLiveData editingProfiles = new MutableLiveData<>(false); private final View.OnClickListener mOnClickListener = view -> { MobileLedgerProfile profile = (MobileLedgerProfile) ((View) view.getParent()).getTag(); editProfile(view, profile); }; - public MutableLiveData editingProfiles = new MutableLiveData<>(false); + private final ItemTouchHelper rearrangeHelper; private RecyclerView recyclerView; - private ItemTouchHelper rearrangeHelper; private boolean animationsEnabled = true; public ProfilesRecyclerViewAdapter() { instanceRef = new WeakReference<>(this); @@ -106,23 +105,29 @@ public class ProfilesRecyclerViewAdapter public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); this.recyclerView = recyclerView; - if (editingProfiles.getValue()) + if (editingProfiles()) rearrangeHelper.attachToRecyclerView(recyclerView); } + public boolean editingProfiles() { + final Boolean b = editingProfiles.getValue(); + if (b == null) + return false; + return b; + } public void startEditingProfiles() { - if (editingProfiles.getValue()) + if (editingProfiles()) return; this.editingProfiles.setValue(true); rearrangeHelper.attachToRecyclerView(recyclerView); } public void stopEditingProfiles() { - if (!editingProfiles.getValue()) + if (!editingProfiles()) return; this.editingProfiles.setValue(false); rearrangeHelper.attachToRecyclerView(null); } public void flipEditingProfiles() { - if (editingProfiles.getValue()) + if (editingProfiles()) stopEditingProfiles(); else startEditingProfiles(); @@ -138,7 +143,7 @@ public class ProfilesRecyclerViewAdapter context.startActivity(intent); } private void onProfileRowClicked(View v) { - if (editingProfiles.getValue()) + if (editingProfiles()) return; MobileLedgerProfile profile = (MobileLedgerProfile) v.getTag(); if (profile == null) @@ -171,7 +176,7 @@ public class ProfilesRecyclerViewAdapter }); View.OnTouchListener dragStarter = (v, event) -> { - if (rearrangeHelper != null && editingProfiles.getValue()) { + if (rearrangeHelper != null && editingProfiles()) { rearrangeHelper.startDrag(holder); return true; } @@ -188,8 +193,8 @@ public class ProfilesRecyclerViewAdapter throw new AssertionError(); final MobileLedgerProfile profile = profiles.get(position); final MobileLedgerProfile currentProfile = Data.getProfile(); - debug("profiles", String.format(Locale.ENGLISH, "pos %d: %s, current: %s", position, - profile.getUuid(), currentProfile.getUuid())); +// debug("profiles", String.format(Locale.ENGLISH, "pos %d: %s, current: %s", position, +// profile.getUuid(), currentProfile.getUuid())); holder.itemView.setTag(profile); int hue = profile.getThemeHue(); @@ -207,7 +212,7 @@ public class ProfilesRecyclerViewAdapter final boolean sameProfile = currentProfile.equals(profile); holder.itemView.setBackground( sameProfile ? new ColorDrawable(Colors.tableRowDarkBG) : null); - if (editingProfiles.getValue()) { + if (editingProfiles()) { boolean wasHidden = holder.mEditButton.getVisibility() == View.GONE; holder.mRearrangeHandle.setVisibility(View.VISIBLE); holder.mEditButton.setVisibility(View.VISIBLE); @@ -235,7 +240,7 @@ public class ProfilesRecyclerViewAdapter final ArrayList profiles = Data.profiles.getValue(); return profiles != null ? profiles.size() : 0; } - class ProfileListViewHolder extends RecyclerView.ViewHolder { + static class ProfileListViewHolder extends RecyclerView.ViewHolder { final TextView mEditButton; final TextView mTitle, mColorTag; final LinearLayout tagAndHandleLayout;