Skip to content

Commit 920489a

Browse files
committed
Change RTE layout based on plain text / rich text mode
1 parent cf5b96f commit 920489a

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

changelog.d/7620.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make the plain text mode layout of the RTE more compact.

vector/src/main/java/im/vector/app/features/home/room/detail/composer/RichTextComposerLayout.kt

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import android.widget.ImageButton
3434
import android.widget.LinearLayout
3535
import androidx.annotation.DrawableRes
3636
import androidx.annotation.StringRes
37+
import androidx.constraintlayout.widget.ConstraintSet
3738
import androidx.core.text.toSpannable
3839
import androidx.core.view.isGone
3940
import androidx.core.view.isInvisible
@@ -72,6 +73,11 @@ class RichTextComposerLayout @JvmOverloads constructor(
7273
field = value
7374
updateTextFieldBorder(isFullScreen)
7475
updateEditTextVisibility()
76+
updateFullScreenButtonVisibility()
77+
// If formatting is no longer enabled and it's in full screen, minimise the editor
78+
if (!value && isFullScreen) {
79+
callback?.onFullScreenModeChanged()
80+
}
7581
}
7682

7783
override val text: Editable?
@@ -191,8 +197,7 @@ class RichTextComposerLayout @JvmOverloads constructor(
191197
}
192198

193199
views.composerFullScreenButton.apply {
194-
// There's no point in having full screen in landscape since there's almost no vertical space
195-
isInvisible = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
200+
updateFullScreenButtonVisibility()
196201
setOnClickListener {
197202
callback?.onFullScreenModeChanged()
198203
}
@@ -254,6 +259,33 @@ class RichTextComposerLayout @JvmOverloads constructor(
254259
views.richTextComposerEditText.isVisible = isTextFormattingEnabled
255260
views.richTextMenu.isVisible = isTextFormattingEnabled
256261
views.plainTextComposerEditText.isVisible = !isTextFormattingEnabled
262+
263+
// The layouts for formatted text mode and plain text mode are different, so we need to update the constraints
264+
val dp = { px: Int -> (px * resources.displayMetrics.density).toInt() }
265+
ConstraintSet().apply {
266+
clone(views.composerLayoutContent)
267+
clear(R.id.composerEditTextOuterBorder, ConstraintSet.TOP)
268+
clear(R.id.composerEditTextOuterBorder, ConstraintSet.BOTTOM)
269+
clear(R.id.composerEditTextOuterBorder, ConstraintSet.START)
270+
clear(R.id.composerEditTextOuterBorder, ConstraintSet.END)
271+
if (isTextFormattingEnabled) {
272+
connect(R.id.composerEditTextOuterBorder, ConstraintSet.TOP, R.id.composerLayoutContent, ConstraintSet.TOP, dp(8))
273+
connect(R.id.composerEditTextOuterBorder, ConstraintSet.BOTTOM, R.id.sendButton, ConstraintSet.TOP, 0)
274+
connect(R.id.composerEditTextOuterBorder, ConstraintSet.START, R.id.composerLayoutContent, ConstraintSet.START, dp(12))
275+
connect(R.id.composerEditTextOuterBorder, ConstraintSet.END, R.id.composerLayoutContent, ConstraintSet.END, dp(12))
276+
} else {
277+
connect(R.id.composerEditTextOuterBorder, ConstraintSet.TOP, R.id.composerLayoutContent, ConstraintSet.TOP, dp(10))
278+
connect(R.id.composerEditTextOuterBorder, ConstraintSet.BOTTOM, R.id.composerLayoutContent, ConstraintSet.BOTTOM, dp(10))
279+
connect(R.id.composerEditTextOuterBorder, ConstraintSet.START, R.id.attachmentButton, ConstraintSet.END, 0)
280+
connect(R.id.composerEditTextOuterBorder, ConstraintSet.END, R.id.sendButton, ConstraintSet.START, 0)
281+
}
282+
applyTo(views.composerLayoutContent)
283+
}
284+
}
285+
286+
private fun updateFullScreenButtonVisibility() {
287+
// There's no point in having full screen in landscape since there's almost no vertical space
288+
views.composerFullScreenButton.isInvisible = !isTextFormattingEnabled || resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
257289
}
258290

259291
/**

vector/src/main/res/layout/composer_rich_text_layout.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
</FrameLayout>
2727

2828
<androidx.constraintlayout.widget.ConstraintLayout
29+
android:id="@+id/composerLayoutContent"
2930
android:layout_width="match_parent"
3031
android:layout_height="match_parent">
3132

0 commit comments

Comments
 (0)