mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-26 01:36:55 +00:00
Clear activity views
This commit is contained in:
parent
1b0d80cc9b
commit
224fcdb2f4
4 changed files with 34 additions and 28 deletions
|
@ -20,7 +20,6 @@ package eu.faircode.email;
|
|||
*/
|
||||
|
||||
import android.Manifest;
|
||||
import android.animation.Animator;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
|
@ -60,14 +59,11 @@ import androidx.lifecycle.LifecycleObserver;
|
|||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.recyclerview.selection.SelectionTracker;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
@ -807,26 +803,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
|
|||
@Override
|
||||
public void onFragmentViewDestroyed(@NonNull FragmentManager fm, @NonNull Fragment f) {
|
||||
log(fm, f, "onFragmentViewDestroyed");
|
||||
try {
|
||||
for (Field field : f.getClass().getDeclaredFields()) {
|
||||
Class<?> type = field.getType();
|
||||
if (View.class.isAssignableFrom(type) ||
|
||||
Animator.class.isAssignableFrom(type) ||
|
||||
SelectionTracker.class.isAssignableFrom(type) ||
|
||||
SelectionTracker.SelectionPredicate.class.isAssignableFrom(type) ||
|
||||
RecyclerView.Adapter.class.isAssignableFrom(type)) {
|
||||
Log.i("Clearing " + f.getClass().getSimpleName() + ":" + field.getName());
|
||||
field.setAccessible(true);
|
||||
|
||||
if (Animator.class.isAssignableFrom(type))
|
||||
((Animator) field.get(f)).setTarget(null);
|
||||
|
||||
field.set(f, null);
|
||||
}
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
Helper.clearViews(f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1047,10 +1047,6 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (lastSnackbar != null) {
|
||||
lastSnackbar.setAction(null, null);
|
||||
lastSnackbar = null;
|
||||
}
|
||||
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
|
||||
lbm.unregisterReceiver(creceiver);
|
||||
super.onDestroy();
|
||||
|
|
|
@ -766,6 +766,8 @@ public class ApplicationEx extends Application
|
|||
@Override
|
||||
public void onActivityDestroyed(@NonNull Activity activity) {
|
||||
log(activity, "onActivityDestroyed");
|
||||
Helper.clearViews(activity);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,6 +23,7 @@ import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
|
|||
import static androidx.browser.customtabs.CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION;
|
||||
|
||||
import android.Manifest;
|
||||
import android.animation.Animator;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.app.Activity;
|
||||
|
@ -108,6 +109,7 @@ import androidx.lifecycle.LifecycleObserver;
|
|||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.recyclerview.selection.SelectionTracker;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
|
@ -1270,6 +1272,35 @@ public class Helper {
|
|||
return fragment.getClass().getName() + ":result:" + who;
|
||||
}
|
||||
|
||||
static void clearViews(Object instance) {
|
||||
try {
|
||||
for (Field field : instance.getClass().getDeclaredFields()) {
|
||||
Class<?> type = field.getType();
|
||||
if (View.class.isAssignableFrom(type) ||
|
||||
Animator.class.isAssignableFrom(type) ||
|
||||
Snackbar.class.isAssignableFrom(type) ||
|
||||
SelectionTracker.class.isAssignableFrom(type) ||
|
||||
SelectionTracker.SelectionPredicate.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) field.get(instance)).setTarget(null);
|
||||
|
||||
if (Snackbar.class.isAssignableFrom(type)) {
|
||||
((Snackbar) field.get(instance)).setAction(null, null);
|
||||
}
|
||||
|
||||
field.set(instance, null);
|
||||
}
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
}
|
||||
|
||||
// Graphics
|
||||
|
||||
static int dp2pixels(Context context, int dp) {
|
||||
|
|
Loading…
Reference in a new issue