[bubble merge] Hook up Element's bubbles to SC setting
Change-Id: I0948a2d38ba0dcbbee87f465eab59aad321c8468
This commit is contained in:
parent
af202d22be
commit
1024761526
|
@ -254,6 +254,7 @@ class TimelineFragment @Inject constructor(
|
|||
private val notificationDrawerManager: NotificationDrawerManager,
|
||||
private val eventHtmlRenderer: EventHtmlRenderer,
|
||||
private val vectorPreferences: VectorPreferences,
|
||||
private val bubbleThemeUtils: BubbleThemeUtils,
|
||||
private val colorProvider: ColorProvider,
|
||||
private val dimensionConverter: DimensionConverter,
|
||||
private val userPreferencesProvider: UserPreferencesProvider,
|
||||
|
@ -1067,11 +1068,12 @@ class TimelineFragment @Inject constructor(
|
|||
}
|
||||
|
||||
// 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
|
||||
val selectedBubbleStyle = when (bubbleThemeUtils.getBubbleStyle()) {
|
||||
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
|
||||
BubbleThemeUtils.BUBBLE_STYLE_ELEMENT -> R.id.dev_bubble_style_element
|
||||
else -> R.id.dev_bubble_style_both
|
||||
}
|
||||
menu.findItem(selectedBubbleStyle).isChecked = true
|
||||
}
|
||||
|
@ -1118,6 +1120,10 @@ class TimelineFragment @Inject constructor(
|
|||
handleSetBubbleStyle(BubbleThemeUtils.BUBBLE_STYLE_BOTH)
|
||||
true
|
||||
}
|
||||
R.id.dev_bubble_style_element -> {
|
||||
handleSetBubbleStyle(BubbleThemeUtils.BUBBLE_STYLE_ELEMENT)
|
||||
true
|
||||
}
|
||||
R.id.menu_timeline_thread_list -> {
|
||||
navigateToThreadList()
|
||||
true
|
||||
|
@ -2519,8 +2525,8 @@ class TimelineFragment @Inject constructor(
|
|||
}
|
||||
|
||||
private fun handleSetBubbleStyle(bubbleStyle: String) {
|
||||
if (bubbleStyle != BubbleThemeUtils.getBubbleStyle(requireContext())) {
|
||||
BubbleThemeUtils.setBubbleStyle(requireContext(), bubbleStyle)
|
||||
if (bubbleStyle != bubbleThemeUtils.getBubbleStyle()) {
|
||||
bubbleThemeUtils.setBubbleStyle(bubbleStyle)
|
||||
requireActivity().recreate()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ class TimelineMediaSizeProvider @Inject constructor(private val resources: Resou
|
|||
maxImageWidth = (width * 0.7f).roundToInt()
|
||||
maxImageHeight = (height * 0.7f).roundToInt()
|
||||
}
|
||||
return if (vectorPreferences.useMessageBubblesLayout()) {
|
||||
return if (vectorPreferences.useElementMessageBubblesLayout()) {
|
||||
val bubbleMaxImageWidth = maxImageWidth.coerceAtMost(resources.getDimensionPixelSize(R.dimen.chat_bubble_fixed_size))
|
||||
Pair(bubbleMaxImageWidth, maxImageHeight)
|
||||
} else {
|
||||
|
|
|
@ -17,16 +17,23 @@
|
|||
package im.vector.app.features.home.room.detail.timeline.style
|
||||
|
||||
import im.vector.app.features.settings.VectorPreferences
|
||||
import im.vector.app.features.themes.BubbleThemeUtils
|
||||
import javax.inject.Inject
|
||||
|
||||
class TimelineLayoutSettingsProvider @Inject constructor(private val vectorPreferences: VectorPreferences) {
|
||||
class TimelineLayoutSettingsProvider @Inject constructor(/*private val vectorPreferences: VectorPreferences,*/ private val bubbleThemeUtils: BubbleThemeUtils) {
|
||||
|
||||
fun getLayoutSettings(): TimelineLayoutSettings {
|
||||
// SC-TODO
|
||||
return when (bubbleThemeUtils.getBubbleStyle()) {
|
||||
BubbleThemeUtils.BUBBLE_STYLE_NONE -> TimelineLayoutSettings.MODERN
|
||||
BubbleThemeUtils.BUBBLE_STYLE_ELEMENT -> TimelineLayoutSettings.BUBBLE
|
||||
else -> TimelineLayoutSettings.SC_BUBBLE
|
||||
}
|
||||
/*
|
||||
return if (vectorPreferences.useMessageBubblesLayout()) {
|
||||
TimelineLayoutSettings.BUBBLE
|
||||
} else {
|
||||
TimelineLayoutSettings.MODERN
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import im.vector.app.databinding.FragmentPromptSimplifiedModeBinding
|
|||
import im.vector.app.features.settings.VectorPreferences
|
||||
import javax.inject.Inject
|
||||
|
||||
class PromptSimplifiedModeFragment @Inject constructor() : VectorBaseFragment<FragmentPromptSimplifiedModeBinding>() {
|
||||
class PromptSimplifiedModeFragment @Inject constructor(private val vectorPreferences: VectorPreferences) : VectorBaseFragment<FragmentPromptSimplifiedModeBinding>() {
|
||||
|
||||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentPromptSimplifiedModeBinding {
|
||||
return FragmentPromptSimplifiedModeBinding.inflate(inflater, container, false)
|
||||
|
@ -39,12 +39,12 @@ class PromptSimplifiedModeFragment @Inject constructor() : VectorBaseFragment<Fr
|
|||
}
|
||||
|
||||
private fun simplifiedModeOn() {
|
||||
VectorPreferences(requireContext()).setSimplifiedMode(true)
|
||||
vectorPreferences.setSimplifiedMode(true)
|
||||
activity?.finish()
|
||||
}
|
||||
|
||||
private fun simplifiedModeOff() {
|
||||
VectorPreferences(requireContext()).setSimplifiedMode(false)
|
||||
vectorPreferences.setSimplifiedMode(false)
|
||||
activity?.finish()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,13 +30,16 @@ import im.vector.app.core.di.DefaultSharedPreferences
|
|||
import im.vector.app.features.disclaimer.SHARED_PREF_KEY
|
||||
import im.vector.app.features.home.room.detail.timeline.helper.MatrixItemColorProvider
|
||||
import im.vector.app.features.homeserver.ServerUrlsRepository
|
||||
import im.vector.app.features.themes.BubbleThemeUtils
|
||||
import im.vector.app.features.themes.ThemeUtils
|
||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
class VectorPreferences @Inject constructor(private val context: Context): StaticScSdkHelper.ScSdkPreferenceProvider {
|
||||
class VectorPreferences @Inject constructor(private val context: Context, private val bubbleThemeUtils: BubbleThemeUtils): StaticScSdkHelper.ScSdkPreferenceProvider {
|
||||
|
||||
constructor(context: Context) : this(context, BubbleThemeUtils(context))
|
||||
|
||||
companion object {
|
||||
const val SETTINGS_HELP_PREFERENCE_KEY = "SETTINGS_HELP_PREFERENCE_KEY"
|
||||
|
@ -890,9 +893,14 @@ class VectorPreferences @Inject constructor(private val context: Context): Stati
|
|||
*
|
||||
* @return true to show timeline message in bubble.
|
||||
*/
|
||||
/* SC: use BubbleThemeUtils instead
|
||||
fun useMessageBubblesLayout(): Boolean {
|
||||
return defaultPrefs.getBoolean(SETTINGS_INTERFACE_BUBBLE_KEY, false)
|
||||
}
|
||||
*/
|
||||
fun useElementMessageBubblesLayout(): Boolean {
|
||||
return bubbleThemeUtils.getBubbleStyle() == BubbleThemeUtils.BUBBLE_STYLE_ELEMENT
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if the rage shake is used.
|
||||
|
|
|
@ -34,12 +34,12 @@ import im.vector.app.features.MainActivity
|
|||
import im.vector.app.features.MainActivityArgs
|
||||
import im.vector.app.features.configuration.VectorConfiguration
|
||||
import im.vector.app.features.themes.BubbleThemeUtils
|
||||
import im.vector.app.features.themes.BubbleThemeUtils.BUBBLE_TIME_BOTTOM
|
||||
import im.vector.app.features.themes.ThemeUtils
|
||||
import javax.inject.Inject
|
||||
|
||||
class VectorSettingsPreferencesFragment @Inject constructor(
|
||||
private val vectorConfiguration: VectorConfiguration,
|
||||
private val bubbleThemeUtils: BubbleThemeUtils,
|
||||
private val vectorPreferences: VectorPreferences
|
||||
) : VectorSettingsBaseFragment() {
|
||||
|
||||
|
@ -99,30 +99,12 @@ class VectorSettingsPreferencesFragment @Inject constructor(
|
|||
|
||||
val bubbleStylePreference = findPreference<VectorListPreference>(BubbleThemeUtils.BUBBLE_STYLE_KEY)
|
||||
bubbleStylePreference!!.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
|
||||
BubbleThemeUtils.invalidateBubbleStyle()
|
||||
updateBubbleDependencies(
|
||||
bubbleStyle = newValue as String,
|
||||
BUBBLE_TIME_BOTTOM //bubbleTimeLocation = bubbleTimeLocationPref!!.value
|
||||
)
|
||||
updateBubbleDependencies(bubbleStyle = newValue as String)
|
||||
true
|
||||
}
|
||||
|
||||
//bubbleTimeLocationPref = findPreference<VectorListPreference>(BubbleThemeUtils.BUBBLE_TIME_LOCATION_KEY)
|
||||
alwaysShowTimestampsPref = findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_ALWAYS_SHOW_TIMESTAMPS_KEY)
|
||||
/*
|
||||
bubbleTimeLocationPref!!.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
|
||||
BubbleThemeUtils.invalidateBubbleStyle()
|
||||
updateBubbleDependencies(
|
||||
bubbleStyle = bubbleStylePreference.value,
|
||||
bubbleTimeLocation = newValue as String
|
||||
)
|
||||
true
|
||||
}
|
||||
*/
|
||||
updateBubbleDependencies(
|
||||
bubbleStyle = bubbleStylePreference.value,
|
||||
bubbleTimeLocation = BUBBLE_TIME_BOTTOM //bubbleTimeLocationPref!!.value
|
||||
)
|
||||
updateBubbleDependencies(bubbleStyle = bubbleStylePreference.value)
|
||||
|
||||
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_PREF_SPACE_SHOW_ALL_ROOM_IN_HOME)!!.let { pref ->
|
||||
pref.isChecked = vectorPreferences.prefSpacesShowAllRoomInHome()
|
||||
|
@ -262,8 +244,8 @@ class VectorSettingsPreferencesFragment @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun updateBubbleDependencies(bubbleStyle: String, bubbleTimeLocation: String) {
|
||||
private fun updateBubbleDependencies(bubbleStyle: String) {
|
||||
//bubbleTimeLocationPref?.setEnabled(BubbleThemeUtils.isBubbleTimeLocationSettingAllowed(bubbleStyle))
|
||||
alwaysShowTimestampsPref?.setEnabled(!BubbleThemeUtils.forceAlwaysShowTimestamps(bubbleStyle, bubbleTimeLocation))
|
||||
alwaysShowTimestampsPref?.setEnabled(!bubbleThemeUtils.forceAlwaysShowTimestamps(bubbleStyle))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,63 +6,49 @@ import android.widget.TextView
|
|||
import androidx.preference.PreferenceManager
|
||||
import im.vector.app.features.home.room.detail.timeline.item.AnonymousReadReceipt
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Util class for managing themes.
|
||||
*/
|
||||
object BubbleThemeUtils {
|
||||
const val BUBBLE_STYLE_KEY = "BUBBLE_STYLE_KEY"
|
||||
const val BUBBLE_TIME_LOCATION_KEY = "BUBBLE_TIME_LOCATION_KEY"
|
||||
class BubbleThemeUtils @Inject constructor(private val context: Context) {
|
||||
companion object {
|
||||
const val BUBBLE_STYLE_KEY = "BUBBLE_STYLE_KEY"
|
||||
const val BUBBLE_TIME_LOCATION_KEY = "BUBBLE_TIME_LOCATION_KEY"
|
||||
|
||||
const val BUBBLE_STYLE_NONE = "none"
|
||||
const val BUBBLE_STYLE_START = "start"
|
||||
const val BUBBLE_STYLE_BOTH = "both"
|
||||
const val BUBBLE_TIME_TOP = "top"
|
||||
const val BUBBLE_TIME_BOTTOM = "bottom"
|
||||
const val BUBBLE_STYLE_NONE = "none"
|
||||
const val BUBBLE_STYLE_ELEMENT = "element"
|
||||
const val BUBBLE_STYLE_START = "start"
|
||||
const val BUBBLE_STYLE_BOTH = "both"
|
||||
const val BUBBLE_TIME_TOP = "top"
|
||||
const val BUBBLE_TIME_BOTTOM = "bottom"
|
||||
}
|
||||
|
||||
// Special case of BUBBLE_STYLE_BOTH, to allow non-bubble items align to the sender either way
|
||||
// (not meant for user setting, but internal use)
|
||||
const val BUBBLE_STYLE_BOTH_HIDDEN = "both_hidden"
|
||||
//const val BUBBLE_STYLE_BOTH_HIDDEN = "both_hidden"
|
||||
// As above, so for single bubbles side
|
||||
const val BUBBLE_STYLE_START_HIDDEN = "start_hidden"
|
||||
//const val BUBBLE_STYLE_START_HIDDEN = "start_hidden"
|
||||
|
||||
private var mBubbleStyle: String = ""
|
||||
private var mBubbleTimeLocation: String = ""
|
||||
//private var mBubbleStyle: String = ""
|
||||
//private var mBubbleTimeLocation: String = ""
|
||||
|
||||
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
|
||||
}
|
||||
fun getBubbleStyle(): String {
|
||||
val bubbleStyle = PreferenceManager.getDefaultSharedPreferences(context).getString(BUBBLE_STYLE_KEY, BUBBLE_STYLE_BOTH)!!
|
||||
if (bubbleStyle !in listOf(BUBBLE_STYLE_NONE, BUBBLE_STYLE_START, BUBBLE_STYLE_BOTH, BUBBLE_STYLE_ELEMENT)) {
|
||||
Timber.e("Ignoring invalid bubble style setting: $bubbleStyle")
|
||||
// Invalid setting, fallback to default
|
||||
return BUBBLE_STYLE_BOTH
|
||||
}
|
||||
return mBubbleStyle
|
||||
return bubbleStyle
|
||||
}
|
||||
|
||||
fun setBubbleStyle(context: Context, value: String) {
|
||||
fun setBubbleStyle(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
|
||||
/*
|
||||
if (mBubbleTimeLocation == "") {
|
||||
mBubbleTimeLocation = PreferenceManager.getDefaultSharedPreferences(context).getString(BUBBLE_TIME_LOCATION_KEY, BUBBLE_TIME_BOTTOM)!!
|
||||
}
|
||||
if (!isBubbleTimeLocationSettingAllowed(context)) {
|
||||
return BUBBLE_TIME_TOP;
|
||||
}
|
||||
return mBubbleTimeLocation
|
||||
*/
|
||||
}
|
||||
|
||||
fun getVisibleAnonymousReadReceipts(context: Context, readReceipt: AnonymousReadReceipt, sentByMe: Boolean): AnonymousReadReceipt {
|
||||
fun getVisibleAnonymousReadReceipts(readReceipt: AnonymousReadReceipt, sentByMe: Boolean): AnonymousReadReceipt {
|
||||
// TODO
|
||||
if (false) android.util.Log.e("SCSCSC", " " + context)
|
||||
return if (sentByMe && (/*TODO setting*/ true || readReceipt == AnonymousReadReceipt.PROCESSING)) {
|
||||
readReceipt
|
||||
} else {
|
||||
|
@ -70,6 +56,7 @@ object BubbleThemeUtils {
|
|||
}
|
||||
}
|
||||
|
||||
/* SC-TODO
|
||||
fun drawsActualBubbles(bubbleStyle: String): Boolean {
|
||||
return bubbleStyle == BUBBLE_STYLE_START || bubbleStyle == BUBBLE_STYLE_BOTH
|
||||
}
|
||||
|
@ -77,11 +64,7 @@ object BubbleThemeUtils {
|
|||
fun drawsDualSide(bubbleStyle: String): Boolean {
|
||||
return bubbleStyle == BUBBLE_STYLE_BOTH || bubbleStyle == BUBBLE_STYLE_BOTH_HIDDEN
|
||||
}
|
||||
|
||||
fun invalidateBubbleStyle() {
|
||||
mBubbleStyle = ""
|
||||
mBubbleTimeLocation = ""
|
||||
}
|
||||
*/
|
||||
|
||||
fun guessTextWidth(view: TextView): Float {
|
||||
return guessTextWidth(view, view.text)
|
||||
|
@ -97,19 +80,19 @@ object BubbleThemeUtils {
|
|||
return paint.measureText(text.toString())
|
||||
}
|
||||
|
||||
fun forceAlwaysShowTimestamps(bubbleStyle: String, bubbleTimeLocation: String): Boolean {
|
||||
return isBubbleTimeLocationSettingAllowed(bubbleStyle) && bubbleTimeLocation == BUBBLE_TIME_BOTTOM
|
||||
fun forceAlwaysShowTimestamps(bubbleStyle: String): Boolean {
|
||||
return isBubbleTimeLocationSettingAllowed(bubbleStyle)
|
||||
}
|
||||
|
||||
fun isBubbleTimeLocationSettingAllowed(bubbleStyle: String): Boolean {
|
||||
return bubbleStyle == BUBBLE_STYLE_BOTH || bubbleStyle == BUBBLE_STYLE_BOTH_HIDDEN
|
||||
return bubbleStyle == BUBBLE_STYLE_BOTH // SC-TODO? || bubbleStyle == BUBBLE_STYLE_BOTH_HIDDEN
|
||||
}
|
||||
|
||||
fun forceAlwaysShowTimestamps(context: Context): Boolean {
|
||||
return forceAlwaysShowTimestamps(getBubbleStyle(context), getBubbleTimeLocation(context))
|
||||
fun forceAlwaysShowTimestamps(): Boolean {
|
||||
return forceAlwaysShowTimestamps(getBubbleStyle())
|
||||
}
|
||||
|
||||
fun isBubbleTimeLocationSettingAllowed(context: Context): Boolean {
|
||||
return isBubbleTimeLocationSettingAllowed(getBubbleStyle(context))
|
||||
fun isBubbleTimeLocationSettingAllowed(): Boolean {
|
||||
return isBubbleTimeLocationSettingAllowed(getBubbleStyle())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,15 +89,18 @@
|
|||
<group
|
||||
android:checkableBehavior="single">
|
||||
<item
|
||||
android:id="@+id/dev_bubble_style_none"
|
||||
android:title="@string/bubble_style_none" />
|
||||
android:id="@+id/dev_bubble_style_both"
|
||||
android:title="@string/bubble_style_both"
|
||||
android:checked="true" />
|
||||
<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" />
|
||||
android:id="@+id/dev_bubble_style_element"
|
||||
android:title="@string/bubble_style_element" />
|
||||
<item
|
||||
android:id="@+id/dev_bubble_style_none"
|
||||
android:title="@string/bubble_style_none" />
|
||||
</group>
|
||||
</menu>
|
||||
</item>
|
||||
|
|
|
@ -2,14 +2,16 @@
|
|||
<resources>
|
||||
|
||||
<string-array name="bubble_style_entries" translatable="false">
|
||||
<item>@string/bubble_style_none</item>
|
||||
<item>@string/bubble_style_start</item>
|
||||
<item>@string/bubble_style_both</item>
|
||||
<item>@string/bubble_style_start</item>
|
||||
<item>@string/bubble_style_element</item>
|
||||
<item>@string/bubble_style_none</item>
|
||||
</string-array>
|
||||
<string-array name="bubble_style_values" translatable="false">
|
||||
<item>none</item>
|
||||
<item>start</item>
|
||||
<item>both</item>
|
||||
<item>start</item>
|
||||
<item>element</item>
|
||||
<item>none</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="bubble_time_location_entries" translatable="false">
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
<string name="bubble_style_none">None</string>
|
||||
<string name="bubble_style_start">Same side</string>
|
||||
<string name="bubble_style_both">Both sides</string>
|
||||
<string name="bubble_style_element">Element</string>
|
||||
<string name="bubble_time_location">Timestamp location</string>
|
||||
<string name="bubble_time_location_top">Top</string>
|
||||
<string name="bubble_time_location_bottom">Bottom</string>
|
||||
|
|
Loading…
Reference in New Issue