From ba1246d8bc73199acc00a4fbea6a2eed913a8ac3 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sun, 5 May 2019 18:21:53 +0300 Subject: [PATCH] ProfilesRecyclerViewAdapter as a weak singleton will be needed by the ProfileDetailsFragment when a profile is saved to let the adapter know of the change --- .../ui/profiles/ProfilesRecyclerViewAdapter.java | 7 +++++++ 1 file changed, 7 insertions(+) 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 eb3d0a0d..bd5a3fec 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 @@ -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 editingProfiles = new MutableLiveData<>(false); + private static WeakReference 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; } -- 2.39.2