From 330d1aeda613b9d2a7ed26c0a4c86ffc69ede6d5 Mon Sep 17 00:00:00 2001 From: Hawkwood Glazier Date: Thu, 30 Mar 2023 11:23:17 +0000 Subject: [PATCH] Seperate weather/date visibility methods Bug: 274631066 Test: Manually checked visibility behavior unchanged Change-Id: I3a0dd8eb2635fafdb229d4f42fe8313c96a8bd29 --- .../KeyguardClockSwitchController.java | 26 ++++++++++------- .../KeyguardClockSwitchControllerTest.java | 28 +++++++++++++++++++ 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java index 9290220b86984..25d17928351a7 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java @@ -109,7 +109,7 @@ public class KeyguardClockSwitchController extends ViewController= 0) { @@ -487,16 +490,19 @@ public class KeyguardClockSwitchController extends ViewController { - if (mDateWeatherView != null) { - mDateWeatherView.setVisibility( - clockHasCustomWeatherDataDisplay() ? View.GONE : View.VISIBLE); - } - if (mWeatherView != null) { - mWeatherView.setVisibility( - mSmartspaceController.isWeatherEnabled() ? View.VISIBLE : View.GONE); - } + mDateWeatherView.setVisibility( + clockHasCustomWeatherDataDisplay() ? View.GONE : View.VISIBLE); + }); + } + } + + private void setWeatherVisibility() { + if (mWeatherView != null) { + mUiExecutor.execute(() -> { + mWeatherView.setVisibility( + mSmartspaceController.isWeatherEnabled() ? View.VISIBLE : View.GONE); }); } } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java index 2f627cb5d9d7f..b9f8dd9452937 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java @@ -48,8 +48,10 @@ import com.android.systemui.keyguard.KeyguardUnlockAnimationController; import com.android.systemui.plugins.ClockAnimations; import com.android.systemui.plugins.ClockController; import com.android.systemui.plugins.ClockEvents; +import com.android.systemui.plugins.ClockFaceConfig; import com.android.systemui.plugins.ClockFaceController; import com.android.systemui.plugins.ClockFaceEvents; +import com.android.systemui.plugins.ClockTickRate; import com.android.systemui.plugins.log.LogBuffer; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.shared.clocks.AnimatableClockView; @@ -185,6 +187,10 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { when(mClockController.getAnimations()).thenReturn(mClockAnimations); when(mClockRegistry.createCurrentClock()).thenReturn(mClockController); when(mClockEventController.getClock()).thenReturn(mClockController); + when(mSmallClockController.getConfig()) + .thenReturn(new ClockFaceConfig(ClockTickRate.PER_MINUTE, false)); + when(mLargeClockController.getConfig()) + .thenReturn(new ClockFaceConfig(ClockTickRate.PER_MINUTE, false)); mSliceView = new View(getContext()); when(mView.findViewById(R.id.keyguard_slice_view)).thenReturn(mSliceView); @@ -366,6 +372,28 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { assertEquals(View.VISIBLE, mFakeWeatherView.getVisibility()); } + @Test + public void testChangeClockDateWeatherEnabled_SetsDateWeatherViewVisibility() { + ArgumentCaptor listenerArgumentCaptor = + ArgumentCaptor.forClass(ClockRegistry.ClockChangeListener.class); + when(mSmartspaceController.isEnabled()).thenReturn(true); + when(mSmartspaceController.isDateWeatherDecoupled()).thenReturn(true); + when(mSmartspaceController.isWeatherEnabled()).thenReturn(true); + mController.init(); + mExecutor.runAllReady(); + assertEquals(View.VISIBLE, mFakeDateView.getVisibility()); + + when(mSmallClockController.getConfig()) + .thenReturn(new ClockFaceConfig(ClockTickRate.PER_MINUTE, true)); + when(mLargeClockController.getConfig()) + .thenReturn(new ClockFaceConfig(ClockTickRate.PER_MINUTE, true)); + verify(mClockRegistry).registerClockChangeListener(listenerArgumentCaptor.capture()); + listenerArgumentCaptor.getValue().onCurrentClockChanged(); + + mExecutor.runAllReady(); + assertEquals(View.GONE, mFakeDateView.getVisibility()); + } + @Test public void testGetClock_nullClock_returnsNull() { when(mClockEventController.getClock()).thenReturn(null);