From 7ba116584be9a635e761ce0cf37262d93b72fa29 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 12 Jan 2021 13:40:53 -0500 Subject: [PATCH] fab prep --- .../instagrabber/animations/FabAnimation.java | 61 +++++++++++++++++++ .../fragments/main/FeedFragment.java | 20 ++++++ 2 files changed, 81 insertions(+) create mode 100644 app/src/main/java/awais/instagrabber/animations/FabAnimation.java diff --git a/app/src/main/java/awais/instagrabber/animations/FabAnimation.java b/app/src/main/java/awais/instagrabber/animations/FabAnimation.java new file mode 100644 index 00000000..1df54dcc --- /dev/null +++ b/app/src/main/java/awais/instagrabber/animations/FabAnimation.java @@ -0,0 +1,61 @@ +package awais.instagrabber.animations; + +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.view.View; + +// https://medium.com/better-programming/animated-fab-button-with-more-options-2dcf7118fff6 + +public class FabAnimation { + public static boolean rotateFab(final View v, boolean rotate) { + v.animate().setDuration(200) + .setListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + super.onAnimationEnd(animation); + } + }) + .rotation(rotate ? 135f : 0f); + return rotate; + } + + public static void showIn(final View v) { + v.setVisibility(View.VISIBLE); + v.setAlpha(0f); + v.setTranslationY(v.getHeight()); + v.animate() + .setDuration(200) + .translationY(0) + .setListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + super.onAnimationEnd(animation); + } + }) + .alpha(1f) + .start(); + } + + public static void showOut(final View v) { + v.setVisibility(View.VISIBLE); + v.setAlpha(1f); + v.setTranslationY(0); + v.animate() + .setDuration(200) + .translationY(v.getHeight()) + .setListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + v.setVisibility(View.GONE); + super.onAnimationEnd(animation); + } + }).alpha(0f) + .start(); + } + + public static void init(final View v) { + v.setVisibility(View.GONE); + v.setTranslationY(v.getHeight()); + v.setAlpha(0f); + } +} diff --git a/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java index b9c6d465..94a7c046 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java @@ -39,6 +39,7 @@ import awais.instagrabber.R; import awais.instagrabber.activities.MainActivity; import awais.instagrabber.adapters.FeedAdapterV2; import awais.instagrabber.adapters.FeedStoriesAdapter; +import awais.instagrabber.animations.FabAnimation; import awais.instagrabber.asyncs.FeedPostFetchService; import awais.instagrabber.customviews.PrimaryActionModeCallback; import awais.instagrabber.databinding.FragmentFeedBinding; @@ -68,6 +69,7 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre private FragmentFeedBinding binding; private StoriesService storiesService; private boolean shouldRefresh = true; + private final boolean isRotate = false; private FeedStoriesViewModel feedStoriesViewModel; private boolean storiesFetching; private ActionMode actionMode; @@ -282,6 +284,24 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { if (!shouldRefresh) return; binding.feedSwipeRefreshLayout.setOnRefreshListener(this); + /* + FabAnimation.init(binding.fabCamera); + FabAnimation.init(binding.fabStory); + binding.fabAdd.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + isRotate = FabAnimation.rotateFab(v, !isRotate); + if (isRotate) { + FabAnimation.showIn(binding.fabCamera); + FabAnimation.showIn(binding.fabStory); + } + else { + FabAnimation.showOut(binding.fabCamera); + FabAnimation.showOut(binding.fabStory); + } + } + }); + */ setupFeedStories(); setupFeed(); shouldRefresh = false;