From 53596362188d8f45043848816fa364c0c8c2d832 Mon Sep 17 00:00:00 2001 From: Thales Lima Date: Mon, 12 Jul 2021 12:35:46 +0100 Subject: [PATCH] sysui: update wallet card widths on configuration changes When opening a foldable the animation is still not perfect because the view is laid out before the carousel has a chance to set the new adapter. Fixes: 187516046 Test: manual testing Change-Id: If4cd56053ce7599260d8d3bb5dbbdce7236442e1 --- .../systemui/wallet/ui/WalletCardCarousel.java | 13 +++++++++++-- .../com/android/systemui/wallet/ui/WalletView.java | 6 +----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/wallet/ui/WalletCardCarousel.java b/packages/SystemUI/src/com/android/systemui/wallet/ui/WalletCardCarousel.java index 1e1b459382d7e..77fd2e8308736 100644 --- a/packages/SystemUI/src/com/android/systemui/wallet/ui/WalletCardCarousel.java +++ b/packages/SystemUI/src/com/android/systemui/wallet/ui/WalletCardCarousel.java @@ -189,6 +189,15 @@ public class WalletCardCarousel extends RecyclerView { return mCardHeightPx; } + /** + * Sets the adapter again in the RecyclerView, updating the ViewHolders children's layout. + * This is needed when changing the state of the device (eg fold/unfold) so the ViewHolders are + * recreated. + */ + void resetAdapter() { + setAdapter(mWalletCardCarouselAdapter); + } + /** * Returns true if the data set is changed. */ @@ -376,8 +385,8 @@ public class WalletCardCarousel extends RecyclerView { CardView cardView = viewHolder.mCardView; cardView.setRadius(mCornerRadiusPx); ViewGroup.LayoutParams layoutParams = cardView.getLayoutParams(); - layoutParams.width = mCardWidthPx; - layoutParams.height = mCardHeightPx; + layoutParams.width = getCardWidthPx(); + layoutParams.height = getCardHeightPx(); view.setTag(viewHolder); return viewHolder; } diff --git a/packages/SystemUI/src/com/android/systemui/wallet/ui/WalletView.java b/packages/SystemUI/src/com/android/systemui/wallet/ui/WalletView.java index 420f84abe0ddd..9b2702ff7bf27 100644 --- a/packages/SystemUI/src/com/android/systemui/wallet/ui/WalletView.java +++ b/packages/SystemUI/src/com/android/systemui/wallet/ui/WalletView.java @@ -99,17 +99,13 @@ public class WalletView extends FrameLayout implements WalletCardCarousel.OnCard mCardCarousel.setExpectedViewWidth(getWidth()); } - @Override - protected void onConfigurationChanged(Configuration newConfig) { - updateViewForOrientation(newConfig.orientation); - } - private void updateViewForOrientation(@Configuration.Orientation int orientation) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { renderViewPortrait(); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { renderViewLandscape(); } + mCardCarousel.resetAdapter(); // necessary to update cards width ViewGroup.LayoutParams params = mCardCarouselContainer.getLayoutParams(); if (params instanceof MarginLayoutParams) { ((MarginLayoutParams) params).topMargin =