Improved view clearing

pull/207/head
M66B 3 years ago
parent 6206194ece
commit 3c5d41cad3

@ -1275,17 +1275,27 @@ public class Helper {
static void clearViews(Object instance) { static void clearViews(Object instance) {
try { try {
String cname = instance.getClass().getSimpleName();
for (Field field : instance.getClass().getDeclaredFields()) { for (Field field : instance.getClass().getDeclaredFields()) {
String fname = cname + ":" + field.getName();
Class<?> ftype = field.getType(); Class<?> ftype = field.getType();
Class<?> type = (ftype.isArray() ? ftype.getComponentType() : ftype); Class<?> type = (ftype.isArray() ? ftype.getComponentType() : ftype);
if (type == null) {
Log.e(fname + "=null");
continue;
}
if (View.class.isAssignableFrom(type) || if (View.class.isAssignableFrom(type) ||
Animator.class.isAssignableFrom(type) || Animator.class.isAssignableFrom(type) ||
Snackbar.class.isAssignableFrom(type) || Snackbar.class.isAssignableFrom(type) ||
SelectionTracker.class.isAssignableFrom(type) || SelectionTracker.class.isAssignableFrom(type) ||
SelectionTracker.SelectionPredicate.class.isAssignableFrom(type) || SelectionTracker.SelectionPredicate.class.isAssignableFrom(type) ||
PagerAdapter.class.isAssignableFrom(type) || PagerAdapter.class.isAssignableFrom(type) ||
RecyclerView.Adapter.class.isAssignableFrom(type)) { RecyclerView.Adapter.class.isAssignableFrom(type))
Log.i("Clearing " + instance.getClass().getSimpleName() + ":" + field.getName()); try {
Log.i("Clearing " + fname);
field.setAccessible(true); field.setAccessible(true);
@ -1307,10 +1317,12 @@ public class Helper {
} }
field.set(instance, null); field.set(instance, null);
} catch (Throwable ex) {
Log.e(new Throwable(fname, ex));
} }
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Log.w(ex); Log.e(ex);
} }
} }

Loading…
Cancel
Save