Room detail: create lazy loaded views holder

This commit is contained in:
ganfra 2021-09-22 11:36:37 +02:00
parent fb10e9f113
commit 290586948f
2 changed files with 54 additions and 10 deletions

View File

@ -76,7 +76,6 @@ import im.vector.app.core.epoxy.LayoutManagerStateRestorer
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.extensions.hideKeyboard
import im.vector.app.core.extensions.inflateIfNeeded
import im.vector.app.core.extensions.registerStartForActivityResult
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.core.extensions.showKeyboard
@ -155,6 +154,7 @@ import im.vector.app.features.home.room.detail.timeline.item.ReadReceiptData
import im.vector.app.features.home.room.detail.timeline.reactions.ViewReactionsBottomSheet
import im.vector.app.features.home.room.detail.timeline.url.PreviewUrlRetriever
import im.vector.app.features.home.room.detail.upgrade.MigrateRoomBottomSheet
import im.vector.app.features.home.room.detail.views.RoomDetailLazyLoadedViews
import im.vector.app.features.home.room.detail.widget.RoomWidgetsBottomSheet
import im.vector.app.features.html.EventHtmlRenderer
import im.vector.app.features.html.PillImageSpan
@ -314,7 +314,7 @@ class RoomDetailFragment @Inject constructor(
private var lockSendButton = false
private val currentCallsViewPresenter = CurrentCallsViewPresenter()
private var inviteView: VectorInviteView? = null
private val lazyLoadedViews = RoomDetailLazyLoadedViews()
private val emojiPopup: EmojiPopup by lifecycleAwareLazy {
createEmojiPopup()
}
@ -326,9 +326,6 @@ class RoomDetailFragment @Inject constructor(
roomDetailViewModel.handle(RoomDetailAction.RoomUpgradeSuccess(replacementRoomId))
}
}
lifecycleScope.launchWhenResumed {
}
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -348,6 +345,7 @@ class RoomDetailFragment @Inject constructor(
onTapToReturnToCall = ::onTapToReturnToCall
)
keyboardStateUtils = KeyboardStateUtils(requireActivity())
lazyLoadedViews.bind(views)
setupToolbar(views.roomToolbar)
setupRecyclerView()
setupComposer()
@ -776,6 +774,7 @@ class RoomDetailFragment @Inject constructor(
}
override fun onDestroyView() {
lazyLoadedViews.unBind()
timelineEventController.callback = null
timelineEventController.removeModelBuildListener(modelBuildListener)
currentCallsViewPresenter.unBind()
@ -1368,7 +1367,7 @@ class RoomDetailFragment @Inject constructor(
views.jumpToBottomView.count = summary.notificationCount
views.jumpToBottomView.drawBadge = summary.hasUnreadMessages
timelineEventController.update(state)
inviteView?.isVisible = false
lazyLoadedViews.inviteView?.isVisible = false
if (state.tombstoneEvent == null) {
if (state.canSendMessage) {
if (!views.voiceMessageRecorderView.isActive()) {
@ -1389,12 +1388,9 @@ class RoomDetailFragment @Inject constructor(
views.notificationAreaView.render(NotificationAreaView.State.Tombstone(state.tombstoneEvent))
}
} else if (summary?.membership == Membership.INVITE && inviter != null) {
views.inviteViewStub.inflateIfNeeded<VectorInviteView> {
inviteView = it
}
views.composerLayout.isVisible = false
views.voiceMessageRecorderView.isVisible = false
inviteView?.apply {
lazyLoadedViews.inviteView?.apply {
callback = this@RoomDetailFragment
isVisible = true
render(inviter, VectorInviteView.Mode.LARGE, state.changeMembershipState)

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2021 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.detail.views
import im.vector.app.core.extensions.inflateIfNeeded
import im.vector.app.databinding.FragmentRoomDetailBinding
import im.vector.app.features.invite.VectorInviteView
/**
* This is an holder for lazy loading some views of the RoomDetail screen.
* It's using some ViewStub where it makes sense.
*/
class RoomDetailLazyLoadedViews {
private var roomDetailBinding: FragmentRoomDetailBinding? = null
var inviteView: VectorInviteView? = null
private set
get() {
roomDetailBinding?.inviteViewStub?.inflateIfNeeded<VectorInviteView> {
inviteView = it
}
return field
}
fun bind(roomDetailBinding: FragmentRoomDetailBinding) {
this.roomDetailBinding = roomDetailBinding
}
fun unBind() {
roomDetailBinding = null
inviteView = null
}
}