Refactoring

pull/194/merge
M66B 3 years ago
parent 6505d1411b
commit 11b6a370ec

@ -22,7 +22,6 @@ package eu.faircode.email;
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@ -46,7 +45,6 @@ import androidx.appcompat.widget.PopupMenu;
import androidx.constraintlayout.widget.Group;
import androidx.core.view.MenuCompat;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.Observer;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.DividerItemDecoration;
@ -276,18 +274,7 @@ public class FragmentAccounts extends FragmentBase {
}
});
animator = ObjectAnimator.ofFloat(fab, "alpha", 0.5f, 1.0f);
animator.setDuration(750L);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.setRepeatMode(ValueAnimator.REVERSE);
animator.addUpdateListener(new ObjectAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
return;
fab.setAlpha((float) animation.getAnimatedValue());
}
});
animator = Helper.getFabAnimator(fab, this);
// Initialize
FragmentDialogTheme.setBackground(getContext(), view, false);

@ -22,7 +22,6 @@ package eu.faircode.email;
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Canvas;
@ -37,7 +36,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.Observer;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.DividerItemDecoration;
@ -176,18 +174,7 @@ public class FragmentIdentities extends FragmentBase {
}
});
animator = ObjectAnimator.ofFloat(fab, "alpha", 0.5f, 1.0f);
animator.setDuration(750L);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.setRepeatMode(ValueAnimator.REVERSE);
animator.addUpdateListener(new ObjectAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
return;
fab.setAlpha((float) animation.getAnimatedValue());
}
});
animator = Helper.getFabAnimator(fab, this);
// Initialize
FragmentDialogTheme.setBackground(getContext(), view, false);

@ -23,6 +23,8 @@ import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
import static androidx.browser.customtabs.CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION;
import android.Manifest;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.KeyguardManager;
@ -631,6 +633,22 @@ public class Helper {
return context.getResources().getDimensionPixelSize(resid);
}
static ObjectAnimator getFabAnimator(View fab, LifecycleOwner owner) {
ObjectAnimator animator = ObjectAnimator.ofFloat(fab, "alpha", 0.5f, 1.0f);
animator.setDuration(750L);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.setRepeatMode(ValueAnimator.REVERSE);
animator.addUpdateListener(new ObjectAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
if (!owner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
return;
fab.setAlpha((float) animation.getAnimatedValue());
}
});
return animator;
}
static Intent getChooser(Context context, Intent intent) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
PackageManager pm = context.getPackageManager();

Loading…
Cancel
Save