From b47422fd758896c7e3371bcf59ec6fe9a262e980 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sat, 26 Sep 2020 10:10:51 +0800 Subject: Animate layout changes in item_post_compact.xml. --- .../Adapter/PostRecyclerViewAdapter.java | 25 ++++++++++++++++---- .../infinityforreddit/Fragment/PostFragment.java | 27 ++++++++++++++++++++++ app/src/main/res/layout/item_post_compact.xml | 3 ++- 3 files changed, 49 insertions(+), 6 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index 772040b6..32f3eb84 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -16,6 +16,7 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; @@ -782,9 +783,15 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { if (mLongPressToHideToolbarInCompactLayout) { - if (bottomConstraintLayout.getVisibility() == View.VISIBLE) { - bottomConstraintLayout.setVisibility(View.GONE); + if (bottomConstraintLayout.getLayoutParams().height == 0) { + ViewGroup.LayoutParams params = (LinearLayout.LayoutParams) bottomConstraintLayout.getLayoutParams(); + params.height = LinearLayout.LayoutParams.WRAP_CONTENT; + bottomConstraintLayout.setLayoutParams(params); + mCallback.delayTransition(); } else { - bottomConstraintLayout.setVisibility(View.VISIBLE); + mCallback.delayTransition(); + ViewGroup.LayoutParams params = (LinearLayout.LayoutParams) bottomConstraintLayout.getLayoutParams(); + params.height = 0; + bottomConstraintLayout.setLayoutParams(params); } } return true; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java index fcf7db71..d5b638b3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -42,6 +42,8 @@ import androidx.recyclerview.widget.LinearSmoothScroller; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.StaggeredGridLayoutManager; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import androidx.transition.AutoTransition; +import androidx.transition.TransitionManager; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; @@ -441,6 +443,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { maxPosition = position; } } + + @Override + public void delayTransition() { + TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition()); + } }); mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, @@ -488,6 +495,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { maxPosition = position; } } + + @Override + public void delayTransition() { + TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition()); + } }); mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, @@ -537,6 +549,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { maxPosition = position; } } + + @Override + public void delayTransition() { + TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition()); + } }); mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, @@ -585,6 +602,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { maxPosition = position; } } + + @Override + public void delayTransition() { + TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition()); + } }); mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, @@ -624,6 +646,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { maxPosition = position; } } + + @Override + public void delayTransition() { + TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition()); + } }); mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mOauthRetrofit, accessToken, diff --git a/app/src/main/res/layout/item_post_compact.xml b/app/src/main/res/layout/item_post_compact.xml index 54f1f34d..36dcfc60 100644 --- a/app/src/main/res/layout/item_post_compact.xml +++ b/app/src/main/res/layout/item_post_compact.xml @@ -3,7 +3,8 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="vertical"> + android:orientation="vertical" + android:animateLayoutChanges="true">