From: Damyan Ivanov Date: Sun, 5 May 2019 15:21:53 +0000 (+0300) Subject: ProfilesRecyclerViewAdapter as a weak singleton X-Git-Tag: v0.10.0~11 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=ba1246d8bc73199acc00a4fbea6a2eed913a8ac3;p=mobile-ledger.git ProfilesRecyclerViewAdapter as a weak singleton will be needed by the ProfileDetailsFragment when a profile is saved to let the adapter know of the change --- 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; }