Make long topic expandable.

This commit is contained in:
Onuray Sahin 2020-10-09 14:45:36 +03:00
parent 1fd24e746c
commit 4f92db7651
8 changed files with 153 additions and 20 deletions

View File

@ -0,0 +1,86 @@
/*
* 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.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<ExpandableTextItem.Holder>() {
@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)
}
}
} else {
holder.arrow.isVisible = false
}
}
}
private fun expand(holder: Holder) {
ObjectAnimator.ofInt(holder.content, "maxLines", expandedLines)
.apply { duration = 500 }
.also { it.start() }
holder.arrow.setImageResource(R.drawable.ic_expand_less)
isExpanded = true
}
private fun collapse(holder: Holder) {
ObjectAnimator.ofInt(holder.content, "maxLines", maxLines)
.apply { duration = 500 }
.also { it.start() }
holder.arrow.setImageResource(R.drawable.ic_expand_more)
isExpanded = false
}
class Holder : VectorEpoxyHolder() {
val content by bind<TextView>(R.id.expandableContent)
val arrow by bind<ImageView>(R.id.expandableArrow)
}
}

View File

@ -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.isNotBlank() }
?.let {
buildProfileSection(stringProvider.getString(R.string.room_profile_section_topic))
expandableTextItem {
id("topic")
content(roomSummary.topic)
maxLines(2)
}
}
// Security
buildProfileSection(stringProvider.getString(R.string.room_profile_section_security))
val learnMoreSubtitle = if (roomSummary.isEncrypted) {

View File

@ -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)

View File

@ -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:fillColor="#FF000000"
android:pathData="M12,8l-6,6 1.41,1.41L12,10.83l4.59,4.58L18,14z"/>
</vector>

View File

@ -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:fillColor="#FF000000"
android:pathData="M16.59,8.59L12,13.17 7.41,8.59 6,10l6,6 6,-6z"/>
</vector>

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<TextView
android:id="@+id/expandableContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
app:layout_constraintBottom_toTopOf="@+id/expandableArrow"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:maxLines="2"
tools:text="@sample/matrix.json/data/roomTopic" />
<ImageView
android:id="@+id/expandableArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:src="@drawable/ic_expand_more"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/expandableContent"
app:tint="?riotx_text_secondary"
tools:ignore="MissingPrefix" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -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" />
<TextView
android:id="@+id/roomProfileTopicView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"
android:autoLink="web"
android:fontFamily="sans-serif"
android:gravity="center"
android:textSize="14sp"
android:textStyle="normal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/roomProfileAliasView"
tools:text="@sample/matrix.json/data/roomTopic" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -2124,6 +2124,7 @@
<string name="direct_room_profile_not_encrypted_subtitle">Messages here are not end-to-end encrypted.</string>
<string name="room_profile_encrypted_subtitle">Messages in this room are end-to-end encrypted.\n\nYour messages are secured with locks and only you and the recipient have the unique keys to unlock them.</string>
<string name="direct_room_profile_encrypted_subtitle">Messages here are end-to-end encrypted.\n\nYour messages are secured with locks and only you and the recipient have the unique keys to unlock them.</string>
<string name="room_profile_section_topic">Topic</string>
<string name="room_profile_section_security">Security</string>
<string name="room_profile_section_security_learn_more">Learn more</string>
<string name="room_profile_section_more">More</string>