forward the theme to all widgets

This commit is contained in:
Benoit Marty 2021-02-05 12:32:09 +01:00
parent afd2ecd384
commit cf9d99ee8b

View File

@ -49,14 +49,6 @@ class WidgetArgsBuilder @Inject constructor(
) )
} }
private fun getTheme(): String {
return if (ThemeUtils.isLightTheme(context)) {
"light"
} else {
"dark"
}
}
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
fun buildStickerPickerArgs(roomId: String, widget: Widget): WidgetArgs { fun buildStickerPickerArgs(roomId: String, widget: Widget): WidgetArgs {
val widgetId = widget.widgetId val widgetId = widget.widgetId
@ -68,7 +60,8 @@ class WidgetArgsBuilder @Inject constructor(
widgetId = widgetId, widgetId = widgetId,
urlParams = mapOf( urlParams = mapOf(
"widgetId" to widgetId, "widgetId" to widgetId,
"room_id" to roomId "room_id" to roomId,
"theme" to getTheme()
).filterNotNull() ).filterNotNull()
) )
} }
@ -80,7 +73,10 @@ class WidgetArgsBuilder @Inject constructor(
baseUrl = baseUrl, baseUrl = baseUrl,
kind = WidgetKind.ROOM, kind = WidgetKind.ROOM,
roomId = roomId, roomId = roomId,
widgetId = widgetId widgetId = widgetId,
urlParams = mapOf(
"theme" to getTheme()
).filterNotNull()
) )
} }
@ -88,4 +84,12 @@ class WidgetArgsBuilder @Inject constructor(
private fun Map<String, String?>.filterNotNull(): Map<String, String> { private fun Map<String, String?>.filterNotNull(): Map<String, String> {
return filterValues { it != null } as Map<String, String> return filterValues { it != null } as Map<String, String>
} }
private fun getTheme(): String {
return if (ThemeUtils.isLightTheme(context)) {
"light"
} else {
"dark"
}
}
} }