From cbc67cdf2832e2ebdccb82020aac69f92cc2b3ba Mon Sep 17 00:00:00 2001 From: John Andrew Camu Date: Wed, 20 Dec 2023 15:00:40 +0800 Subject: [PATCH] Fixed weather at glance (#3895) * Fixed weather at glance - Fixed not displaying weather caused by the new google at glance widget * Fixed weather clicked action * Fixed styling * Open in google app weather instead of page --- .../smartspace/provider/SmartspaceWidgetReader.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lawnchair/src/app/lawnchair/smartspace/provider/SmartspaceWidgetReader.kt b/lawnchair/src/app/lawnchair/smartspace/provider/SmartspaceWidgetReader.kt index a10e130d27..a0162dbd30 100644 --- a/lawnchair/src/app/lawnchair/smartspace/provider/SmartspaceWidgetReader.kt +++ b/lawnchair/src/app/lawnchair/smartspace/provider/SmartspaceWidgetReader.kt @@ -3,6 +3,7 @@ package app.lawnchair.smartspace.provider import android.app.Activity import android.app.PendingIntent import android.appwidget.AppWidgetManager +import android.content.ComponentName import android.content.Context import android.content.Intent import android.graphics.Bitmap @@ -12,7 +13,6 @@ import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView -import androidx.core.view.isVisible import app.lawnchair.BlankActivity import app.lawnchair.HeadlessWidgetsManager import app.lawnchair.smartspace.model.SmartspaceAction @@ -57,9 +57,9 @@ class SmartspaceWidgetReader(context: Context) : SmartspaceDataSource( } private fun extractWidgetLayout(appWidgetHostView: ViewGroup): List { - val children = appWidgetHostView.recursiveChildren.filter { it.isVisible } + val children = appWidgetHostView.recursiveChildren val texts = children.filterIsInstance().filter { !it.text.isNullOrEmpty() }.toList() - val images = children.filterIsInstance().toList() + val images = children.filterIsInstance().toList().filter { it.drawable != null && it.drawable is BitmapDrawable } var weatherIconView: ImageView? = null var cardIconView: ImageView? = null var title: TextView? = null @@ -68,7 +68,7 @@ class SmartspaceWidgetReader(context: Context) : SmartspaceDataSource( var temperatureText: TextView? = null if (texts.isEmpty()) return listOf(dummyTarget) if (images.isNotEmpty()) { - weatherIconView = images.last() + weatherIconView = images.firstOrNull() temperatureText = texts.last() } if (images.size > 1 && texts.size > 2) { @@ -103,6 +103,7 @@ class SmartspaceWidgetReader(context: Context) : SmartspaceDataSource( title = ttl, subtitle = sub.text, pendingIntent = pendingIntent, + intent = weather.baseAction?.intent, ), score = SmartspaceScores.SCORE_CALENDAR, featureType = SmartspaceTarget.FeatureType.FEATURE_CALENDAR, @@ -119,6 +120,9 @@ class SmartspaceWidgetReader(context: Context) : SmartspaceDataSource( val weatherData = parseWeatherData( weatherIcon, temperature, pendingIntent, ) ?: return null + val intent = Intent().apply { + component = WEATHER_COMPONENT + } return SmartspaceTarget( id = "smartspaceWidgetWeather", headerAction = SmartspaceAction( @@ -127,6 +131,7 @@ class SmartspaceWidgetReader(context: Context) : SmartspaceDataSource( title = "", subtitle = weatherData.getTitle(), pendingIntent = weatherData.pendingIntent, + intent = intent, ), score = SmartspaceScores.SCORE_WEATHER, featureType = SmartspaceTarget.FeatureType.FEATURE_WEATHER, @@ -153,6 +158,8 @@ class SmartspaceWidgetReader(context: Context) : SmartspaceDataSource( companion object { private const val GSA_PACKAGE = "com.google.android.googlequicksearchbox" private const val WIDGET_CLASS_NAME = "com.google.android.apps.gsa.staticplugins.smartspace.widget.SmartspaceWidgetProvider" + private const val GSA_WEATHER = "com.google.android.apps.search.weather.WeatherExportedActivity" + private val WEATHER_COMPONENT = ComponentName(GSA_PACKAGE, GSA_WEATHER) private val dummyTarget = SmartspaceTarget( id = "dummyTarget",