]> git.ktnx.net Git - mobile-ledger.git/commitdiff
ProfilesRecyclerViewAdapter as a weak singleton
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 5 May 2019 15:21:53 +0000 (18:21 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 5 May 2019 15:21:53 +0000 (18:21 +0300)
will be needed by the ProfileDetailsFragment when a profile is saved to let
the adapter know of the change

app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java

index eb3d0a0d115fd15ea8dc41697157e13e5d0541ab..bd5a3fec5996417aa4dd165f845f92537ba7be7d 100644 (file)
@@ -35,11 +35,13 @@ import net.ktnx.mobileledger.model.MobileLedgerProfile;
 import net.ktnx.mobileledger.ui.activity.ProfileDetailActivity;
 import net.ktnx.mobileledger.utils.Colors;
 
+import java.lang.ref.WeakReference;
 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;
@@ -54,10 +56,12 @@ public class ProfilesRecyclerViewAdapter
         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;
     public ProfilesRecyclerViewAdapter() {
+        instanceRef = new WeakReference<>(this);
         debug("flow", "ProfilesRecyclerViewAdapter.new()");
 
         ItemTouchHelper.Callback cb = new ItemTouchHelper.Callback() {
@@ -84,6 +88,9 @@ public class ProfilesRecyclerViewAdapter
         };
         rearrangeHelper = new ItemTouchHelper(cb);
     }
+    public static @Nullable ProfilesRecyclerViewAdapter getInstance() {
+        return instanceRef.get();
+    }
     public void setAnimationsEnabled(boolean animationsEnabled) {
         this.animationsEnabled = animationsEnabled;
     }