mirror of https://github.com/M66B/FairEmail.git
Clear fragment animators
This commit is contained in:
parent
7e727f8be1
commit
a001d0f566
|
@ -20,6 +20,7 @@ package eu.faircode.email;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
|
import android.animation.Animator;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -809,6 +810,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
|
||||||
for (Field field : f.getClass().getDeclaredFields()) {
|
for (Field field : f.getClass().getDeclaredFields()) {
|
||||||
Class<?> type = field.getType();
|
Class<?> type = field.getType();
|
||||||
if (View.class.isAssignableFrom(type) ||
|
if (View.class.isAssignableFrom(type) ||
|
||||||
|
Animator.class.isAssignableFrom(type) ||
|
||||||
RecyclerView.Adapter.class.isAssignableFrom(type)) {
|
RecyclerView.Adapter.class.isAssignableFrom(type)) {
|
||||||
Log.i("Clearing " + f.getClass().getSimpleName() + ":" + field.getName());
|
Log.i("Clearing " + f.getClass().getSimpleName() + ":" + field.getName());
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
|
|
|
@ -330,11 +330,11 @@ public class FragmentAccounts extends FragmentBase {
|
||||||
|
|
||||||
if (accounts.size() == 0) {
|
if (accounts.size() == 0) {
|
||||||
fab.setCustomSize(Helper.dp2pixels(context, 2 * 56));
|
fab.setCustomSize(Helper.dp2pixels(context, 2 * 56));
|
||||||
if (!animator.isStarted())
|
if (animator != null && !animator.isStarted())
|
||||||
animator.start();
|
animator.start();
|
||||||
} else {
|
} else {
|
||||||
fab.clearCustomSize();
|
fab.clearCustomSize();
|
||||||
if (animator.isStarted())
|
if (animator != null && animator.isStarted())
|
||||||
animator.end();
|
animator.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,11 +211,11 @@ public class FragmentIdentities extends FragmentBase {
|
||||||
|
|
||||||
if (identities.size() == 0) {
|
if (identities.size() == 0) {
|
||||||
fab.setCustomSize(Helper.dp2pixels(context, 2 * 56));
|
fab.setCustomSize(Helper.dp2pixels(context, 2 * 56));
|
||||||
if (!animator.isStarted())
|
if (animator != null && !animator.isStarted())
|
||||||
animator.start();
|
animator.start();
|
||||||
} else {
|
} else {
|
||||||
fab.clearCustomSize();
|
fab.clearCustomSize();
|
||||||
if (animator.isStarted())
|
if (animator != null && animator.isStarted())
|
||||||
animator.end();
|
animator.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1446,16 +1446,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||||
criteria.with_notes ||
|
criteria.with_notes ||
|
||||||
criteria.with_types != null) {
|
criteria.with_types != null) {
|
||||||
fabSearch.hide();
|
fabSearch.hide();
|
||||||
if (animator.isStarted())
|
if (animator != null && animator.isStarted())
|
||||||
animator.end();
|
animator.end();
|
||||||
} else {
|
} else {
|
||||||
fabSearch.show();
|
fabSearch.show();
|
||||||
if (!animator.isStarted())
|
if (animator != null && !animator.isStarted())
|
||||||
animator.start();
|
animator.start();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fabSearch.hide();
|
fabSearch.hide();
|
||||||
if (animator.isStarted())
|
if (animator != null && animator.isStarted())
|
||||||
animator.end();
|
animator.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -640,11 +640,7 @@ public class Helper {
|
||||||
}
|
}
|
||||||
|
|
||||||
static ObjectAnimator getFabAnimator(View fab, LifecycleOwner owner) {
|
static ObjectAnimator getFabAnimator(View fab, LifecycleOwner owner) {
|
||||||
ObjectAnimator animator = ObjectAnimator.ofFloat(fab, "alpha", 0.9f, 1.0f);
|
ObjectAnimator.AnimatorUpdateListener listener = new ObjectAnimator.AnimatorUpdateListener() {
|
||||||
animator.setDuration(750L);
|
|
||||||
animator.setRepeatCount(ValueAnimator.INFINITE);
|
|
||||||
animator.setRepeatMode(ValueAnimator.REVERSE);
|
|
||||||
animator.addUpdateListener(new ObjectAnimator.AnimatorUpdateListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationUpdate(ValueAnimator animation) {
|
public void onAnimationUpdate(ValueAnimator animation) {
|
||||||
if (!owner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
|
if (!owner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
|
||||||
|
@ -652,7 +648,27 @@ public class Helper {
|
||||||
fab.setScaleX((float) animation.getAnimatedValue());
|
fab.setScaleX((float) animation.getAnimatedValue());
|
||||||
fab.setScaleY((float) animation.getAnimatedValue());
|
fab.setScaleY((float) animation.getAnimatedValue());
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ObjectAnimator animator = ObjectAnimator.ofFloat(fab, "alpha", 0.9f, 1.0f);
|
||||||
|
animator.setDuration(750L);
|
||||||
|
animator.setRepeatCount(ValueAnimator.INFINITE);
|
||||||
|
animator.setRepeatMode(ValueAnimator.REVERSE);
|
||||||
|
animator.addUpdateListener(listener);
|
||||||
|
|
||||||
|
owner.getLifecycle().addObserver(new LifecycleObserver() {
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||||
|
public void onDestroyed() {
|
||||||
|
try {
|
||||||
|
animator.removeUpdateListener(listener);
|
||||||
|
fab.setAlpha(1.0f);
|
||||||
|
owner.getLifecycle().removeObserver(this);
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
Log.e(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return animator;
|
return animator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue