Skip to content
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

Apply design changes to WYSIWYG editor #7354

Merged
merged 6 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/7354.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update WYSIWYG editor designs.
8 changes: 7 additions & 1 deletion library/ui-strings/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@
<string name="labs_enable_deferred_dm_summary">Create DM only on first message</string>

<string name="labs_enable_rich_text_editor_title">Enable rich text editor</string>
<string name="labs_enable_rich_text_editor_summary">Use a rich text editor to send formatted messages</string>
<string name="labs_enable_rich_text_editor_summary">Try out the rich text editor (plain text mode coming soon)</string>

<!-- Home fragment -->
<string name="invitations_header">Invites</string>
Expand Down Expand Up @@ -3358,4 +3358,10 @@
<string name="onboarding_new_app_layout_feedback_message">Tap top right to see the option to feedback.</string>
<string name="onboarding_new_app_layout_button_try">Try it out</string>

<!-- WYSIWYG Composer -->
<string name="rich_text_editor_format_bold">Apply bold format</string>
<string name="rich_text_editor_format_italic">Apply italic format</string>
<string name="rich_text_editor_format_strikethrough">Apply strikethrough format</string>
<string name="rich_text_editor_format_underline">Apply underline format</string>

</resources>
5 changes: 5 additions & 0 deletions library/ui-styles/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,9 @@
<color name="vctr_badge_color_border_light">@color/palette_white</color>
<color name="vctr_badge_color_border_dark">@color/palette_black_950</color>

<!-- WYSIWYG Colors -->
<attr name="vctr_rich_text_editor_menu_button_background" format="color" />
<color name="vctr_rich_text_editor_menu_button_background_light">#EEF8F4</color>
<color name="vctr_rich_text_editor_menu_button_background_dark">#1D292A</color>

</resources>
3 changes: 2 additions & 1 deletion library/ui-styles/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
<dimen name="composer_min_height">56dp</dimen>
<dimen name="composer_attachment_size">52dp</dimen>
<dimen name="composer_attachment_margin">1dp</dimen>

<dimen name="rich_text_composer_corner_radius_single_line">28dp</dimen>
<dimen name="rich_text_composer_corner_radius_expanded">14dp</dimen>

<dimen name="chat_bubble_margin_start">28dp</dimen>
<dimen name="chat_bubble_margin_end">6dp</dimen>
Expand Down
12 changes: 11 additions & 1 deletion library/ui-styles/src/main/res/values/styles_edit_text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,14 @@
<item name="android:textColor">?vctr_message_text_color</item>
</style>

</resources>
<style name="Widget.Vector.EditText.RichTextComposer" parent="Widget.AppCompat.EditText">
<item name="android:background">@android:color/transparent</item>
<item name="android:inputType">textCapSentences|textMultiLine</item>
<item name="android:maxLines">12</item>
<item name="android:minHeight">20dp</item>
<item name="android:padding">0dp</item>
<item name="android:textSize">15sp</item>
<item name="android:textColor">?vctr_message_text_color</item>
</style>

</resources>
3 changes: 3 additions & 0 deletions library/ui-styles/src/main/res/values/theme_dark.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@

<!-- Material 3 -->
<item name="collapsingToolbarLayoutMediumSize">@dimen/collapsing_toolbar_layout_medium_size</item>

<!-- WYSIWYG Editor -->
<item name="vctr_rich_text_editor_menu_button_background">@color/vctr_rich_text_editor_menu_button_background_dark</item>
</style>

<style name="Theme.Vector.Dark" parent="Base.Theme.Vector.Dark" />
Expand Down
3 changes: 3 additions & 0 deletions library/ui-styles/src/main/res/values/theme_light.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@

<!-- Material 3 -->
<item name="collapsingToolbarLayoutMediumSize">@dimen/collapsing_toolbar_layout_medium_size</item>

<!-- WYSIWYG Editor -->
<item name="vctr_rich_text_editor_menu_button_background">@color/vctr_rich_text_editor_menu_button_background_light</item>
</style>

<style name="Theme.Vector.Light" parent="Base.Theme.Vector.Light" />
Expand Down
6 changes: 5 additions & 1 deletion vector-app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,8 @@

-keep class org.bouncycastle.** { *; }
-keepnames class org.bouncycastle.** { *; }
-dontwarn org.bouncycastle.**
-dontwarn org.bouncycastle.**

# JNA
-keep class com.sun.jna.** { *; }
-keep class * implements com.sun.jna.** { *; }
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import android.widget.ImageButton
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import androidx.core.text.toSpannable
Expand All @@ -42,7 +43,10 @@ import im.vector.app.core.animations.SimpleTransitionListener
import im.vector.app.core.extensions.setTextIfDifferent
import im.vector.app.databinding.ComposerRichTextLayoutBinding
import im.vector.app.databinding.ViewRichTextMenuButtonBinding
import io.element.android.wysiwyg.EditorEditText
import io.element.android.wysiwyg.InlineFormat
import uniffi.wysiwyg_composer.ComposerAction
import uniffi.wysiwyg_composer.MenuState

class RichTextComposerLayout @JvmOverloads constructor(
context: Context,
Expand Down Expand Up @@ -91,10 +95,18 @@ class RichTextComposerLayout @JvmOverloads constructor(
collapse(false)

views.composerEditText.addTextChangedListener(object : TextWatcher {
private var previousTextWasExpanded = false

override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
override fun afterTextChanged(s: Editable) {
callback?.onTextChanged(s)

val isExpanded = s.lines().count() > 1
if (previousTextWasExpanded != isExpanded) {
updateTextFieldBorder(isExpanded)
}
previousTextWasExpanded = isExpanded
}
})

Expand All @@ -116,32 +128,57 @@ class RichTextComposerLayout @JvmOverloads constructor(
}

private fun setupRichTextMenu() {
addRichTextMenuItem(R.drawable.ic_composer_bold, "Bold") {
addRichTextMenuItem(R.drawable.ic_composer_bold, R.string.rich_text_editor_format_bold, ComposerAction.Bold) {
views.composerEditText.toggleInlineFormat(InlineFormat.Bold)
}
addRichTextMenuItem(R.drawable.ic_composer_italic, "Italic") {
addRichTextMenuItem(R.drawable.ic_composer_italic, R.string.rich_text_editor_format_italic, ComposerAction.Italic) {
views.composerEditText.toggleInlineFormat(InlineFormat.Italic)
}
addRichTextMenuItem(R.drawable.ic_composer_underlined, "Underline") {
addRichTextMenuItem(R.drawable.ic_composer_underlined, R.string.rich_text_editor_format_underline, ComposerAction.Underline) {
views.composerEditText.toggleInlineFormat(InlineFormat.Underline)
}
addRichTextMenuItem(R.drawable.ic_composer_strikethrough, "Strikethrough") {
addRichTextMenuItem(R.drawable.ic_composer_strikethrough, R.string.rich_text_editor_format_strikethrough, ComposerAction.StrikeThrough) {
views.composerEditText.toggleInlineFormat(InlineFormat.StrikeThrough)
}

views.composerEditText.menuStateChangedListener = EditorEditText.OnMenuStateChangedListener { state ->
if (state is MenuState.Update) {
updateMenuStateFor(ComposerAction.Bold, state)
updateMenuStateFor(ComposerAction.Italic, state)
updateMenuStateFor(ComposerAction.Underline, state)
updateMenuStateFor(ComposerAction.StrikeThrough, state)
}
}
}

private fun addRichTextMenuItem(@DrawableRes iconId: Int, description: String, action: () -> Unit) {
private fun addRichTextMenuItem(@DrawableRes iconId: Int, @StringRes description: Int, action: ComposerAction, onClick: () -> Unit) {
val inflater = LayoutInflater.from(context)
val button = ViewRichTextMenuButtonBinding.inflate(inflater, views.richTextMenu, true)
button.root.tag = action
with(button.root) {
contentDescription = description
contentDescription = resources.getString(description)
setImageResource(iconId)
setOnClickListener {
action()
onClick()
}
}
}

private fun updateMenuStateFor(action: ComposerAction, menuState: MenuState.Update) {
val button = findViewWithTag<ImageButton>(action) ?: return
button.isEnabled = !menuState.disabledActions.contains(action)
button.isSelected = menuState.reversedActions.contains(action)
}

private fun updateTextFieldBorder(isExpanded: Boolean) {
val borderResource = if (isExpanded) {
R.drawable.bg_composer_rich_edit_text_expanded
} else {
R.drawable.bg_composer_rich_edit_text_single_line
}
views.composerEditTextOuterBorder.setBackgroundResource(borderResource)
}

override fun replaceFormattedContent(text: CharSequence) {
views.composerEditText.setHtml(text.toString())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class VoiceMessageViews(

fun resetMicButtonUi() {
views.voiceMessageMicButton.isVisible = true
views.voiceMessageMicButton.setImageResource(R.drawable.ic_voice_mic)
views.voiceMessageMicButton.setImageResource(R.drawable.ic_microphone)
views.voiceMessageMicButton.setAttributeBackground(android.R.attr.selectableItemBackgroundBorderless)
views.voiceMessageMicButton.updateLayoutParams<ViewGroup.MarginLayoutParams> {
if (rtlXMultiplier == -1) {
Expand Down
8 changes: 8 additions & 0 deletions vector/src/main/res/color/selector_rich_text_menu_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="?attr/vctr_content_quinary" />
<item android:state_pressed="true" android:color="?attr/colorSecondary" />
<item android:state_hovered="true" android:color="?attr/colorSecondary" />
<item android:state_selected="true" android:color="?attr/colorSecondary" />
<item android:color="?attr/vctr_content_tertiary" />
</selector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<solid android:color="@android:color/transparent" />

<stroke
android:width="1dp"
android:color="?vctr_content_quaternary" />

<corners android:radius="@dimen/rich_text_composer_corner_radius_expanded" />

</shape>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<solid android:color="@android:color/transparent" />

<stroke
android:width="1dp"
android:color="?vctr_content_quaternary" />

<corners android:radius="@dimen/rich_text_composer_corner_radius_single_line" />

</shape>
18 changes: 18 additions & 0 deletions vector/src/main/res/drawable/bg_rich_text_menu_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_hovered="true">
<shape android:shape="rectangle">
<corners android:radius="8dp" />
<solid android:color="?attr/vctr_rich_text_editor_menu_button_background" />
</shape>
</item>
<item android:state_selected="true">
<shape android:shape="rectangle">
<corners android:radius="8dp" />
<solid android:color="?attr/vctr_rich_text_editor_menu_button_background" />
</shape>
</item>
<item>
<ripple android:color="?attr/vctr_rich_text_editor_menu_button_background" />
</item>
</selector>
9 changes: 9 additions & 0 deletions vector/src/main/res/drawable/ic_microphone.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M12,15C13.66,15 14.99,13.66 14.99,12L15,6C15,4.34 13.66,3 12,3C10.34,3 9,4.34 9,6V12C9,13.66 10.34,15 12,15ZM18.08,12C17.66,12 17.31,12.3 17.25,12.71C16.88,15.32 14.53,17.1 12,17.1C9.47,17.1 7.12,15.33 6.75,12.71C6.69,12.3 6.33,12 5.92,12C5.4,12 5,12.46 5.07,12.97C5.53,15.94 8.03,18.27 11,18.72V21C11,21.55 11.45,22 12,22C12.55,22 13,21.55 13,21V18.72C15.96,18.29 18.47,15.94 18.93,12.97C19,12.46 18.6,12 18.08,12Z"
android:fillColor="#8D97A5"/>
</vector>
12 changes: 0 additions & 12 deletions vector/src/main/res/drawable/ic_voice_mic.xml

This file was deleted.

6 changes: 4 additions & 2 deletions vector/src/main/res/layout/composer_rich_text_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
android:id="@+id/attachmentButton"
android:layout_width="0dp"
android:layout_height="0dp"
android:paddingTop="2dp"
android:background="?android:attr/selectableItemBackground"
android:contentDescription="@string/option_send_files"
android:src="@drawable/ic_attachment"
Expand All @@ -100,16 +101,17 @@
android:id="@+id/composerEditTextOuterBorder"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/bg_composer_edit_text" />
android:background="@drawable/bg_composer_rich_edit_text_single_line" />

<io.element.android.wysiwyg.EditorEditText
android:id="@+id/composerEditText"
style="@style/Widget.Vector.EditText.Composer"
style="@style/Widget.Vector.EditText.RichTextComposer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:nextFocusLeft="@id/composerEditText"
android:nextFocusUp="@id/composerEditText"
tools:hint="@string/room_message_placeholder"
tools:text="@tools:sample/lorem/random"
tools:ignore="MissingConstraints" />

<ImageButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,28 +124,30 @@
android:id="@+id/composerEditTextOuterBorder"
android:layout_width="0dp"
android:layout_height="0dp"
android:minHeight="40dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="@id/composerEditText"
app:layout_constraintStart_toStartOf="@id/composerEditText"
app:layout_constraintEnd_toEndOf="@id/composerEditText"
app:layout_constraintTop_toTopOf="@id/composerEditText"
app:layout_goneMarginEnd="12dp" />
android:layout_marginHorizontal="12dp"
android:background="@drawable/bg_composer_rich_edit_text_single_line"
app:layout_constraintVertical_bias="0"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/sendButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<io.element.android.wysiwyg.EditorEditText
android:id="@+id/composerEditText"
style="@style/Widget.Vector.EditText.Composer"
style="@style/Widget.Vector.EditText.RichTextComposer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/room_message_placeholder"
android:nextFocusLeft="@id/composerEditText"
android:nextFocusUp="@id/composerEditText"
android:layout_marginHorizontal="10dp"
app:layout_constraintVertical_bias="0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginHorizontal="12dp"
android:layout_marginVertical="10dp"
app:layout_constraintBottom_toBottomOf="@id/composerEditTextOuterBorder"
app:layout_constraintEnd_toEndOf="@id/composerEditTextOuterBorder"
app:layout_constraintStart_toStartOf="@id/composerEditTextOuterBorder"
app:layout_constraintTop_toTopOf="@id/composerEditTextOuterBorder"
tools:text="@tools:sample/lorem/random" />

<ImageButton
Expand All @@ -158,7 +160,7 @@
android:scaleType="center"
android:src="@drawable/ic_send"
android:visibility="invisible"
app:layout_constraintTop_toBottomOf="@id/composerEditText"
app:layout_constraintTop_toBottomOf="@id/composerEditTextOuterBorder"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="MissingPrefix"
Expand Down
Loading