Fix clock carousel crash when touching the empty UI
When there are no clocks, there is no need to show the clock carousel.It
also prevents from crashing when touchingthe empty clock UI.
Test: Manually tesed the crash does not happen
Bug: 392753230
Flag: EXEMPT bugfix
Change-Id: I234098113c420f13a8cd6cca7672c710213db02f
diff --git a/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt b/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt
index 0ed0362..27bc42c 100644
--- a/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt
+++ b/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt
@@ -30,6 +30,7 @@
import androidx.core.view.doOnPreDraw
import androidx.core.view.get
import androidx.core.view.isNotEmpty
+import androidx.core.view.isVisible
import com.android.customization.picker.clock.shared.ClockSize
import com.android.customization.picker.clock.ui.viewmodel.ClockCarouselItemViewModel
import com.android.systemui.plugins.clocks.ClockController
@@ -57,6 +58,7 @@
val clockCarousel = LayoutInflater.from(context).inflate(R.layout.clock_carousel, this)
carousel = clockCarousel.requireViewById(R.id.carousel)
motionLayout = clockCarousel.requireViewById(R.id.motion_container)
+ motionLayout.isVisible = false
motionLayout.contentDescription = context.getString(R.string.custom_clocks_label)
clockViewScale =
TypedValue().let {
@@ -133,6 +135,11 @@
onClockSelected: (clock: ClockCarouselItemViewModel) -> Unit,
isTwoPaneAndSmallWidth: Boolean,
) {
+ if (clocks.isEmpty()) {
+ // Hide the carousel if clock list is empty
+ motionLayout.isVisible = false
+ return
+ }
if (isTwoPaneAndSmallWidth) {
overrideScreenPreviewWidth()
}
@@ -311,6 +318,7 @@
) {}
}
)
+ motionLayout.isVisible = true
}
fun setSelectedClockIndex(index: Int) {