X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fprofiles%2FProfilesRecyclerViewAdapter.java;h=974c979322f79ff0e2f7c74aab3dc07e8cd93d2f;hp=bd5a3fec5996417aa4dd165f845f92537ba7be7d;hb=5fb830346325e20be596a09118d377b26f09779b;hpb=ba1246d8bc73199acc00a4fbea6a2eed913a8ac3 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..974c9793 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.profile.getValue() != profile ) + Data.drawerOpen.setValue(false); Data.setCurrentProfile(profile); } @NonNull @@ -179,7 +182,7 @@ public class ProfilesRecyclerViewAdapter profile.getUuid(), (currentProfile == null) ? "" : 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));