1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 14:47:29 +00:00

Make comments to animation follow disable transition preference

This commit is contained in:
Ammar Githam 2021-07-04 02:52:37 +09:00
parent 97490d5c0b
commit a41d2a2f73
2 changed files with 19 additions and 8 deletions

View File

@ -15,6 +15,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
@ -34,9 +35,11 @@ import awais.instagrabber.R;
import awais.instagrabber.adapters.CommentsAdapter; import awais.instagrabber.adapters.CommentsAdapter;
import awais.instagrabber.customviews.helpers.RecyclerLazyLoader; import awais.instagrabber.customviews.helpers.RecyclerLazyLoader;
import awais.instagrabber.databinding.FragmentCommentsBinding; import awais.instagrabber.databinding.FragmentCommentsBinding;
import awais.instagrabber.fragments.settings.PreferenceKeys;
import awais.instagrabber.models.Comment; import awais.instagrabber.models.Comment;
import awais.instagrabber.models.Resource; import awais.instagrabber.models.Resource;
import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils;
import awais.instagrabber.viewmodels.AppStateViewModel; import awais.instagrabber.viewmodels.AppStateViewModel;
import awais.instagrabber.viewmodels.CommentsViewerViewModel; import awais.instagrabber.viewmodels.CommentsViewerViewModel;
@ -78,7 +81,7 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment {
@NonNull @NonNull
@Override @Override
public Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) { public Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) {
return new BottomSheetDialog(getContext(), getTheme()) { return new BottomSheetDialog(requireContext(), getTheme()) {
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (showingReplies) { if (showingReplies) {
@ -205,12 +208,15 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment {
viewModel, viewModel,
(comment, focusInput) -> { (comment, focusInput) -> {
if (comment == null) return null; 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); final RepliesFragment repliesFragment = RepliesFragment.newInstance(comment, focusInput != null && focusInput);
getChildFragmentManager().beginTransaction() final FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
.setCustomAnimations(R.anim.slide_left, R.anim.slide_right, 0, R.anim.slide_right) if (!disableTransition) {
.add(R.id.replies_container_view, repliesFragment) transaction.setCustomAnimations(R.anim.slide_left, R.anim.slide_right, 0, R.anim.slide_right);
.addToBackStack(RepliesFragment.TAG) }
.commit(); transaction.add(R.id.replies_container_view, repliesFragment)
.addToBackStack(RepliesFragment.TAG)
.commit();
showingReplies = true; showingReplies = true;
return null; return null;
})); }));

View File

@ -83,8 +83,13 @@ public class RepliesFragment extends Fragment {
@Override @Override
public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) { public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
if (!enter || nextAnim == 0) { if (!enter) {
return super.onCreateAnimation(transit, enter, nextAnim); return super.onCreateAnimation(transit, false, nextAnim);
}
if (nextAnim == 0) {
setupList();
setupObservers();
return super.onCreateAnimation(transit, true, nextAnim);
} }
final Animation animation = AnimationUtils.loadAnimation(getContext(), nextAnim); final Animation animation = AnimationUtils.loadAnimation(getContext(), nextAnim);
animation.setAnimationListener(new Animation.AnimationListener() { animation.setAnimationListener(new Animation.AnimationListener() {