diff --git a/CHANGES.md b/CHANGES.md index 05d189ed12..82efc6d089 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,6 +21,7 @@ Bugfix 🐛: - Improve support for image/audio/video/file selection with intent changes (#1376) - Fix Splash layout on small screens - Simplifies draft management and should fix bunch of draft issues (#952, #683) + - Very long topic cannot be fully visible (#1957) Translations 🗣: - diff --git a/vector/src/main/java/im/vector/app/core/epoxy/ExpandableTextItem.kt b/vector/src/main/java/im/vector/app/core/epoxy/ExpandableTextItem.kt new file mode 100644 index 0000000000..3dceec48ef --- /dev/null +++ b/vector/src/main/java/im/vector/app/core/epoxy/ExpandableTextItem.kt @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2020 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.core.epoxy + +import android.animation.ObjectAnimator +import android.text.TextUtils +import android.widget.ImageView +import android.widget.TextView +import androidx.core.view.doOnPreDraw +import androidx.core.view.isVisible +import com.airbnb.epoxy.EpoxyAttribute +import com.airbnb.epoxy.EpoxyModelClass +import im.vector.app.R +import im.vector.app.core.extensions.copyOnLongClick + +@EpoxyModelClass(layout = R.layout.item_expandable_textview) +abstract class ExpandableTextItem : VectorEpoxyModel() { + + @EpoxyAttribute + lateinit var content: String + + @EpoxyAttribute + var maxLines: Int = 3 + + private var isExpanded = false + private var expandedLines = 0 + + override fun bind(holder: Holder) { + super.bind(holder) + holder.content.text = content + holder.content.copyOnLongClick() + + holder.content.doOnPreDraw { + if (holder.content.lineCount > maxLines) { + expandedLines = holder.content.lineCount + holder.content.maxLines = maxLines + + holder.view.setOnClickListener { + if (isExpanded) { + collapse(holder) + } else { + expand(holder) + } + } + holder.arrow.isVisible = true + } else { + holder.arrow.isVisible = false + } + } + } + + private fun expand(holder: Holder) { + ObjectAnimator + .ofInt(holder.content, "maxLines", expandedLines) + .setDuration(200) + .start() + + holder.content.ellipsize = null + holder.arrow.setImageResource(R.drawable.ic_expand_less) + holder.arrow.contentDescription = holder.view.context.getString(R.string.merged_events_collapse) + isExpanded = true + } + + private fun collapse(holder: Holder) { + ObjectAnimator + .ofInt(holder.content, "maxLines", maxLines) + .setDuration(200) + .start() + + holder.content.ellipsize = TextUtils.TruncateAt.END + holder.arrow.setImageResource(R.drawable.ic_expand_more) + holder.arrow.contentDescription = holder.view.context.getString(R.string.merged_events_expand) + isExpanded = false + } + + class Holder : VectorEpoxyHolder() { + val content by bind(R.id.expandableContent) + val arrow by bind(R.id.expandableArrow) + } +} diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt index 160ebd56be..7dc744da31 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt @@ -19,6 +19,7 @@ package im.vector.app.features.roomprofile import com.airbnb.epoxy.TypedEpoxyController import im.vector.app.R +import im.vector.app.core.epoxy.expandableTextItem import im.vector.app.core.epoxy.profiles.buildProfileAction import im.vector.app.core.epoxy.profiles.buildProfileSection import im.vector.app.core.resources.ColorProvider @@ -57,6 +58,20 @@ class RoomProfileController @Inject constructor( return } val roomSummary = data.roomSummary() ?: return + + // Topic + roomSummary + .topic + .takeIf { it.isNotEmpty() } + ?.let { + buildProfileSection(stringProvider.getString(R.string.room_settings_topic)) + expandableTextItem { + id("topic") + content(it) + maxLines(2) + } + } + // Security buildProfileSection(stringProvider.getString(R.string.room_profile_section_security)) val learnMoreSubtitle = if (roomSummary.isEncrypted) { diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt index 399c1ecf32..c2f25c08d3 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt @@ -129,7 +129,6 @@ class RoomProfileFragment @Inject constructor( private fun setupLongClicks() { roomProfileNameView.copyOnLongClick() roomProfileAliasView.copyOnLongClick() - roomProfileTopicView.copyOnLongClick() } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -187,7 +186,6 @@ class RoomProfileFragment @Inject constructor( roomProfileNameView.text = it.displayName matrixProfileToolbarTitleView.text = it.displayName roomProfileAliasView.setTextOrHide(it.canonicalAlias) - roomProfileTopicView.setTextOrHide(it.topic) val matrixItem = it.toMatrixItem() avatarRenderer.render(matrixItem, roomProfileAvatarView) avatarRenderer.render(matrixItem, matrixProfileToolbarAvatarImageView) diff --git a/vector/src/main/res/drawable/ic_expand_less.xml b/vector/src/main/res/drawable/ic_expand_less.xml new file mode 100644 index 0000000000..92bc86da08 --- /dev/null +++ b/vector/src/main/res/drawable/ic_expand_less.xml @@ -0,0 +1,9 @@ + + + diff --git a/vector/src/main/res/drawable/ic_expand_more.xml b/vector/src/main/res/drawable/ic_expand_more.xml new file mode 100644 index 0000000000..22c401f0c3 --- /dev/null +++ b/vector/src/main/res/drawable/ic_expand_more.xml @@ -0,0 +1,9 @@ + + + diff --git a/vector/src/main/res/layout/item_expandable_textview.xml b/vector/src/main/res/layout/item_expandable_textview.xml new file mode 100644 index 0000000000..b0c232d77e --- /dev/null +++ b/vector/src/main/res/layout/item_expandable_textview.xml @@ -0,0 +1,38 @@ + + + + + + + + \ No newline at end of file diff --git a/vector/src/main/res/layout/view_stub_room_profile_header.xml b/vector/src/main/res/layout/view_stub_room_profile_header.xml index f7ae1c77a5..ecb7174f0e 100644 --- a/vector/src/main/res/layout/view_stub_room_profile_header.xml +++ b/vector/src/main/res/layout/view_stub_room_profile_header.xml @@ -54,27 +54,9 @@ android:textAppearance="@style/Vector.Toolbar.Title" android:textSize="14sp" android:textStyle="bold" - app:layout_constraintBottom_toTopOf="@+id/roomProfileTopicView" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/roomProfileNameView" tools:text="@sample/matrix.json/data/roomAlias" /> - -