-
Notifications
You must be signed in to change notification settings - Fork 748
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
recents carousel for new home screen layout #6707
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
87ff248
new room list implementation for EditLayout
c7f6163
code review changes
997b4fc
lint fixes
b76957c
recents carousel for new home screen layout
27e5039
Merge branch 'develop' into feature/nfe/edit_layout_recents_list
dda62d4
review fixes
e205b96
Merge branch 'develop' into feature/nfe/edit_layout_recents_list
406d30a
fixed margins
8f92f85
Merge branch 'develop' into feature/nfe/edit_layout_recents_list
6f6f615
recent room title font style changed to Body
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...in/java/im/vector/app/features/home/room/list/home/recent/RecentRoomCarouselController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2022 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.features.home.room.list.home.recent | ||
|
||
import com.airbnb.epoxy.CarouselModelBuilder | ||
import com.airbnb.epoxy.EpoxyController | ||
import com.airbnb.epoxy.EpoxyModel | ||
import com.airbnb.epoxy.carousel | ||
import im.vector.app.features.home.AvatarRenderer | ||
import im.vector.app.features.home.room.list.RoomListListener | ||
import org.matrix.android.sdk.api.session.room.model.RoomSummary | ||
import org.matrix.android.sdk.api.util.toMatrixItem | ||
import javax.inject.Inject | ||
|
||
class RecentRoomCarouselController @Inject constructor( | ||
private val avatarRenderer: AvatarRenderer | ||
) : EpoxyController() { | ||
|
||
private var data: List<RoomSummary>? = null | ||
var listener: RoomListListener? = null | ||
|
||
fun submitList(recentList: List<RoomSummary>) { | ||
this.data = recentList | ||
requestModelBuild() | ||
} | ||
|
||
override fun buildModels() { | ||
val host = this | ||
data?.let { data -> | ||
carousel { | ||
id("recents_carousel") | ||
withModelsFrom(data) { roomSummary -> | ||
val onClick = host.listener?.let { it::onRoomClicked } | ||
val onLongClick = host.listener?.let { it::onRoomLongClicked } | ||
|
||
RecentRoomItem_() | ||
.id(roomSummary.roomId) | ||
.avatarRenderer(host.avatarRenderer) | ||
.matrixItem(roomSummary.toMatrixItem()) | ||
.unreadNotificationCount(roomSummary.notificationCount) | ||
.showHighlighted(roomSummary.highlightCount > 0) | ||
.itemLongClickListener { _ -> onLongClick?.invoke(roomSummary) ?: false } | ||
.itemClickListener { onClick?.invoke(roomSummary) } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private inline fun <T> CarouselModelBuilder.withModelsFrom( | ||
items: List<T>, | ||
modelBuilder: (T) -> EpoxyModel<*> | ||
) { | ||
models(items.map { modelBuilder(it) }) | ||
} |
78 changes: 78 additions & 0 deletions
78
vector/src/main/java/im/vector/app/features/home/room/list/home/recent/RecentRoomItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (c) 2022 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.features.home.room.list.home.recent | ||
|
||
import android.view.HapticFeedbackConstants | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ImageView | ||
import android.widget.TextView | ||
import com.airbnb.epoxy.EpoxyAttribute | ||
import com.airbnb.epoxy.EpoxyModelClass | ||
import im.vector.app.R | ||
import im.vector.app.core.epoxy.ClickListener | ||
import im.vector.app.core.epoxy.VectorEpoxyHolder | ||
import im.vector.app.core.epoxy.VectorEpoxyModel | ||
import im.vector.app.core.epoxy.onClick | ||
import im.vector.app.features.displayname.getBestName | ||
import im.vector.app.features.home.AvatarRenderer | ||
import im.vector.app.features.home.room.list.UnreadCounterBadgeView | ||
import org.matrix.android.sdk.api.util.MatrixItem | ||
|
||
@EpoxyModelClass | ||
abstract class RecentRoomItem : VectorEpoxyModel<RecentRoomItem.Holder>(R.layout.item_recent_room) { | ||
|
||
@EpoxyAttribute lateinit var avatarRenderer: AvatarRenderer | ||
@EpoxyAttribute lateinit var matrixItem: MatrixItem | ||
@EpoxyAttribute var unreadNotificationCount: Int = 0 | ||
@EpoxyAttribute var showHighlighted: Boolean = false | ||
|
||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) | ||
var itemLongClickListener: View.OnLongClickListener? = null | ||
|
||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) | ||
var itemClickListener: ClickListener? = null | ||
|
||
override fun bind(holder: Holder) { | ||
super.bind(holder) | ||
|
||
holder.rootView.onClick(itemClickListener) | ||
holder.rootView.setOnLongClickListener { | ||
it.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) | ||
itemLongClickListener?.onLongClick(it) ?: false | ||
} | ||
|
||
avatarRenderer.render(matrixItem, holder.avatarImageView) | ||
holder.avatarImageView.contentDescription = matrixItem.getBestName() | ||
holder.unreadCounterBadgeView.render(UnreadCounterBadgeView.State(unreadNotificationCount, showHighlighted)) | ||
holder.title.text = matrixItem.getBestName() | ||
} | ||
|
||
override fun unbind(holder: Holder) { | ||
holder.rootView.setOnClickListener(null) | ||
holder.rootView.setOnLongClickListener(null) | ||
avatarRenderer.clear(holder.avatarImageView) | ||
super.unbind(holder) | ||
} | ||
|
||
class Holder : VectorEpoxyHolder() { | ||
val unreadCounterBadgeView by bind<UnreadCounterBadgeView>(R.id.recentUnreadCounterBadgeView) | ||
val avatarImageView by bind<ImageView>(R.id.recentImageView) | ||
val title by bind<TextView>(R.id.recentTitle) | ||
val rootView by bind<ViewGroup>(R.id.recentRoot) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?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:id="@+id/recentRoot" | ||
android:layout_width="84dp" | ||
android:layout_height="wrap_content" | ||
android:background="?android:colorBackground" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
android:clickable="true" | ||
android:focusable="true" | ||
android:foreground="?attr/selectableItemBackground" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
android:paddingVertical="12dp" | ||
tools:viewBindingIgnore="true"> | ||
|
||
<ImageView | ||
android:id="@+id/recentImageView" | ||
android:layout_width="60dp" | ||
android:layout_height="60dp" | ||
android:layout_marginHorizontal="12dp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
tools:ignore="ContentDescription" | ||
tools:src="@sample/room_round_avatars" /> | ||
|
||
<im.vector.app.features.home.room.list.UnreadCounterBadgeView | ||
android:id="@+id/recentUnreadCounterBadgeView" | ||
style="@style/Widget.Vector.TextView.Micro" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:gravity="center" | ||
android:minWidth="18dp" | ||
android:minHeight="18dp" | ||
android:textColor="?colorOnError" | ||
android:visibility="gone" | ||
app:layout_constraintCircle="@id/recentImageView" | ||
app:layout_constraintCircleAngle="45" | ||
app:layout_constraintCircleRadius="28dp" | ||
tools:background="@drawable/bg_unread_highlight" | ||
tools:ignore="MissingConstraints" | ||
tools:text="24" | ||
tools:visibility="visible" /> | ||
|
||
|
||
<TextView | ||
android:id="@+id/recentTitle" | ||
style="@style/Widget.Vector.TextView.Subtitle" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="4dp" | ||
android:ellipsize="end" | ||
android:lines="1" | ||
android:textColor="?vctr_content_primary" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/recentImageView" | ||
tools:text="Coffee" /> | ||
|
||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any clean up of
RecyclerViews
inonDestroyView()
of the fragment. Could we override it and clean the adapters associated to the lists (there is aRecyclerView.cleanUp()
extension) + removing the listener from the controllers as we are passing the Fragment instance here.