mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-28 11:55:20 +01:00
Fixed runnable memory leaks
This commit is contained in:
@@ -24,12 +24,8 @@ import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public class FixedLinearLayout extends LinearLayout {
|
||||
public FixedLinearLayout(Context context) {
|
||||
super(context);
|
||||
@@ -56,46 +52,4 @@ public class FixedLinearLayout extends LinearLayout {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Runnable, Runnable> mapRunnable = null;
|
||||
|
||||
@NonNull
|
||||
private Map<Runnable, Runnable> getMapRunnable() {
|
||||
if (mapRunnable == null)
|
||||
mapRunnable = new WeakHashMap<>();
|
||||
return mapRunnable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean post(Runnable action) {
|
||||
Runnable wrapped = new RunnableEx("post") {
|
||||
@Override
|
||||
protected void delegate() {
|
||||
action.run();
|
||||
}
|
||||
};
|
||||
getMapRunnable().put(action, wrapped);
|
||||
return super.post(wrapped);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean postDelayed(Runnable action, long delayMillis) {
|
||||
Runnable wrapped = new RunnableEx("postDelayed") {
|
||||
@Override
|
||||
protected void delegate() {
|
||||
action.run();
|
||||
}
|
||||
};
|
||||
getMapRunnable().put(action, wrapped);
|
||||
return super.postDelayed(wrapped, delayMillis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeCallbacks(Runnable action) {
|
||||
Runnable wrapped = getMapRunnable().get(action);
|
||||
if (wrapped == null)
|
||||
return super.removeCallbacks(action);
|
||||
else
|
||||
return super.removeCallbacks(wrapped);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user