diff --git a/android/src/main/kotlin/foundation/e/blissweather/widget/WeatherAppWidgetProvider.kt b/android/src/main/kotlin/foundation/e/blissweather/widget/WeatherAppWidgetProvider.kt
index 9955587eb708da980f934649cc5072106b49a3b4..443a8970235e389c6693001361b0b6b4c9d7db20 100644
--- a/android/src/main/kotlin/foundation/e/blissweather/widget/WeatherAppWidgetProvider.kt
+++ b/android/src/main/kotlin/foundation/e/blissweather/widget/WeatherAppWidgetProvider.kt
@@ -7,9 +7,11 @@
*/
package foundation.e.blissweather.widget
+import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider
import android.content.Context
import android.content.Intent
+import android.os.Bundle
import android.util.Log
import androidx.work.BackoffPolicy
import androidx.work.Constraints
@@ -28,6 +30,16 @@ import javax.inject.Inject
class WeatherAppWidgetProvider : AppWidgetProvider() {
@Inject lateinit var appPrefs: AppPreferences
+ override fun onAppWidgetOptionsChanged(
+ context: Context,
+ appWidgetManager: AppWidgetManager,
+ appWidgetId: Int,
+ newOptions: Bundle?
+ ) {
+ refresh(context)
+ super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions)
+ }
+
override fun onEnabled(context: Context) {
val workMgr = WorkManager.getInstance(context.applicationContext)
val refreshInterval = appPrefs.weatherRefreshInterval
@@ -55,14 +67,18 @@ class WeatherAppWidgetProvider : AppWidgetProvider() {
}
}
+ private fun refresh(context: Context) {
+ onDisabled(context)
+ onEnabled(context)
+ }
+
override fun onReceive(context: Context, intent: Intent?) {
Log.d(TAG, "onReceive: $intent}")
super.onReceive(context, intent)
when (intent?.action) {
ACTION_WEATHER_REFRESH,
Intent.ACTION_LOCALE_CHANGED -> {
- onDisabled(context)
- onEnabled(context)
+ refresh(context)
}
}
}
diff --git a/android/src/main/kotlin/foundation/e/blissweather/worker/WeatherUpdaterWorker.kt b/android/src/main/kotlin/foundation/e/blissweather/worker/WeatherUpdaterWorker.kt
index f47f4a3d5c9c2bbe00cced7f2ba37b4cc3e2168b..53d688a35d03c893ed302b799669de82077d1931 100644
--- a/android/src/main/kotlin/foundation/e/blissweather/worker/WeatherUpdaterWorker.kt
+++ b/android/src/main/kotlin/foundation/e/blissweather/worker/WeatherUpdaterWorker.kt
@@ -53,12 +53,22 @@ constructor(
return if (weather?.current == null || weather.forecasts == null) {
Result.retry()
} else {
- val views =
- RemoteViews(applicationContext.packageName, R.layout.layout_weather_info).apply {
- updateWeatherView(applicationContext, weather, appPreferences)
- }
+ widgetIds.forEach { id ->
+ val maxWidth =
+ appWidgetManager
+ ?.getAppWidgetOptions(id)
+ ?.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH)
+ ?: 0
+ val view =
+ RemoteViews(
+ applicationContext.packageName,
+ if (maxWidth <= 300) R.layout.layout_weather_info_narrow
+ else R.layout.layout_weather_info
+ )
+ .apply { updateWeatherView(applicationContext, weather, appPreferences) }
- appWidgetManager.updateAppWidget(widgetIds, views)
+ appWidgetManager.updateAppWidget(id, view)
+ }
Result.success()
}
}
diff --git a/android/src/main/res/layout/layout_weather_info.xml b/android/src/main/res/layout/layout_weather_info.xml
index f172b33e72e48eb1ec39270d3589c1343fe241ff..f2914decba0de51e6b1a8dadf2524928e52d1c60 100644
--- a/android/src/main/res/layout/layout_weather_info.xml
+++ b/android/src/main/res/layout/layout_weather_info.xml
@@ -78,7 +78,8 @@
android:id="@+id/location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:breakStrategy="high_quality"
+ android:ellipsize="middle"
+ android:maxLines="1"
android:textColor="@color/e_primary_text_color_dark"
android:textSize="18sp" />
@@ -86,6 +87,7 @@
android:id="@+id/weather_summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/e_secondary_text_color_dark"
android:textSize="16sp" />
@@ -161,4 +163,4 @@
android:layout_height="wrap_content"
android:orientation="horizontal" />
-
+
\ No newline at end of file
diff --git a/android/src/main/res/layout/layout_weather_info_narrow.xml b/android/src/main/res/layout/layout_weather_info_narrow.xml
new file mode 100644
index 0000000000000000000000000000000000000000..aadb2167f07e6143ef95c1251364e7a0aee39486
--- /dev/null
+++ b/android/src/main/res/layout/layout_weather_info_narrow.xml
@@ -0,0 +1,167 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android/src/main/res/layout/weather_day.xml b/android/src/main/res/layout/weather_day.xml
index 3318d47c9cab8dc3eb1d197b50caed5b3a79a256..f557c14c8e65be0f9ca338abd600fe0396e30529 100644
--- a/android/src/main/res/layout/weather_day.xml
+++ b/android/src/main/res/layout/weather_day.xml
@@ -14,9 +14,9 @@
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal|fill_horizontal"
android:maxLines="1"
- android:text="mon"
android:textAppearance="?android:attr/textAppearanceSmallInverse"
- android:textColor="@color/e_secondary_text_color_dark" />
+ android:textColor="@color/e_secondary_text_color_dark"
+ android:textSize="12sp" />
+ android:textColor="@color/e_primary_text_color_dark"
+ android:textSize="12sp" />