From a41d2a2f73c148f98260ee8de6cd769c3cb9ddcd Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sun, 4 Jul 2021 02:52:37 +0900 Subject: [PATCH] Make comments to animation follow disable transition preference --- .../comments/CommentsViewerFragment.java | 18 ++++++++++++------ .../fragments/comments/RepliesFragment.java | 9 +++++++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/comments/CommentsViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/comments/CommentsViewerFragment.java index 0b5dbc82..6bc8643c 100644 --- a/app/src/main/java/awais/instagrabber/fragments/comments/CommentsViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/comments/CommentsViewerFragment.java @@ -15,6 +15,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentTransaction; import androidx.lifecycle.LiveData; import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; @@ -34,9 +35,11 @@ import awais.instagrabber.R; import awais.instagrabber.adapters.CommentsAdapter; import awais.instagrabber.customviews.helpers.RecyclerLazyLoader; import awais.instagrabber.databinding.FragmentCommentsBinding; +import awais.instagrabber.fragments.settings.PreferenceKeys; import awais.instagrabber.models.Comment; import awais.instagrabber.models.Resource; import awais.instagrabber.utils.TextUtils; +import awais.instagrabber.utils.Utils; import awais.instagrabber.viewmodels.AppStateViewModel; import awais.instagrabber.viewmodels.CommentsViewerViewModel; @@ -78,7 +81,7 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment { @NonNull @Override public Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) { - return new BottomSheetDialog(getContext(), getTheme()) { + return new BottomSheetDialog(requireContext(), getTheme()) { @Override public void onBackPressed() { if (showingReplies) { @@ -205,12 +208,15 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment { viewModel, (comment, focusInput) -> { if (comment == null) return null; + final boolean disableTransition = Utils.settingsHelper.getBoolean(PreferenceKeys.PREF_DISABLE_SCREEN_TRANSITIONS); final RepliesFragment repliesFragment = RepliesFragment.newInstance(comment, focusInput != null && focusInput); - getChildFragmentManager().beginTransaction() - .setCustomAnimations(R.anim.slide_left, R.anim.slide_right, 0, R.anim.slide_right) - .add(R.id.replies_container_view, repliesFragment) - .addToBackStack(RepliesFragment.TAG) - .commit(); + final FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); + if (!disableTransition) { + transaction.setCustomAnimations(R.anim.slide_left, R.anim.slide_right, 0, R.anim.slide_right); + } + transaction.add(R.id.replies_container_view, repliesFragment) + .addToBackStack(RepliesFragment.TAG) + .commit(); showingReplies = true; return null; })); diff --git a/app/src/main/java/awais/instagrabber/fragments/comments/RepliesFragment.java b/app/src/main/java/awais/instagrabber/fragments/comments/RepliesFragment.java index ebeb89fa..bbb12a7e 100644 --- a/app/src/main/java/awais/instagrabber/fragments/comments/RepliesFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/comments/RepliesFragment.java @@ -83,8 +83,13 @@ public class RepliesFragment extends Fragment { @Override public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) { - if (!enter || nextAnim == 0) { - return super.onCreateAnimation(transit, enter, nextAnim); + if (!enter) { + return super.onCreateAnimation(transit, false, nextAnim); + } + if (nextAnim == 0) { + setupList(); + setupObservers(); + return super.onCreateAnimation(transit, true, nextAnim); } final Animation animation = AnimationUtils.loadAnimation(getContext(), nextAnim); animation.setAnimationListener(new Animation.AnimationListener() {