Glance widget fixes (#7706)

* Fix glance failing when there's too much children

* Adjust cover error placeholder
This commit is contained in:
Ivan Iskandar 2022-08-08 20:20:45 +07:00 committed by GitHub
parent 3bc6b1e202
commit 16abfeeff0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 17 deletions

View File

@ -164,8 +164,7 @@ class UpdatesGridGlanceWidget : GlanceAppWidget() {
Box( Box(
modifier = modifier modifier = modifier
.size(width = CoverWidth, height = CoverHeight) .size(width = CoverWidth, height = CoverHeight)
.appWidgetInnerRadius() .appWidgetInnerRadius(),
.background(ColorProvider(R.color.appwidget_surface_variant)),
) { ) {
if (cover != null) { if (cover != null) {
Image( Image(
@ -179,11 +178,9 @@ class UpdatesGridGlanceWidget : GlanceAppWidget() {
} else { } else {
// Enjoy placeholder // Enjoy placeholder
Image( Image(
provider = ImageProvider(R.drawable.appwidget_cover_placeholder), provider = ImageProvider(R.drawable.appwidget_cover_error),
contentDescription = null, contentDescription = null,
modifier = GlanceModifier modifier = GlanceModifier.fillMaxSize(),
.fillMaxSize()
.padding(4.dp),
contentScale = ContentScale.Crop, contentScale = ContentScale.Crop,
) )
} }
@ -281,7 +278,8 @@ private val ContainerModifier = GlanceModifier
*/ */
private fun DpSize.calculateRowAndColumnCount(): Pair<Int, Int> { private fun DpSize.calculateRowAndColumnCount(): Pair<Int, Int> {
// Hack: Size provided by Glance manager is not reliable so take at least 1 row and 1 column // 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) // Set max to 10 children each direction because of Glance limitation
val columnCount = (width.value / 64).toInt().coerceAtLeast(1) val rowCount = (height.value / 95).toInt().coerceIn(1, 10)
val columnCount = (width.value / 64).toInt().coerceIn(1, 10)
return Pair(rowCount, columnCount) return Pair(rowCount, columnCount)
} }

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/cover_placeholder" />
<corners android:radius="@dimen/appwidget_inner_radius" />
</shape>
</item>
<item
android:top="24dp"
android:bottom="24dp"
android:left="24dp"
android:right="24dp">
<vector
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/cover_placeholder"
android:pathData="M21,5v6.59l-2.29,-2.3c-0.39,-0.39 -1.03,-0.39 -1.42,0L14,12.59 10.71,9.3c-0.39,-0.39 -1.02,-0.39 -1.41,0L6,12.59 3,9.58L3,5c0,-1.1 0.9,-2 2,-2h14c1.1,0 2,0.9 2,2zM18,11.42l3,3.01L21,19c0,1.1 -0.9,2 -2,2L5,21c-1.1,0 -2,-0.9 -2,-2v-6.58l2.29,2.29c0.39,0.39 1.02,0.39 1.41,0l3.3,-3.3 3.29,3.29c0.39,0.39 1.02,0.39 1.41,0l3.3,-3.28z"/>
</vector>
</item>
</layer-list>

View File

@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/appwidget_background"
android:pathData="M10,6L8.59,7.41 13.17,12l-4.58,4.59L10,18l6,-6z" />
</vector>