Dev mode: quick option to switch message bubble style

Change-Id: I229a5cf12591cad47fe6c212a21bd2d654c61ba6
This commit is contained in:
SpiritCroc 2022-01-11 12:56:49 +01:00
parent 2da47f81bd
commit ffe60fe763
4 changed files with 64 additions and 0 deletions

View file

@ -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<ContentAttachmentData>) {

View file

@ -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
}

View file

@ -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

View file

@ -63,6 +63,29 @@
app:showAsAction="never"
tools:visible="true" />
<item
android:id="@+id/dev_bubble_style"
android:title="@string/bubble_style"
android:visible="false"
app:showAsAction="never"
tools:visible="true">
<menu>
<group
android:checkableBehavior="single">
<item
android:id="@+id/dev_bubble_style_none"
android:title="@string/bubble_style_none" />
<item
android:id="@+id/dev_bubble_style_start"
android:title="@string/bubble_style_start" />
<item
android:id="@+id/dev_bubble_style_both"
android:title="@string/bubble_style_both"
android:checked="true" />
</group>
</menu>
</item>
<item
android:id="@+id/dev_tools"
android:icon="@drawable/ic_settings_root_general"