From 783212961c230a465fb1f201e586cce44ccd3339 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Tue, 19 Jan 2021 18:16:14 +0100 Subject: [PATCH] Sticker picker: pass dark/light theme Change-Id: I3c0152cab2d991c4439c10834a06b4c2753510e1 --- FEATURES.md | 1 + .../features/navigation/DefaultNavigator.kt | 3 ++- .../vector/app/features/themes/ThemeUtils.kt | 20 +++++++++++++++++++ .../app/features/widgets/WidgetArgsBuilder.kt | 5 +++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/FEATURES.md b/FEATURES.md index c5ac0add3f..89a2eec146 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -32,6 +32,7 @@ Here you can find some extra features and changes compared to Element Android (w - Some different icons - Emoji-only messages with increased size: also for messages that have spaces between emojis - Also fallback to other user's avatar for 2-person-rooms not marked as DM +- Pass theme to stickerpicker (tested with maunium-stickerpicker) - ... - Sometimes bug fixes for issues in Element, when found during internal testing - Sometimes additional bugs ;) diff --git a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt index 0a6197e424..def5df8973 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt @@ -65,6 +65,7 @@ import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.settings.VectorSettingsActivity import im.vector.app.features.share.SharedData import im.vector.app.features.terms.ReviewTermsActivity +import im.vector.app.features.themes.ThemeUtils import im.vector.app.features.widgets.WidgetActivity import im.vector.app.features.widgets.WidgetArgsBuilder import org.matrix.android.sdk.api.session.crypto.verification.IncomingSasVerificationTransaction @@ -279,7 +280,7 @@ class DefaultNavigator @Inject constructor( activityResultLauncher: ActivityResultLauncher, roomId: String, widget: Widget) { - val widgetArgs = widgetArgsBuilder.buildStickerPickerArgs(roomId, widget) + val widgetArgs = widgetArgsBuilder.buildStickerPickerArgs(roomId, widget, ThemeUtils.getWidgetTheme(context)) val intent = WidgetActivity.newIntent(context, widgetArgs) activityResultLauncher.launch(intent) } diff --git a/vector/src/main/java/im/vector/app/features/themes/ThemeUtils.kt b/vector/src/main/java/im/vector/app/features/themes/ThemeUtils.kt index 02986dcdc7..6af19a413f 100644 --- a/vector/src/main/java/im/vector/app/features/themes/ThemeUtils.kt +++ b/vector/src/main/java/im/vector/app/features/themes/ThemeUtils.kt @@ -125,6 +125,26 @@ object ThemeUtils { } } + /** + * @return true if current theme is black (darker than dark) + */ + fun isBlackTheme(context: Context): Boolean { + return when (getApplicationTheme(context)) { + THEME_BLACK_VALUE, + THEME_SC_VALUE, + THEME_SC_COLORED_VALUE -> true + else -> false + } + } + + fun getWidgetTheme(context: Context): String { + return when { + isLightTheme(context) -> "light" + isBlackTheme(context) -> "black" + else -> "dark" + } + } + /** * Provides the selected application theme * diff --git a/vector/src/main/java/im/vector/app/features/widgets/WidgetArgsBuilder.kt b/vector/src/main/java/im/vector/app/features/widgets/WidgetArgsBuilder.kt index 198278a794..4ba02a04dc 100644 --- a/vector/src/main/java/im/vector/app/features/widgets/WidgetArgsBuilder.kt +++ b/vector/src/main/java/im/vector/app/features/widgets/WidgetArgsBuilder.kt @@ -44,7 +44,7 @@ class WidgetArgsBuilder @Inject constructor(private val sessionHolder: ActiveSes } @Suppress("UNCHECKED_CAST") - fun buildStickerPickerArgs(roomId: String, widget: Widget): WidgetArgs { + fun buildStickerPickerArgs(roomId: String, widget: Widget, theme: String): WidgetArgs { val widgetId = widget.widgetId val baseUrl = widget.computedUrl ?: throw IllegalStateException() return WidgetArgs( @@ -54,7 +54,8 @@ class WidgetArgsBuilder @Inject constructor(private val sessionHolder: ActiveSes widgetId = widgetId, urlParams = mapOf( "widgetId" to widgetId, - "room_id" to roomId + "room_id" to roomId, + "theme" to theme ).filterNotNull() ) }