]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java
replace assertions with good old if()
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / profiles / ProfilesRecyclerViewAdapter.java
index 80e0dcdcbcedfd23132012d333701c4eb0d22be7..eb3d0a0d115fd15ea8dc41697157e13e5d0541ab 100644 (file)
@@ -56,6 +56,7 @@ public class ProfilesRecyclerViewAdapter
     public MutableLiveData<Boolean> editingProfiles = new MutableLiveData<>(false);
     private RecyclerView recyclerView;
     private ItemTouchHelper rearrangeHelper;
+    private boolean animationsEnabled = true;
     public ProfilesRecyclerViewAdapter() {
         debug("flow", "ProfilesRecyclerViewAdapter.new()");
 
@@ -70,7 +71,7 @@ public class ProfilesRecyclerViewAdapter
                                   @NonNull RecyclerView.ViewHolder viewHolder,
                                   @NonNull RecyclerView.ViewHolder target) {
                 final ArrayList<MobileLedgerProfile> profiles = Data.profiles.getValue();
-                assert profiles != null;
+                if (profiles == null) throw new AssertionError();
                 Collections.swap(profiles, viewHolder.getAdapterPosition(),
                         target.getAdapterPosition());
                 MobileLedgerProfile.storeProfilesOrder();
@@ -83,6 +84,9 @@ public class ProfilesRecyclerViewAdapter
         };
         rearrangeHelper = new ItemTouchHelper(cb);
     }
+    public void setAnimationsEnabled(boolean animationsEnabled) {
+        this.animationsEnabled = animationsEnabled;
+    }
     @Override
     public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) {
         rearrangeHelper.attachToRecyclerView(null);
@@ -98,13 +102,11 @@ public class ProfilesRecyclerViewAdapter
     public void startEditingProfiles() {
         if (editingProfiles.getValue()) return;
         this.editingProfiles.setValue(true);
-        notifyDataSetChanged();
         rearrangeHelper.attachToRecyclerView(recyclerView);
     }
     public void stopEditingProfiles() {
         if (!editingProfiles.getValue()) return;
         this.editingProfiles.setValue(false);
-        notifyDataSetChanged();
         rearrangeHelper.attachToRecyclerView(null);
     }
     public void flipEditingProfiles() {
@@ -163,11 +165,11 @@ public class ProfilesRecyclerViewAdapter
     @Override
     public void onBindViewHolder(@NonNull final ProfileListViewHolder holder, int position) {
         final ArrayList<MobileLedgerProfile> 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) ? "<NULL>" : currentProfile.getUuid()));
+        debug("profiles", String.format(Locale.ENGLISH, "pos %d: %s, current: %s", position,
+                profile.getUuid(), (currentProfile == null) ? "<NULL>" : currentProfile.getUuid()));
         holder.itemView.setTag(profile);
 
         int hue = profile.getThemeId();
@@ -187,7 +189,7 @@ public class ProfilesRecyclerViewAdapter
             boolean wasHidden = holder.mEditButton.getVisibility() == View.GONE;
             holder.mRearrangeHandle.setVisibility(View.VISIBLE);
             holder.mEditButton.setVisibility(View.VISIBLE);
-            if (wasHidden) {
+            if (wasHidden && animationsEnabled) {
                 Animation a = AnimationUtils
                         .loadAnimation(holder.mRearrangeHandle.getContext(), R.anim.fade_in);
                 holder.mRearrangeHandle.startAnimation(a);
@@ -198,7 +200,7 @@ public class ProfilesRecyclerViewAdapter
             boolean wasShown = holder.mEditButton.getVisibility() == View.VISIBLE;
             holder.mRearrangeHandle.setVisibility(View.INVISIBLE);
             holder.mEditButton.setVisibility(View.GONE);
-            if (wasShown) {
+            if (wasShown && animationsEnabled) {
                 Animation a = AnimationUtils
                         .loadAnimation(holder.mRearrangeHandle.getContext(), R.anim.fade_out);
                 holder.mRearrangeHandle.startAnimation(a);