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=f24f6f0cc10155aa2730f689dff0d491a4afa915;hp=8ee0dd96c696c5a299a52cdfe38a4b034f7b3a40;hb=0fc2ddc465cd9b9314ae336e69535020a96a7fbc;hpb=2c9601c763805df628328312468278404f448663 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 8ee0dd96..f24f6f0c 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 @@ -36,7 +36,9 @@ import net.ktnx.mobileledger.ui.activity.ProfileDetailActivity; import net.ktnx.mobileledger.utils.Colors; import net.ktnx.mobileledger.utils.ObservableValue; +import java.util.ArrayList; import java.util.Collections; +import java.util.Locale; import java.util.Observer; import androidx.annotation.NonNull; @@ -68,16 +70,12 @@ public class ProfilesRecyclerViewAdapter public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) { - Data.profiles.blockNotifications(); - try { - Collections.swap(Data.profiles, viewHolder.getAdapterPosition(), - target.getAdapterPosition()); - MobileLedgerProfile.storeProfilesOrder(); - notifyItemMoved(viewHolder.getAdapterPosition(), target.getAdapterPosition()); - } - finally { - Data.profiles.unblockNotifications(); - } + final ArrayList profiles = Data.profiles.getValue(); + assert profiles != null; + Collections.swap(profiles, viewHolder.getAdapterPosition(), + target.getAdapterPosition()); + MobileLedgerProfile.storeProfilesOrder(); + notifyItemMoved(viewHolder.getAdapterPosition(), target.getAdapterPosition()); return true; } @Override @@ -121,7 +119,7 @@ public class ProfilesRecyclerViewAdapter else startEditingProfiles(); } private void editProfile(View view, MobileLedgerProfile profile) { - int index = Data.profiles.indexOf(profile); + int index = Data.getProfileIndex(profile); Context context = view.getContext(); Intent intent = new Intent(context, ProfileDetailActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION); @@ -157,11 +155,6 @@ public class ProfilesRecyclerViewAdapter flipEditingProfiles(); return true; }); - Data.profile.addObserver((o, arg) -> { - MobileLedgerProfile myProfile = (MobileLedgerProfile) holder.itemView.getTag(); - final MobileLedgerProfile currentProfile = Data.profile.get(); - final boolean sameProfile = currentProfile.equals(myProfile); - }); View.OnTouchListener dragStarter = (v, event) -> { if (rearrangeHelper != null && editingProfiles.get()) { @@ -176,9 +169,11 @@ public class ProfilesRecyclerViewAdapter } @Override public void onBindViewHolder(@NonNull final ProfileListViewHolder holder, int position) { - final MobileLedgerProfile profile = Data.profiles.get(position); - final MobileLedgerProfile currentProfile = Data.profile.get(); - debug("profiles", String.format("pos %d: %s, current: %s", position, profile.getUuid(), + final ArrayList profiles = Data.profiles.getValue(); + assert profiles != null; + 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())); holder.itemView.setTag(profile); @@ -220,7 +215,8 @@ public class ProfilesRecyclerViewAdapter } @Override public int getItemCount() { - return Data.profiles.size(); + final ArrayList profiles = Data.profiles.getValue(); + return profiles != null ? profiles.size() : 0; } public boolean isEditingProfiles() { return editingProfiles.get();