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=bd5a3fec5996417aa4dd165f845f92537ba7be7d;hp=50fb32cf7d45acbecfa9e441f82d5c6308599451;hb=ba1246d8bc73199acc00a4fbea6a2eed913a8ac3;hpb=88e1dbc1a1427beb57611c24af255186c32c825e 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 50fb32cf..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() { @@ -71,7 +75,7 @@ public class ProfilesRecyclerViewAdapter @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) { final ArrayList profiles = Data.profiles.getValue(); - assert profiles != null; + if (profiles == null) throw new AssertionError(); Collections.swap(profiles, viewHolder.getAdapterPosition(), target.getAdapterPosition()); MobileLedgerProfile.storeProfilesOrder(); @@ -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; } @@ -165,11 +172,11 @@ public class ProfilesRecyclerViewAdapter @Override public void onBindViewHolder(@NonNull final ProfileListViewHolder holder, int position) { final ArrayList profiles = Data.profiles.getValue(); - assert profiles != null; + if (profiles == null) throw new AssertionError(); final MobileLedgerProfile profile = profiles.get(position); final MobileLedgerProfile currentProfile = Data.profile.getValue(); - debug("profiles", String.format(Locale.ENGLISH,"pos %d: %s, current: %s", position, profile.getUuid(), - (currentProfile == null) ? "" : currentProfile.getUuid())); + debug("profiles", String.format(Locale.ENGLISH, "pos %d: %s, current: %s", position, + profile.getUuid(), (currentProfile == null) ? "" : currentProfile.getUuid())); holder.itemView.setTag(profile); int hue = profile.getThemeId();