From 66d988506c71e9020d958219d06185a49d4396a2 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 17 Apr 2022 12:14:39 +0200 Subject: [PATCH] Improved clearing views --- .../main/java/eu/faircode/email/Helper.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index d1121fbec4..09495994b9 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -111,6 +111,7 @@ import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.PreferenceManager; import androidx.recyclerview.selection.SelectionTracker; import androidx.recyclerview.widget.RecyclerView; +import androidx.viewpager.widget.PagerAdapter; import com.google.android.material.bottomnavigation.BottomNavigationView; import com.google.android.material.snackbar.Snackbar; @@ -1275,27 +1276,31 @@ public class Helper { static void clearViews(Object instance) { try { for (Field field : instance.getClass().getDeclaredFields()) { - Class type = field.getType(); + Class ftype = field.getType(); + Class type = (ftype.isArray() ? ftype.getComponentType() : ftype); if (View.class.isAssignableFrom(type) || Animator.class.isAssignableFrom(type) || Snackbar.class.isAssignableFrom(type) || SelectionTracker.class.isAssignableFrom(type) || SelectionTracker.SelectionPredicate.class.isAssignableFrom(type) || + PagerAdapter.class.isAssignableFrom(type) || RecyclerView.Adapter.class.isAssignableFrom(type)) { Log.i("Clearing " + instance.getClass().getSimpleName() + ":" + field.getName()); field.setAccessible(true); - if (Animator.class.isAssignableFrom(type)) { - Animator animator = (Animator) field.get(instance); - if (animator != null) - animator.setTarget(null); - } + if (!ftype.isArray()) { + if (Animator.class.isAssignableFrom(type)) { + Animator animator = (Animator) field.get(instance); + if (animator != null) + animator.setTarget(null); + } - if (Snackbar.class.isAssignableFrom(type)) { - Snackbar snackbar = (Snackbar) field.get(instance); - if (snackbar != null) - snackbar.setAction(null, null); + if (Snackbar.class.isAssignableFrom(type)) { + Snackbar snackbar = (Snackbar) field.get(instance); + if (snackbar != null) + snackbar.setAction(null, null); + } } field.set(instance, null);