]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java
control/save state of drawer being open via a MutableLiveData instance
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / profiles / ProfilesRecyclerViewAdapter.java
index bd5a3fec5996417aa4dd165f845f92537ba7be7d..974c979322f79ff0e2f7c74aab3dc07e8cd93d2f 100644 (file)
@@ -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<ProfilesRecyclerViewAdapter.ProfileListViewHolder> {
+    private static WeakReference<ProfilesRecyclerViewAdapter> instanceRef;
     private final View.OnClickListener mOnClickListener = view -> {
         MobileLedgerProfile profile = (MobileLedgerProfile) ((View) view.getParent()).getTag();
         editProfile(view, profile);
     };
     public MutableLiveData<Boolean> editingProfiles = new MutableLiveData<>(false);
-    private static WeakReference<ProfilesRecyclerViewAdapter> 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) ? "<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));