From ffe60fe763d5e34ad6608c8c26a7ecc42e8e9feb Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Tue, 11 Jan 2022 12:56:49 +0100 Subject: [PATCH] Dev mode: quick option to switch message bubble style Change-Id: I229a5cf12591cad47fe6c212a21bd2d654c61ba6 --- .../home/room/detail/RoomDetailFragment.kt | 29 +++++++++++++++++++ .../home/room/detail/RoomDetailViewModel.kt | 1 + .../app/features/themes/BubbleThemeUtils.kt | 11 +++++++ vector/src/main/res/menu/menu_timeline.xml | 23 +++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt index 8b4151144f..c8e82fdbe8 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailFragment.kt @@ -179,6 +179,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.spaces.share.ShareSpaceBottomSheet +import im.vector.app.features.themes.BubbleThemeUtils import im.vector.app.features.themes.ThemeUtils import im.vector.app.features.voice.VoiceFailure import im.vector.app.features.widgets.WidgetActivity @@ -1021,6 +1022,15 @@ class RoomDetailFragment @Inject constructor( matrixAppsMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS) } } + + // Selected bubble style + val selectedBubbleStyle = when (BubbleThemeUtils.getBubbleStyle(requireContext())) { + BubbleThemeUtils.BUBBLE_STYLE_NONE -> R.id.dev_bubble_style_none + BubbleThemeUtils.BUBBLE_STYLE_START -> R.id.dev_bubble_style_start + BubbleThemeUtils.BUBBLE_STYLE_BOTH -> R.id.dev_bubble_style_both + else -> 0 + } + menu.findItem(selectedBubbleStyle).isChecked = true } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -1053,6 +1063,18 @@ class RoomDetailFragment @Inject constructor( navigator.openRoomProfile(requireActivity(), roomDetailArgs.roomId) true } + R.id.dev_bubble_style_none -> { + handleSetBubbleStyle(BubbleThemeUtils.BUBBLE_STYLE_NONE) + true + } + R.id.dev_bubble_style_start -> { + handleSetBubbleStyle(BubbleThemeUtils.BUBBLE_STYLE_START) + true + } + R.id.dev_bubble_style_both -> { + handleSetBubbleStyle(BubbleThemeUtils.BUBBLE_STYLE_BOTH) + true + } R.id.search -> { handleSearchAction() true @@ -2287,6 +2309,13 @@ class RoomDetailFragment @Inject constructor( }.exhaustive } + private fun handleSetBubbleStyle(bubbleStyle: String) { + if (bubbleStyle != BubbleThemeUtils.getBubbleStyle(requireContext())) { + BubbleThemeUtils.setBubbleStyle(requireContext(), bubbleStyle) + requireActivity().recreate() + } + } + // AttachmentsHelper.Callback override fun onContentAttachmentsReady(attachments: List) { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt index 965062429b..b66e04198b 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt @@ -620,6 +620,7 @@ class RoomDetailViewModel @AssistedInject constructor( R.id.show_room_info -> true R.id.show_participants -> true R.id.search -> true + R.id.dev_bubble_style, R.id.dev_tools -> vectorPreferences.developerMode() else -> false } diff --git a/vector/src/main/java/im/vector/app/features/themes/BubbleThemeUtils.kt b/vector/src/main/java/im/vector/app/features/themes/BubbleThemeUtils.kt index 02a8473e27..690931f0d4 100644 --- a/vector/src/main/java/im/vector/app/features/themes/BubbleThemeUtils.kt +++ b/vector/src/main/java/im/vector/app/features/themes/BubbleThemeUtils.kt @@ -5,6 +5,7 @@ import android.graphics.Paint import android.widget.TextView import androidx.preference.PreferenceManager import im.vector.app.features.home.room.detail.timeline.item.AnonymousReadReceipt +import timber.log.Timber /** * Util class for managing themes. @@ -31,10 +32,20 @@ object BubbleThemeUtils { fun getBubbleStyle(context: Context): String { if (mBubbleStyle == "") { mBubbleStyle = PreferenceManager.getDefaultSharedPreferences(context).getString(BUBBLE_STYLE_KEY, BUBBLE_STYLE_BOTH)!! + if (mBubbleStyle !in listOf(BUBBLE_STYLE_NONE, BUBBLE_STYLE_START, BUBBLE_STYLE_BOTH)) { + Timber.e("Ignoring invalid bubble style setting: $mBubbleStyle") + // Invalid setting, fallback to default + mBubbleStyle = BUBBLE_STYLE_BOTH + } } return mBubbleStyle } + fun setBubbleStyle(context: Context, value: String) { + PreferenceManager.getDefaultSharedPreferences(context).edit().putString(BUBBLE_STYLE_KEY, value).apply() + invalidateBubbleStyle() + } + fun getBubbleTimeLocation(@Suppress("UNUSED_PARAMETER") context: Context): String { // Always use bottom when allowed return if (isBubbleTimeLocationSettingAllowed(context)) BUBBLE_TIME_BOTTOM else BUBBLE_TIME_TOP diff --git a/vector/src/main/res/menu/menu_timeline.xml b/vector/src/main/res/menu/menu_timeline.xml index f4f71971af..98111bb414 100644 --- a/vector/src/main/res/menu/menu_timeline.xml +++ b/vector/src/main/res/menu/menu_timeline.xml @@ -63,6 +63,29 @@ app:showAsAction="never" tools:visible="true" /> + + + + + + + + + +