diff --git a/app/src/main/java/org/futo/circles/view/PostHeaderView.kt b/app/src/main/java/org/futo/circles/view/PostHeaderView.kt index 90d4d4dc276818f42eca49f28a47a4f554f412e7..d5bbbd544becad87b7b5a185a18e2c29e524f74f 100644 --- a/app/src/main/java/org/futo/circles/view/PostHeaderView.kt +++ b/app/src/main/java/org/futo/circles/view/PostHeaderView.kt @@ -44,12 +44,18 @@ class PostHeaderView( sender.notEmptyDisplayName(), sender.avatarUrl, data.postInfo.timestamp, - data.postInfo.isEncrypted + data.postInfo.isEncrypted, + data.timelineName ) } fun bindViewData( - userId: String, name: String, avatarUrl: String?, timestamp: Long, isEncrypted: Boolean + userId: String, + name: String, + avatarUrl: String?, + timestamp: Long, + isEncrypted: Boolean, + roomName: String? = null ) { with(binding) { ivSenderImage.apply { @@ -63,6 +69,10 @@ class PostHeaderView( tvUserId.text = UserUtils.removeDomainSuffix(userId) ivEncrypted.setIsEncryptedIcon(isEncrypted) tvMessageTime.text = DateFormat.format("MMM dd, h:mm a", Date(timestamp)) + roomName?.let { + val nameFormat = "($it)" + tvRoomName.text = nameFormat + } } } diff --git a/app/src/main/res/layout/view_post_header.xml b/app/src/main/res/layout/view_post_header.xml index 26eb0d1ebdad7a9c448f661841b708da1dfaa23c..e19e2a6b10ee90f20676a4cad3bd321f43a46dfa 100644 --- a/app/src/main/res/layout/view_post_header.xml +++ b/app/src/main/res/layout/view_post_header.xml @@ -66,16 +66,34 @@ <TextView android:id="@+id/tvUserId" - android:layout_width="0dp" + android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="end" android:lines="1" android:textSize="13sp" + app:layout_constrainedWidth="true" app:layout_constraintBottom_toBottomOf="@id/ivSenderImage" - app:layout_constraintEnd_toStartOf="@id/btnMore" + app:layout_constraintEnd_toStartOf="@id/tvRoomName" + app:layout_constraintHorizontal_bias="0" + app:layout_constraintHorizontal_chainStyle="packed" app:layout_constraintStart_toStartOf="@id/tvUserName" app:layout_constraintTop_toBottomOf="@id/tvUserName" - tools:text="Android01@domainsadasdasd" /> + tools:text="Android01:nl.circles-dev.net" /> + + <TextView + android:id="@+id/tvRoomName" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="4dp" + android:ellipsize="end" + android:lines="1" + app:layout_constrainedWidth="true" + android:textSize="13sp" + app:layout_constraintBottom_toBottomOf="@id/ivSenderImage" + app:layout_constraintEnd_toStartOf="@id/btnMore" + app:layout_constraintStart_toEndOf="@id/tvUserId" + app:layout_constraintTop_toBottomOf="@id/tvUserName" + tools:text="(Timeline name)" /> <ImageButton android:id="@+id/btnMore" diff --git a/core/src/main/java/org/futo/circles/core/feature/timeline/builder/MultiTimelineBuilder.kt b/core/src/main/java/org/futo/circles/core/feature/timeline/builder/MultiTimelineBuilder.kt index 4ff1529728f357d03ac8f22ac11a24c7b47f407d..a6af3eb632be40a14e27f0e166f6c981fa5c8222 100644 --- a/core/src/main/java/org/futo/circles/core/feature/timeline/builder/MultiTimelineBuilder.kt +++ b/core/src/main/java/org/futo/circles/core/feature/timeline/builder/MultiTimelineBuilder.kt @@ -1,5 +1,6 @@ package org.futo.circles.core.feature.timeline.builder +import org.futo.circles.core.mapping.nameOrId import org.futo.circles.core.mapping.toPost import org.futo.circles.core.model.Post import org.futo.circles.core.provider.MatrixSessionProvider @@ -13,13 +14,15 @@ class MultiTimelineBuilder @Inject constructor() : BaseTimelineBuilder() { private var readReceiptMap: MutableMap<String, List<Long>> = mutableMapOf() override suspend fun List<TimelineEvent>.processSnapshot(isThread: Boolean): List<Post> { - val roomId = - firstOrNull()?.roomId ?: return currentSnapshotMap.flatMap { (_, value) -> value } - val room = MatrixSessionProvider.currentSession?.getRoom(roomId) ?: return emptyList() + val roomId = firstOrNull()?.roomId ?: return getAllTimelinesPostsList() + val room = MatrixSessionProvider.currentSession?.getRoom(roomId) + ?: return getAllTimelinesPostsList() + val roomName = room.roomSummary()?.nameOrId() val receipts = getReadReceipts(room).also { readReceiptMap[roomId] = it } - currentSnapshotMap[roomId] = this.map { it.toPost(receipts) } - val fullTimelineEventList = currentSnapshotMap.flatMap { (_, value) -> value } - return sortList(fullTimelineEventList, isThread) + currentSnapshotMap[roomId] = this.map { it.toPost(receipts, roomName) } + return sortList(getAllTimelinesPostsList(), isThread) } + private fun getAllTimelinesPostsList() = currentSnapshotMap.flatMap { (_, value) -> value } + } \ No newline at end of file diff --git a/core/src/main/java/org/futo/circles/core/mapping/RoomSummaryMapping.kt b/core/src/main/java/org/futo/circles/core/mapping/RoomSummaryMapping.kt index ca2bb9521a78dd04888782f88c8045f31c7217fc..6c1f11a134e90dbd103efdd3ff4e69ae30566b9b 100644 --- a/core/src/main/java/org/futo/circles/core/mapping/RoomSummaryMapping.kt +++ b/core/src/main/java/org/futo/circles/core/mapping/RoomSummaryMapping.kt @@ -5,7 +5,8 @@ import org.futo.circles.core.model.RoomInfo import org.futo.circles.core.model.SelectableRoomListItem import org.matrix.android.sdk.api.session.room.model.RoomSummary -fun RoomSummary.nameOrId() = displayName.takeIf { it.isNotEmpty() } ?: roomId +fun RoomSummary.nameOrId() = + displayName.takeIf { it.isNotEmpty() } ?: name.takeIf { it.isNotEmpty() } ?: roomId fun RoomSummary.toRoomInfo() = RoomInfo( title = nameOrId(), diff --git a/core/src/main/java/org/futo/circles/core/mapping/TimelineEventMapping.kt b/core/src/main/java/org/futo/circles/core/mapping/TimelineEventMapping.kt index 5c96f660041ae87a1903e04ee6e75c30e5238cfa..b33355b84379e006e7546dafe2a63d996f7a78a6 100644 --- a/core/src/main/java/org/futo/circles/core/mapping/TimelineEventMapping.kt +++ b/core/src/main/java/org/futo/circles/core/mapping/TimelineEventMapping.kt @@ -10,7 +10,10 @@ import org.futo.circles.core.model.ReactionsData import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent import org.matrix.android.sdk.api.session.room.timeline.hasBeenEdited -fun TimelineEvent.toPost(readReceipts: List<Long> = emptyList()): Post = Post( +fun TimelineEvent.toPost( + readReceipts: List<Long> = emptyList(), + timelineName: String? = null +): Post = Post( postInfo = toPostInfo(), content = toPostContent(), sendState = root.sendState, @@ -18,7 +21,8 @@ fun TimelineEvent.toPost(readReceipts: List<Long> = emptyList()): Post = Post( repliesCount = root.threadDetails?.numberOfThreads ?: 0, reactionsData = annotations?.reactionsSummary?.map { ReactionsData(it.key, it.count, it.addedByMe) - } ?: emptyList() + } ?: emptyList(), + timelineName = timelineName ) fun TimelineEvent.toPostInfo(): PostInfo = PostInfo( diff --git a/core/src/main/java/org/futo/circles/core/model/Post.kt b/core/src/main/java/org/futo/circles/core/model/Post.kt index 4f14663faa5310799c28b627fa8cec14a58aa107..4a4cac72333a807ee0fcd73c48d576e18f15d5a8 100644 --- a/core/src/main/java/org/futo/circles/core/model/Post.kt +++ b/core/src/main/java/org/futo/circles/core/model/Post.kt @@ -9,7 +9,8 @@ data class Post( val sendState: SendState, val readByCount: Int, val repliesCount: Int, - val reactionsData: List<ReactionsData> + val reactionsData: List<ReactionsData>, + val timelineName: String? = null ) : IdEntity<String> { override val id: String get() = postInfo.id fun isMyPost(): Boolean = postInfo.isMyPost()