From 16abfeeff0eb482482fb60ac8ab6d01d75942531 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Mon, 8 Aug 2022 20:20:45 +0700 Subject: [PATCH] Glance widget fixes (#7706) * Fix glance failing when there's too much children * Adjust cover error placeholder --- .../glance/UpdatesGridGlanceWidget.kt | 14 +++++------ .../res/drawable/appwidget_cover_error.xml | 24 +++++++++++++++++++ .../drawable/appwidget_cover_placeholder.xml | 9 ------- 3 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 app/src/main/res/drawable/appwidget_cover_error.xml delete mode 100644 app/src/main/res/drawable/appwidget_cover_placeholder.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/glance/UpdatesGridGlanceWidget.kt b/app/src/main/java/eu/kanade/tachiyomi/glance/UpdatesGridGlanceWidget.kt index 816cfefa7..4d334448d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/glance/UpdatesGridGlanceWidget.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/glance/UpdatesGridGlanceWidget.kt @@ -164,8 +164,7 @@ class UpdatesGridGlanceWidget : GlanceAppWidget() { Box( modifier = modifier .size(width = CoverWidth, height = CoverHeight) - .appWidgetInnerRadius() - .background(ColorProvider(R.color.appwidget_surface_variant)), + .appWidgetInnerRadius(), ) { if (cover != null) { Image( @@ -179,11 +178,9 @@ class UpdatesGridGlanceWidget : GlanceAppWidget() { } else { // Enjoy placeholder Image( - provider = ImageProvider(R.drawable.appwidget_cover_placeholder), + provider = ImageProvider(R.drawable.appwidget_cover_error), contentDescription = null, - modifier = GlanceModifier - .fillMaxSize() - .padding(4.dp), + modifier = GlanceModifier.fillMaxSize(), contentScale = ContentScale.Crop, ) } @@ -281,7 +278,8 @@ private val ContainerModifier = GlanceModifier */ private fun DpSize.calculateRowAndColumnCount(): Pair { // Hack: Size provided by Glance manager is not reliable so take at least 1 row and 1 column - val rowCount = (height.value / 95).toInt().coerceAtLeast(1) - val columnCount = (width.value / 64).toInt().coerceAtLeast(1) + // Set max to 10 children each direction because of Glance limitation + val rowCount = (height.value / 95).toInt().coerceIn(1, 10) + val columnCount = (width.value / 64).toInt().coerceIn(1, 10) return Pair(rowCount, columnCount) } diff --git a/app/src/main/res/drawable/appwidget_cover_error.xml b/app/src/main/res/drawable/appwidget_cover_error.xml new file mode 100644 index 000000000..355d4bd0c --- /dev/null +++ b/app/src/main/res/drawable/appwidget_cover_error.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/appwidget_cover_placeholder.xml b/app/src/main/res/drawable/appwidget_cover_placeholder.xml deleted file mode 100644 index c6489cc23..000000000 --- a/app/src/main/res/drawable/appwidget_cover_placeholder.xml +++ /dev/null @@ -1,9 +0,0 @@ - - -