From a69049645aec95c41c0ab1cf8ac2840e89dd9604 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 26 Feb 2020 11:11:10 +0100 Subject: [PATCH] FTUE: do not display a different color when encrypting message when not in developer mode. --- CHANGES.md | 1 + .../detail/timeline/MessageColorProvider.kt | 58 +++++++++++++++++++ .../timeline/factory/MessageItemFactory.kt | 2 +- .../factory/VerificationItemFactory.kt | 8 +-- .../helper/ContentUploadStateTrackerBinder.kt | 17 +++--- .../helper/MessageItemAttributesFactory.kt | 6 +- .../timeline/item/AbsBaseMessageItem.kt | 7 +-- .../detail/timeline/item/AbsMessageItem.kt | 4 +- .../item/VerificationRequestConclusionItem.kt | 4 +- .../timeline/item/VerificationRequestItem.kt | 4 +- .../riotx/features/ui/ColorProviderExt.kt | 37 ------------ 11 files changed, 84 insertions(+), 64 deletions(-) create mode 100644 vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/MessageColorProvider.kt delete mode 100644 vector/src/main/java/im/vector/riotx/features/ui/ColorProviderExt.kt diff --git a/CHANGES.md b/CHANGES.md index 37b6c63393..abf318ef50 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ Features ✨: Improvements 🙌: - Migrate to binary QR code verification (#994) - Share action is added to room profile and room member profile (#858) + - FTUE: do not display a different color when encrypting message when not in developer mode. Bugfix 🐛: - Account creation: wrongly hints that an email can be used to create an account (#941) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/MessageColorProvider.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/MessageColorProvider.kt new file mode 100644 index 0000000000..c6ab5b024f --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/MessageColorProvider.kt @@ -0,0 +1,58 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx.features.home.room.detail.timeline + +import androidx.annotation.ColorInt +import im.vector.matrix.android.api.session.room.send.SendState +import im.vector.riotx.R +import im.vector.riotx.core.resources.ColorProvider +import im.vector.riotx.features.settings.VectorPreferences +import javax.inject.Inject + +class MessageColorProvider @Inject constructor( + private val colorProvider: ColorProvider, + private val vectorPreferences: VectorPreferences) { + + @ColorInt + fun getMessageTextColor(sendState: SendState): Int { + return if (vectorPreferences.developerMode()) { + when (sendState) { + // SendStates, in the classical order they will occur + SendState.UNKNOWN, + SendState.UNSENT -> colorProvider.getColorFromAttribute(R.attr.vctr_sending_message_text_color) + SendState.ENCRYPTING -> colorProvider.getColorFromAttribute(R.attr.vctr_encrypting_message_text_color) + SendState.SENDING -> colorProvider.getColorFromAttribute(R.attr.vctr_sending_message_text_color) + SendState.SENT, + SendState.SYNCED -> colorProvider.getColorFromAttribute(R.attr.vctr_message_text_color) + SendState.UNDELIVERED, + SendState.FAILED_UNKNOWN_DEVICES -> colorProvider.getColorFromAttribute(R.attr.vctr_unsent_message_text_color) + } + } else { + // When not in developer mode, we do not use special color for the encrypting state + when (sendState) { + SendState.UNKNOWN, + SendState.UNSENT, + SendState.ENCRYPTING, + SendState.SENDING -> colorProvider.getColorFromAttribute(R.attr.vctr_sending_message_text_color) + SendState.SENT, + SendState.SYNCED -> colorProvider.getColorFromAttribute(R.attr.vctr_message_text_color) + SendState.UNDELIVERED, + SendState.FAILED_UNKNOWN_DEVICES -> colorProvider.getColorFromAttribute(R.attr.vctr_unsent_message_text_color) + } + } + } +} diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt index 83f0c63147..2b221b9fef 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt @@ -222,7 +222,7 @@ class MessageItemFactory @Inject constructor( referenceId = informationData.eventId, informationData = informationData, avatarRenderer = attributes.avatarRenderer, - colorProvider = attributes.colorProvider, + messageColorProvider = attributes.messageColorProvider, itemLongClickListener = attributes.itemLongClickListener, itemClickListener = attributes.itemClickListener, reactionPillCallback = attributes.reactionPillCallback, diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/VerificationItemFactory.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/VerificationItemFactory.kt index dc5bd740dd..12bc10ebdb 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/VerificationItemFactory.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/VerificationItemFactory.kt @@ -27,8 +27,8 @@ import im.vector.matrix.android.api.session.room.model.message.MessageVerificati import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.matrix.android.internal.session.room.VerificationState import im.vector.riotx.core.epoxy.VectorEpoxyModel -import im.vector.riotx.core.resources.ColorProvider import im.vector.riotx.core.resources.UserPreferencesProvider +import im.vector.riotx.features.home.room.detail.timeline.MessageColorProvider import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController import im.vector.riotx.features.home.room.detail.timeline.helper.AvatarSizeProvider import im.vector.riotx.features.home.room.detail.timeline.helper.MessageInformationDataFactory @@ -43,7 +43,7 @@ import javax.inject.Inject * several checks are made to see if this conclusion is attached to a known request */ class VerificationItemFactory @Inject constructor( - private val colorProvider: ColorProvider, + private val messageColorProvider: MessageColorProvider, private val messageInformationDataFactory: MessageInformationDataFactory, private val messageItemAttributesFactory: MessageItemAttributesFactory, private val avatarSizeProvider: AvatarSizeProvider, @@ -97,7 +97,7 @@ class VerificationItemFactory @Inject constructor( isPositive = false, informationData = informationData, avatarRenderer = attributes.avatarRenderer, - colorProvider = colorProvider, + messageColorProvider = messageColorProvider, emojiTypeFace = attributes.emojiTypeFace, itemClickListener = attributes.itemClickListener, itemLongClickListener = attributes.itemLongClickListener, @@ -130,7 +130,7 @@ class VerificationItemFactory @Inject constructor( isPositive = true, informationData = informationData, avatarRenderer = attributes.avatarRenderer, - colorProvider = colorProvider, + messageColorProvider = messageColorProvider, emojiTypeFace = attributes.emojiTypeFace, itemClickListener = attributes.itemClickListener, itemLongClickListener = attributes.itemLongClickListener, diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt index d80c625e8f..4cf14fa83b 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/ContentUploadStateTrackerBinder.kt @@ -27,14 +27,13 @@ import im.vector.riotx.R import im.vector.riotx.core.di.ActiveSessionHolder import im.vector.riotx.core.di.ScreenScope import im.vector.riotx.core.error.ErrorFormatter -import im.vector.riotx.core.resources.ColorProvider import im.vector.riotx.core.utils.TextUtils -import im.vector.riotx.features.ui.getMessageTextColor +import im.vector.riotx.features.home.room.detail.timeline.MessageColorProvider import javax.inject.Inject @ScreenScope class ContentUploadStateTrackerBinder @Inject constructor(private val activeSessionHolder: ActiveSessionHolder, - private val colorProvider: ColorProvider, + private val messageColorProvider: MessageColorProvider, private val errorFormatter: ErrorFormatter) { private val updateListeners = mutableMapOf() @@ -44,7 +43,7 @@ class ContentUploadStateTrackerBinder @Inject constructor(private val activeSess progressLayout: ViewGroup) { activeSessionHolder.getSafeActiveSession()?.also { session -> val uploadStateTracker = session.contentUploadProgressTracker() - val updateListener = ContentMediaProgressUpdater(progressLayout, isLocalFile, colorProvider, errorFormatter) + val updateListener = ContentMediaProgressUpdater(progressLayout, isLocalFile, messageColorProvider, errorFormatter) updateListeners[eventId] = updateListener uploadStateTracker.track(eventId, updateListener) } @@ -68,7 +67,7 @@ class ContentUploadStateTrackerBinder @Inject constructor(private val activeSess private class ContentMediaProgressUpdater(private val progressLayout: ViewGroup, private val isLocalFile: Boolean, - private val colorProvider: ColorProvider, + private val messageColorProvider: MessageColorProvider, private val errorFormatter: ErrorFormatter) : ContentUploadStateTracker.UpdateListener { override fun onUpdate(state: ContentUploadStateTracker.State) { @@ -92,7 +91,7 @@ private class ContentMediaProgressUpdater(private val progressLayout: ViewGroup, progressBar?.isIndeterminate = true progressBar?.progress = 0 progressTextView?.text = progressLayout.context.getString(R.string.send_file_step_idle) - progressTextView?.setTextColor(colorProvider.getMessageTextColor(SendState.UNSENT)) + progressTextView?.setTextColor(messageColorProvider.getMessageTextColor(SendState.UNSENT)) } else { progressLayout.isVisible = false } @@ -120,7 +119,7 @@ private class ContentMediaProgressUpdater(private val progressLayout: ViewGroup, val progressTextView = progressLayout.findViewById(R.id.mediaProgressTextView) progressBar?.isIndeterminate = true progressTextView?.text = progressLayout.context.getString(resId) - progressTextView?.setTextColor(colorProvider.getMessageTextColor(SendState.ENCRYPTING)) + progressTextView?.setTextColor(messageColorProvider.getMessageTextColor(SendState.ENCRYPTING)) } private fun doHandleProgress(resId: Int, current: Long, total: Long) { @@ -134,7 +133,7 @@ private class ContentMediaProgressUpdater(private val progressLayout: ViewGroup, progressTextView?.text = progressLayout.context.getString(resId, TextUtils.formatFileSize(progressLayout.context, current, true), TextUtils.formatFileSize(progressLayout.context, total, true)) - progressTextView?.setTextColor(colorProvider.getMessageTextColor(SendState.SENDING)) + progressTextView?.setTextColor(messageColorProvider.getMessageTextColor(SendState.SENDING)) } private fun handleFailure(state: ContentUploadStateTracker.State.Failure) { @@ -143,7 +142,7 @@ private class ContentMediaProgressUpdater(private val progressLayout: ViewGroup, val progressTextView = progressLayout.findViewById(R.id.mediaProgressTextView) progressBar?.isVisible = false progressTextView?.text = errorFormatter.toHumanReadable(state.throwable) - progressTextView?.setTextColor(colorProvider.getMessageTextColor(SendState.UNDELIVERED)) + progressTextView?.setTextColor(messageColorProvider.getMessageTextColor(SendState.UNDELIVERED)) } private fun handleSuccess() { diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt index 0e1229eeca..7433b03408 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/MessageItemAttributesFactory.kt @@ -20,9 +20,9 @@ package im.vector.riotx.features.home.room.detail.timeline.helper import android.view.View import im.vector.matrix.android.api.session.room.model.message.MessageContent import im.vector.riotx.EmojiCompatFontProvider -import im.vector.riotx.core.resources.ColorProvider import im.vector.riotx.core.utils.DebouncedClickListener import im.vector.riotx.features.home.AvatarRenderer +import im.vector.riotx.features.home.room.detail.timeline.MessageColorProvider import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController import im.vector.riotx.features.home.room.detail.timeline.item.AbsMessageItem import im.vector.riotx.features.home.room.detail.timeline.item.MessageInformationData @@ -30,7 +30,7 @@ import javax.inject.Inject class MessageItemAttributesFactory @Inject constructor( private val avatarRenderer: AvatarRenderer, - private val colorProvider: ColorProvider, + private val messageColorProvider: MessageColorProvider, private val avatarSizeProvider: AvatarSizeProvider, private val emojiCompatFontProvider: EmojiCompatFontProvider) { @@ -41,7 +41,7 @@ class MessageItemAttributesFactory @Inject constructor( avatarSize = avatarSizeProvider.avatarSize, informationData = informationData, avatarRenderer = avatarRenderer, - colorProvider = colorProvider, + messageColorProvider = messageColorProvider, itemLongClickListener = View.OnLongClickListener { view -> callback?.onEventLongClicked(informationData, messageContent, view) ?: false }, diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt index 6d99bb2650..149b5e74ad 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt @@ -24,12 +24,11 @@ import androidx.annotation.IdRes import androidx.core.view.isVisible import im.vector.matrix.android.api.session.room.send.SendState import im.vector.riotx.R -import im.vector.riotx.core.resources.ColorProvider import im.vector.riotx.core.utils.DebouncedClickListener import im.vector.riotx.features.home.AvatarRenderer +import im.vector.riotx.features.home.room.detail.timeline.MessageColorProvider import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController import im.vector.riotx.features.reactions.widget.ReactionButton -import im.vector.riotx.features.ui.getMessageTextColor /** * Base timeline item with reactions and read receipts. @@ -105,7 +104,7 @@ abstract class AbsBaseMessageItem : BaseEventItem protected open fun renderSendState(root: View, textView: TextView?, failureIndicator: ImageView? = null) { root.isClickable = baseAttributes.informationData.sendState.isSent() val state = if (baseAttributes.informationData.hasPendingEdits) SendState.UNSENT else baseAttributes.informationData.sendState - textView?.setTextColor(baseAttributes.colorProvider.getMessageTextColor(state)) + textView?.setTextColor(baseAttributes.messageColorProvider.getMessageTextColor(state)) failureIndicator?.isVisible = baseAttributes.informationData.sendState.hasFailed() } @@ -120,7 +119,7 @@ abstract class AbsBaseMessageItem : BaseEventItem // val avatarSize: Int, val informationData: MessageInformationData val avatarRenderer: AvatarRenderer - val colorProvider: ColorProvider + val messageColorProvider: MessageColorProvider val itemLongClickListener: View.OnLongClickListener? val itemClickListener: View.OnClickListener? // val memberClickListener: View.OnClickListener? diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt index ae69164951..2b01e915df 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt @@ -23,9 +23,9 @@ import android.widget.TextView import androidx.annotation.IdRes import com.airbnb.epoxy.EpoxyAttribute import im.vector.riotx.R -import im.vector.riotx.core.resources.ColorProvider import im.vector.riotx.core.utils.DebouncedClickListener import im.vector.riotx.features.home.AvatarRenderer +import im.vector.riotx.features.home.room.detail.timeline.MessageColorProvider import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController /** @@ -88,7 +88,7 @@ abstract class AbsMessageItem : AbsBaseMessageItem val avatarSize: Int, override val informationData: MessageInformationData, override val avatarRenderer: AvatarRenderer, - override val colorProvider: ColorProvider, + override val messageColorProvider: MessageColorProvider, override val itemLongClickListener: View.OnLongClickListener? = null, override val itemClickListener: View.OnClickListener? = null, val memberClickListener: View.OnClickListener? = null, diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/VerificationRequestConclusionItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/VerificationRequestConclusionItem.kt index 036bf2b036..2b28e15cab 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/VerificationRequestConclusionItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/VerificationRequestConclusionItem.kt @@ -26,8 +26,8 @@ import androidx.core.view.updateLayoutParams import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass import im.vector.riotx.R -import im.vector.riotx.core.resources.ColorProvider import im.vector.riotx.features.home.AvatarRenderer +import im.vector.riotx.features.home.room.detail.timeline.MessageColorProvider import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController @EpoxyModelClass(layout = R.layout.item_timeline_event_base_state) @@ -80,7 +80,7 @@ abstract class VerificationRequestConclusionItem : AbsBaseMessageItem getColorFromAttribute(R.attr.vctr_sending_message_text_color) - SendState.ENCRYPTING -> getColorFromAttribute(R.attr.vctr_encrypting_message_text_color) - SendState.SENDING -> getColorFromAttribute(R.attr.vctr_sending_message_text_color) - SendState.SENT, - SendState.SYNCED -> getColorFromAttribute(R.attr.vctr_message_text_color) - SendState.UNDELIVERED, - SendState.FAILED_UNKNOWN_DEVICES -> getColorFromAttribute(R.attr.vctr_unsent_message_text_color) - } -}