X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fprofiles%2FProfilesRecyclerViewAdapter.java;h=b2b5cb7fe18f9ee86867b041ad134c1625c6270e;hb=0ce370cea3c5c980b6eeb14acf965188ae951f51;hp=bd5a3fec5996417aa4dd165f845f92537ba7be7d;hpb=ba1246d8bc73199acc00a4fbea6a2eed913a8ac3;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 bd5a3fec..b2b5cb7f 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 @@ -29,6 +29,13 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.lifecycle.MutableLiveData; +import androidx.recyclerview.widget.ItemTouchHelper; +import androidx.recyclerview.widget.RecyclerView; + import net.ktnx.mobileledger.R; import net.ktnx.mobileledger.model.Data; import net.ktnx.mobileledger.model.MobileLedgerProfile; @@ -40,23 +47,16 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Locale; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.constraintlayout.widget.ConstraintLayout; -import androidx.lifecycle.MutableLiveData; -import androidx.recyclerview.widget.ItemTouchHelper; -import androidx.recyclerview.widget.RecyclerView; - import static net.ktnx.mobileledger.utils.Logger.debug; public class ProfilesRecyclerViewAdapter extends RecyclerView.Adapter { + private static WeakReference instanceRef; private final View.OnClickListener mOnClickListener = view -> { MobileLedgerProfile profile = (MobileLedgerProfile) ((View) view.getParent()).getTag(); editProfile(view, profile); }; public MutableLiveData editingProfiles = new MutableLiveData<>(false); - private static WeakReference instanceRef; private RecyclerView recyclerView; private ItemTouchHelper rearrangeHelper; private boolean animationsEnabled = true; @@ -88,7 +88,8 @@ public class ProfilesRecyclerViewAdapter }; rearrangeHelper = new ItemTouchHelper(cb); } - public static @Nullable ProfilesRecyclerViewAdapter getInstance() { + public static @Nullable + ProfilesRecyclerViewAdapter getInstance() { return instanceRef.get(); } public void setAnimationsEnabled(boolean animationsEnabled) { @@ -135,6 +136,8 @@ public class ProfilesRecyclerViewAdapter if (profile == null) throw new IllegalStateException("Profile row without associated profile"); debug("profiles", "Setting profile to " + profile.getName()); + if (Data.getProfile() != profile) + Data.drawerOpen.setValue(false); Data.setCurrentProfile(profile); } @NonNull @@ -174,12 +177,12 @@ public class ProfilesRecyclerViewAdapter final ArrayList profiles = Data.profiles.getValue(); if (profiles == null) throw new AssertionError(); final MobileLedgerProfile profile = profiles.get(position); - final MobileLedgerProfile currentProfile = Data.profile.getValue(); + final MobileLedgerProfile currentProfile = Data.getProfile(); debug("profiles", String.format(Locale.ENGLISH, "pos %d: %s, current: %s", position, - profile.getUuid(), (currentProfile == null) ? "" : currentProfile.getUuid())); + profile.getUuid(), currentProfile.getUuid())); holder.itemView.setTag(profile); - int hue = profile.getThemeId(); + int hue = profile.getThemeHue(); if (hue == -1) holder.mColorTag .setBackgroundColor(Colors.getPrimaryColorForHue(Colors.DEFAULT_HUE_DEG)); else holder.mColorTag.setBackgroundColor(Colors.getPrimaryColorForHue(hue)); @@ -189,7 +192,7 @@ public class ProfilesRecyclerViewAdapter holder.mEditButton.setOnClickListener(mOnClickListener); - final boolean sameProfile = (currentProfile != null) && currentProfile.equals(profile); + final boolean sameProfile = currentProfile.equals(profile); holder.itemView .setBackground(sameProfile ? new ColorDrawable(Colors.tableRowDarkBG) : null); if (editingProfiles.getValue()) {