-
Notifications
You must be signed in to change notification settings - Fork 782
[Rich text editor] Add plain text mode and new attachment UI #7459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jmartinesp
merged 15 commits into
resilience-rc
from
feat/PSU-780-plain-text-rebase-resilience-rc
Oct 26, 2022
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
95cdebc
Add new attachments selection dialog
jonnyandrew 3789587
Add rounded corners to bottom sheet dialog.
jonnyandrew 02d6c7c
Add changelog entry
jonnyandrew 36824d6
Remove redundant call to superclass click listener
jonnyandrew 0418b9a
Refactor to use view visibility helper
jonnyandrew dab7e7e
Change redundant sealed class to interface
jonnyandrew d87b109
Remove unused string
jonnyandrew 1da1dca
Revert "Add rounded corners to bottom sheet dialog."
jonnyandrew 4baaf2b
Remove redundant view group
jonnyandrew 1ee7590
Remove redundant `this`
jonnyandrew dcb34bc
Update rich text editor to latest
jonnyandrew 7bde407
Update rich text editor version
jonnyandrew 718ea37
Allow toggling rich text in the new editor
jonnyandrew 78b4f2f
Persist the text formatting setting
jonnyandrew 2b7177b
Add changelog entry
jonnyandrew File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add new UI for selecting an attachment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[Rich text editor] Add plain text mode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
vector/src/main/java/im/vector/app/features/attachments/AttachmentType.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2022 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.app.features.attachments | ||
|
||
import im.vector.app.core.utils.PERMISSIONS_EMPTY | ||
import im.vector.app.core.utils.PERMISSIONS_FOR_FOREGROUND_LOCATION_SHARING | ||
import im.vector.app.core.utils.PERMISSIONS_FOR_PICKING_CONTACT | ||
import im.vector.app.core.utils.PERMISSIONS_FOR_TAKING_PHOTO | ||
import im.vector.app.core.utils.PERMISSIONS_FOR_VOICE_BROADCAST | ||
|
||
/** | ||
* The all possible types to pick with their required permissions. | ||
*/ | ||
enum class AttachmentType(val permissions: List<String>) { | ||
CAMERA(PERMISSIONS_FOR_TAKING_PHOTO), | ||
GALLERY(PERMISSIONS_EMPTY), | ||
FILE(PERMISSIONS_EMPTY), | ||
STICKER(PERMISSIONS_EMPTY), | ||
CONTACT(PERMISSIONS_FOR_PICKING_CONTACT), | ||
POLL(PERMISSIONS_EMPTY), | ||
LOCATION(PERMISSIONS_FOR_FOREGROUND_LOCATION_SHARING), | ||
VOICE_BROADCAST(PERMISSIONS_FOR_VOICE_BROADCAST), | ||
} |
92 changes: 92 additions & 0 deletions
92
vector/src/main/java/im/vector/app/features/attachments/AttachmentTypeSelectorBottomSheet.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (c) 2022 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.app.features.attachments | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.core.view.isVisible | ||
import androidx.fragment.app.FragmentManager | ||
import androidx.fragment.app.viewModels | ||
import com.airbnb.mvrx.parentFragmentViewModel | ||
import com.airbnb.mvrx.withState | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import im.vector.app.R | ||
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment | ||
import im.vector.app.databinding.BottomSheetAttachmentTypeSelectorBinding | ||
import im.vector.app.features.home.room.detail.TimelineViewModel | ||
|
||
@AndroidEntryPoint | ||
class AttachmentTypeSelectorBottomSheet : VectorBaseBottomSheetDialogFragment<BottomSheetAttachmentTypeSelectorBinding>() { | ||
|
||
private val viewModel: AttachmentTypeSelectorViewModel by parentFragmentViewModel() | ||
private val timelineViewModel: TimelineViewModel by parentFragmentViewModel() | ||
private val sharedActionViewModel: AttachmentTypeSelectorSharedActionViewModel by viewModels( | ||
ownerProducer = { requireParentFragment() } | ||
) | ||
|
||
override val showExpanded = true | ||
|
||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetAttachmentTypeSelectorBinding { | ||
return BottomSheetAttachmentTypeSelectorBinding.inflate(inflater, container, false) | ||
} | ||
|
||
override fun invalidate() = withState(viewModel, timelineViewModel) { viewState, timelineState -> | ||
super.invalidate() | ||
views.location.isVisible = viewState.isLocationVisible | ||
views.voiceBroadcast.isVisible = viewState.isVoiceBroadcastVisible | ||
views.poll.isVisible = !timelineState.isThreadTimeline() | ||
views.textFormatting.isChecked = viewState.isTextFormattingEnabled | ||
views.textFormatting.setCompoundDrawablesRelativeWithIntrinsicBounds( | ||
if (viewState.isTextFormattingEnabled) { | ||
R.drawable.ic_text_formatting | ||
} else { | ||
R.drawable.ic_text_formatting_disabled | ||
}, 0, 0, 0 | ||
) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
views.gallery.debouncedClicks { onAttachmentSelected(AttachmentType.GALLERY) } | ||
views.stickers.debouncedClicks { onAttachmentSelected(AttachmentType.STICKER) } | ||
views.file.debouncedClicks { onAttachmentSelected(AttachmentType.FILE) } | ||
views.voiceBroadcast.debouncedClicks { onAttachmentSelected(AttachmentType.VOICE_BROADCAST) } | ||
views.poll.debouncedClicks { onAttachmentSelected(AttachmentType.POLL) } | ||
views.location.debouncedClicks { onAttachmentSelected(AttachmentType.LOCATION) } | ||
views.camera.debouncedClicks { onAttachmentSelected(AttachmentType.CAMERA) } | ||
views.contact.debouncedClicks { onAttachmentSelected(AttachmentType.CONTACT) } | ||
views.textFormatting.setOnCheckedChangeListener { _, isChecked -> onTextFormattingToggled(isChecked) } | ||
} | ||
|
||
private fun onAttachmentSelected(attachmentType: AttachmentType) { | ||
val action = AttachmentTypeSelectorSharedAction.SelectAttachmentTypeAction(attachmentType) | ||
sharedActionViewModel.post(action) | ||
dismiss() | ||
} | ||
|
||
private fun onTextFormattingToggled(isEnabled: Boolean) = | ||
viewModel.handle(AttachmentTypeSelectorAction.ToggleTextFormatting(isEnabled)) | ||
|
||
companion object { | ||
fun show(fragmentManager: FragmentManager) { | ||
val bottomSheet = AttachmentTypeSelectorBottomSheet() | ||
bottomSheet.show(fragmentManager, "AttachmentTypeSelectorBottomSheet") | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...in/java/im/vector/app/features/attachments/AttachmentTypeSelectorSharedActionViewModel.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2022 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.app.features.attachments | ||
|
||
import im.vector.app.core.platform.VectorSharedAction | ||
import im.vector.app.core.platform.VectorSharedActionViewModel | ||
import javax.inject.Inject | ||
|
||
class AttachmentTypeSelectorSharedActionViewModel @Inject constructor() : | ||
VectorSharedActionViewModel<AttachmentTypeSelectorSharedAction>() | ||
|
||
sealed interface AttachmentTypeSelectorSharedAction : VectorSharedAction { | ||
data class SelectAttachmentTypeAction( | ||
val attachmentType: AttachmentType | ||
) : AttachmentTypeSelectorSharedAction | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null
as the view root (needed to resolve layout parameters on the inflated layout's root element)null
as the view root (needed to resolve layout parameters on the inflated layout's root element)null
as the view root (needed to resolve layout parameters on the inflated layout's root element)null
as the view root (needed to resolve layout parameters on the inflated layout's root element)