From d1102f7be47b2c8d6623e659e0e37e12e9a810a7 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 23 Nov 2021 18:19:33 +0000 Subject: [PATCH 1/3] fixing wrong cased data class names --- .../sdk/api/session/room/send/UserDraft.kt | 10 ++-- .../internal/database/mapper/DraftMapper.kt | 18 +++--- .../home/room/detail/RoomDetailFragment.kt | 8 +-- .../composer/MessageComposerViewModel.kt | 56 +++++++++---------- .../composer/MessageComposerViewState.kt | 10 ++-- 5 files changed, 51 insertions(+), 51 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/send/UserDraft.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/send/UserDraft.kt index 9471b3dbcb..1f2f91c0ec 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/send/UserDraft.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/send/UserDraft.kt @@ -24,14 +24,14 @@ package org.matrix.android.sdk.api.session.room.send * REPLY: draft of a reply of another message */ sealed class UserDraft(open val text: String) { - data class REGULAR(override val text: String) : UserDraft(text) - data class QUOTE(val linkedEventId: String, override val text: String) : UserDraft(text) - data class EDIT(val linkedEventId: String, override val text: String) : UserDraft(text) - data class REPLY(val linkedEventId: String, override val text: String) : UserDraft(text) + data class Regular(override val text: String) : UserDraft(text) + data class Quote(val linkedEventId: String, override val text: String) : UserDraft(text) + data class Edit(val linkedEventId: String, override val text: String) : UserDraft(text) + data class Reply(val linkedEventId: String, override val text: String) : UserDraft(text) fun isValid(): Boolean { return when (this) { - is REGULAR -> text.isNotBlank() + is Regular -> text.isNotBlank() else -> true } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/DraftMapper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/DraftMapper.kt index 148f727ba7..426c52f9ef 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/DraftMapper.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/DraftMapper.kt @@ -26,20 +26,20 @@ internal object DraftMapper { fun map(entity: DraftEntity): UserDraft { return when (entity.draftMode) { - DraftEntity.MODE_REGULAR -> UserDraft.REGULAR(entity.content) - DraftEntity.MODE_EDIT -> UserDraft.EDIT(entity.linkedEventId, entity.content) - DraftEntity.MODE_QUOTE -> UserDraft.QUOTE(entity.linkedEventId, entity.content) - DraftEntity.MODE_REPLY -> UserDraft.REPLY(entity.linkedEventId, entity.content) + DraftEntity.MODE_REGULAR -> UserDraft.Regular(entity.content) + DraftEntity.MODE_EDIT -> UserDraft.Edit(entity.linkedEventId, entity.content) + DraftEntity.MODE_QUOTE -> UserDraft.Quote(entity.linkedEventId, entity.content) + DraftEntity.MODE_REPLY -> UserDraft.Reply(entity.linkedEventId, entity.content) else -> null - } ?: UserDraft.REGULAR("") + } ?: UserDraft.Regular("") } fun map(domain: UserDraft): DraftEntity { return when (domain) { - is UserDraft.REGULAR -> DraftEntity(content = domain.text, draftMode = DraftEntity.MODE_REGULAR, linkedEventId = "") - is UserDraft.EDIT -> DraftEntity(content = domain.text, draftMode = DraftEntity.MODE_EDIT, linkedEventId = domain.linkedEventId) - is UserDraft.QUOTE -> DraftEntity(content = domain.text, draftMode = DraftEntity.MODE_QUOTE, linkedEventId = domain.linkedEventId) - is UserDraft.REPLY -> DraftEntity(content = domain.text, draftMode = DraftEntity.MODE_REPLY, linkedEventId = domain.linkedEventId) + is UserDraft.Regular -> DraftEntity(content = domain.text, draftMode = DraftEntity.MODE_REGULAR, linkedEventId = "") + is UserDraft.Edit -> DraftEntity(content = domain.text, draftMode = DraftEntity.MODE_EDIT, linkedEventId = domain.linkedEventId) + is UserDraft.Quote -> DraftEntity(content = domain.text, draftMode = DraftEntity.MODE_QUOTE, linkedEventId = domain.linkedEventId) + is UserDraft.Reply -> DraftEntity(content = domain.text, draftMode = DraftEntity.MODE_REPLY, linkedEventId = domain.linkedEventId) } } } 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 8af2278196..d8f1846d62 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 @@ -391,10 +391,10 @@ class RoomDetailFragment @Inject constructor( return@onEach } when (mode) { - is SendMode.REGULAR -> renderRegularMode(mode.text) - is SendMode.EDIT -> renderSpecialMode(mode.timelineEvent, R.drawable.ic_edit, R.string.edit, mode.text) - is SendMode.QUOTE -> renderSpecialMode(mode.timelineEvent, R.drawable.ic_quote, R.string.quote, mode.text) - is SendMode.REPLY -> renderSpecialMode(mode.timelineEvent, R.drawable.ic_reply, R.string.reply, mode.text) + is SendMode.Regular -> renderRegularMode(mode.text) + is SendMode.Edit -> renderSpecialMode(mode.timelineEvent, R.drawable.ic_edit, R.string.edit, mode.text) + is SendMode.Quote -> renderSpecialMode(mode.timelineEvent, R.drawable.ic_quote, R.string.quote, mode.text) + is SendMode.Reply -> renderSpecialMode(mode.timelineEvent, R.drawable.ic_reply, R.string.reply, mode.text) } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt index b9932e32ee..6940fb58db 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt @@ -120,7 +120,7 @@ class MessageComposerViewModel @AssistedInject constructor( } private fun updateIsSendButtonVisibility(triggerAnimation: Boolean) = setState { - val isSendButtonVisible = isComposerVisible && (sendMode !is SendMode.REGULAR || currentComposerText.isNotBlank()) + val isSendButtonVisible = isComposerVisible && (sendMode !is SendMode.Regular || currentComposerText.isNotBlank()) if (this.isSendButtonVisible != isSendButtonVisible && triggerAnimation) { _viewEvents.post(MessageComposerViewEvents.AnimateSendButtonVisibility(isSendButtonVisible)) } @@ -128,12 +128,12 @@ class MessageComposerViewModel @AssistedInject constructor( } private fun handleEnterRegularMode(action: MessageComposerAction.EnterRegularMode) = setState { - copy(sendMode = SendMode.REGULAR(action.text, action.fromSharing)) + copy(sendMode = SendMode.Regular(action.text, action.fromSharing)) } private fun handleEnterEditMode(action: MessageComposerAction.EnterEditMode) { room.getTimeLineEvent(action.eventId)?.let { timelineEvent -> - setState { copy(sendMode = SendMode.EDIT(timelineEvent, timelineEvent.getTextEditableContent())) } + setState { copy(sendMode = SendMode.Edit(timelineEvent, timelineEvent.getTextEditableContent())) } } } @@ -147,20 +147,20 @@ class MessageComposerViewModel @AssistedInject constructor( private fun handleEnterQuoteMode(action: MessageComposerAction.EnterQuoteMode) { room.getTimeLineEvent(action.eventId)?.let { timelineEvent -> - setState { copy(sendMode = SendMode.QUOTE(timelineEvent, action.text)) } + setState { copy(sendMode = SendMode.Quote(timelineEvent, action.text)) } } } private fun handleEnterReplyMode(action: MessageComposerAction.EnterReplyMode) { room.getTimeLineEvent(action.eventId)?.let { timelineEvent -> - setState { copy(sendMode = SendMode.REPLY(timelineEvent, action.text)) } + setState { copy(sendMode = SendMode.Reply(timelineEvent, action.text)) } } } private fun handleSendMessage(action: MessageComposerAction.SendMessage) { withState { state -> when (state.sendMode) { - is SendMode.REGULAR -> { + is SendMode.Regular -> { when (val slashCommandResult = CommandParser.parseSplashCommand(action.text)) { is ParsedCommand.ErrorNotACommand -> { // Send the text message to the room @@ -382,7 +382,7 @@ class MessageComposerViewModel @AssistedInject constructor( } }.exhaustive } - is SendMode.EDIT -> { + is SendMode.Edit -> { // is original event a reply? val inReplyTo = state.sendMode.timelineEvent.getRelationContent()?.inReplyTo?.eventId if (inReplyTo != null) { @@ -405,7 +405,7 @@ class MessageComposerViewModel @AssistedInject constructor( _viewEvents.post(MessageComposerViewEvents.MessageSent) popDraft() } - is SendMode.QUOTE -> { + is SendMode.Quote -> { val messageContent = state.sendMode.timelineEvent.getLastMessageContent() val textMsg = messageContent?.body @@ -426,7 +426,7 @@ class MessageComposerViewModel @AssistedInject constructor( _viewEvents.post(MessageComposerViewEvents.MessageSent) popDraft() } - is SendMode.REPLY -> { + is SendMode.Reply -> { state.sendMode.timelineEvent.let { room.replyToMessage(it, action.text.toString(), action.autoMarkdown) _viewEvents.post(MessageComposerViewEvents.MessageSent) @@ -438,12 +438,12 @@ class MessageComposerViewModel @AssistedInject constructor( } private fun popDraft() = withState { - if (it.sendMode is SendMode.REGULAR && it.sendMode.fromSharing) { + if (it.sendMode is SendMode.Regular && it.sendMode.fromSharing) { // If we were sharing, we want to get back our last value from draft loadDraftIfAny() } else { // Otherwise we clear the composer and remove the draft from db - setState { copy(sendMode = SendMode.REGULAR("", false)) } + setState { copy(sendMode = SendMode.Regular("", false)) } viewModelScope.launch { room.deleteDraft() } @@ -456,24 +456,24 @@ class MessageComposerViewModel @AssistedInject constructor( copy( // Create a sendMode from a draft and retrieve the TimelineEvent sendMode = when (currentDraft) { - is UserDraft.REGULAR -> SendMode.REGULAR(currentDraft.text, false) - is UserDraft.QUOTE -> { + is UserDraft.Regular -> SendMode.Regular(currentDraft.text, false) + is UserDraft.Quote -> { room.getTimeLineEvent(currentDraft.linkedEventId)?.let { timelineEvent -> - SendMode.QUOTE(timelineEvent, currentDraft.text) + SendMode.Quote(timelineEvent, currentDraft.text) } } - is UserDraft.REPLY -> { + is UserDraft.Reply -> { room.getTimeLineEvent(currentDraft.linkedEventId)?.let { timelineEvent -> - SendMode.REPLY(timelineEvent, currentDraft.text) + SendMode.Reply(timelineEvent, currentDraft.text) } } - is UserDraft.EDIT -> { + is UserDraft.Edit -> { room.getTimeLineEvent(currentDraft.linkedEventId)?.let { timelineEvent -> - SendMode.EDIT(timelineEvent, currentDraft.text) + SendMode.Edit(timelineEvent, currentDraft.text) } } - else -> null - } ?: SendMode.REGULAR("", fromSharing = false) + else -> null + } ?: SendMode.Regular("", fromSharing = false) ) } } @@ -679,21 +679,21 @@ class MessageComposerViewModel @AssistedInject constructor( private fun handleSaveDraft(action: MessageComposerAction.SaveDraft) = withState { session.coroutineScope.launch { when { - it.sendMode is SendMode.REGULAR && !it.sendMode.fromSharing -> { + it.sendMode is SendMode.Regular && !it.sendMode.fromSharing -> { setState { copy(sendMode = it.sendMode.copy(action.draft)) } - room.saveDraft(UserDraft.REGULAR(action.draft)) + room.saveDraft(UserDraft.Regular(action.draft)) } - it.sendMode is SendMode.REPLY -> { + it.sendMode is SendMode.Reply -> { setState { copy(sendMode = it.sendMode.copy(text = action.draft)) } - room.saveDraft(UserDraft.REPLY(it.sendMode.timelineEvent.root.eventId!!, action.draft)) + room.saveDraft(UserDraft.Reply(it.sendMode.timelineEvent.root.eventId!!, action.draft)) } - it.sendMode is SendMode.QUOTE -> { + it.sendMode is SendMode.Quote -> { setState { copy(sendMode = it.sendMode.copy(text = action.draft)) } - room.saveDraft(UserDraft.QUOTE(it.sendMode.timelineEvent.root.eventId!!, action.draft)) + room.saveDraft(UserDraft.Quote(it.sendMode.timelineEvent.root.eventId!!, action.draft)) } - it.sendMode is SendMode.EDIT -> { + it.sendMode is SendMode.Edit -> { setState { copy(sendMode = it.sendMode.copy(text = action.draft)) } - room.saveDraft(UserDraft.EDIT(it.sendMode.timelineEvent.root.eventId!!, action.draft)) + room.saveDraft(UserDraft.Edit(it.sendMode.timelineEvent.root.eventId!!, action.draft)) } } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewState.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewState.kt index def1c8d2fb..d16e6aac38 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewState.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewState.kt @@ -30,23 +30,23 @@ import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent * Depending on the state the bottom toolbar will change (icons/preview/actions...) */ sealed class SendMode(open val text: String) { - data class REGULAR( + data class Regular( override val text: String, val fromSharing: Boolean, // This is necessary for forcing refresh on selectSubscribe private val ts: Long = System.currentTimeMillis() ) : SendMode(text) - data class QUOTE(val timelineEvent: TimelineEvent, override val text: String) : SendMode(text) - data class EDIT(val timelineEvent: TimelineEvent, override val text: String) : SendMode(text) - data class REPLY(val timelineEvent: TimelineEvent, override val text: String) : SendMode(text) + data class Quote(val timelineEvent: TimelineEvent, override val text: String) : SendMode(text) + data class Edit(val timelineEvent: TimelineEvent, override val text: String) : SendMode(text) + data class Reply(val timelineEvent: TimelineEvent, override val text: String) : SendMode(text) } data class MessageComposerViewState( val roomId: String, val canSendMessage: Boolean = true, val isSendButtonVisible: Boolean = false, - val sendMode: SendMode = SendMode.REGULAR("", false), + val sendMode: SendMode = SendMode.Regular("", false), val voiceRecordingUiState: VoiceMessageRecorderView.RecordingUiState = VoiceMessageRecorderView.RecordingUiState.None ) : MavericksState { From 70d25653c8d3571d2af6648d9352b1dc8c9264cf Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 23 Nov 2021 18:21:42 +0000 Subject: [PATCH 2/3] removing unused base property from the sealed classes and switching to interfaces --- .../android/sdk/api/session/room/send/UserDraft.kt | 10 +++++----- .../room/detail/composer/MessageComposerViewState.kt | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/send/UserDraft.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/send/UserDraft.kt index 1f2f91c0ec..073f5c0613 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/send/UserDraft.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/send/UserDraft.kt @@ -23,11 +23,11 @@ package org.matrix.android.sdk.api.session.room.send * EDIT: draft of an edition of a message * REPLY: draft of a reply of another message */ -sealed class UserDraft(open val text: String) { - data class Regular(override val text: String) : UserDraft(text) - data class Quote(val linkedEventId: String, override val text: String) : UserDraft(text) - data class Edit(val linkedEventId: String, override val text: String) : UserDraft(text) - data class Reply(val linkedEventId: String, override val text: String) : UserDraft(text) +sealed interface UserDraft { + data class Regular(val text: String) : UserDraft + data class Quote(val linkedEventId: String, val text: String) : UserDraft + data class Edit(val linkedEventId: String, val text: String) : UserDraft + data class Reply(val linkedEventId: String, val text: String) : UserDraft fun isValid(): Boolean { return when (this) { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewState.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewState.kt index d16e6aac38..7f15b0fe17 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewState.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewState.kt @@ -29,17 +29,17 @@ import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent * * Depending on the state the bottom toolbar will change (icons/preview/actions...) */ -sealed class SendMode(open val text: String) { +sealed interface SendMode { data class Regular( - override val text: String, + val text: String, val fromSharing: Boolean, // This is necessary for forcing refresh on selectSubscribe private val ts: Long = System.currentTimeMillis() - ) : SendMode(text) + ) : SendMode - data class Quote(val timelineEvent: TimelineEvent, override val text: String) : SendMode(text) - data class Edit(val timelineEvent: TimelineEvent, override val text: String) : SendMode(text) - data class Reply(val timelineEvent: TimelineEvent, override val text: String) : SendMode(text) + data class Quote(val timelineEvent: TimelineEvent, val text: String) : SendMode + data class Edit(val timelineEvent: TimelineEvent, val text: String) : SendMode + data class Reply(val timelineEvent: TimelineEvent, val text: String) : SendMode } data class MessageComposerViewState( From 6838e701b57925b3fa60193b7348e284212eb766 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 23 Nov 2021 18:22:47 +0000 Subject: [PATCH 3/3] reformating --- .../detail/composer/MessageComposerViewModel.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt index 6940fb58db..7ccee0220c 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerViewModel.kt @@ -405,7 +405,7 @@ class MessageComposerViewModel @AssistedInject constructor( _viewEvents.post(MessageComposerViewEvents.MessageSent) popDraft() } - is SendMode.Quote -> { + is SendMode.Quote -> { val messageContent = state.sendMode.timelineEvent.getLastMessageContent() val textMsg = messageContent?.body @@ -426,7 +426,7 @@ class MessageComposerViewModel @AssistedInject constructor( _viewEvents.post(MessageComposerViewEvents.MessageSent) popDraft() } - is SendMode.Reply -> { + is SendMode.Reply -> { state.sendMode.timelineEvent.let { room.replyToMessage(it, action.text.toString(), action.autoMarkdown) _viewEvents.post(MessageComposerViewEvents.MessageSent) @@ -457,22 +457,22 @@ class MessageComposerViewModel @AssistedInject constructor( // Create a sendMode from a draft and retrieve the TimelineEvent sendMode = when (currentDraft) { is UserDraft.Regular -> SendMode.Regular(currentDraft.text, false) - is UserDraft.Quote -> { + is UserDraft.Quote -> { room.getTimeLineEvent(currentDraft.linkedEventId)?.let { timelineEvent -> SendMode.Quote(timelineEvent, currentDraft.text) } } - is UserDraft.Reply -> { + is UserDraft.Reply -> { room.getTimeLineEvent(currentDraft.linkedEventId)?.let { timelineEvent -> SendMode.Reply(timelineEvent, currentDraft.text) } } - is UserDraft.Edit -> { + is UserDraft.Edit -> { room.getTimeLineEvent(currentDraft.linkedEventId)?.let { timelineEvent -> SendMode.Edit(timelineEvent, currentDraft.text) } } - else -> null + else -> null } ?: SendMode.Regular("", fromSharing = false) ) } @@ -691,7 +691,7 @@ class MessageComposerViewModel @AssistedInject constructor( setState { copy(sendMode = it.sendMode.copy(text = action.draft)) } room.saveDraft(UserDraft.Quote(it.sendMode.timelineEvent.root.eventId!!, action.draft)) } - it.sendMode is SendMode.Edit -> { + it.sendMode is SendMode.Edit -> { setState { copy(sendMode = it.sendMode.copy(text = action.draft)) } room.saveDraft(UserDraft.Edit(it.sendMode.timelineEvent.root.eventId!!, action.draft)) }