Room detail: use StubView for InviteView

This commit is contained in:
ganfra 2021-09-21 18:31:17 +02:00
parent 6bf8202e65
commit 5bf1761f27
5 changed files with 57 additions and 18 deletions

View File

@ -0,0 +1,26 @@
/*
* Copyright 2019 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.extensions
import android.view.View
import android.view.ViewStub
inline fun <reified T: View> ViewStub.inflateIfNeeded(onInflate: (T) -> Unit) {
if (parent != null) {
onInflate(inflate() as T)
}
}

View File

@ -76,6 +76,7 @@ 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
@ -312,6 +313,7 @@ class RoomDetailFragment @Inject constructor(
private var lockSendButton = false
private val currentCallsViewPresenter = CurrentCallsViewPresenter()
private var inviteView: VectorInviteView? = null
private lateinit var emojiPopup: EmojiPopup
override fun onCreate(savedInstanceState: Bundle?) {
@ -343,7 +345,6 @@ class RoomDetailFragment @Inject constructor(
setupToolbar(views.roomToolbar)
setupRecyclerView()
setupComposer()
setupInviteView()
setupNotificationView()
setupJumpToReadMarkerView()
setupActiveCallView()
@ -1350,10 +1351,6 @@ class RoomDetailFragment @Inject constructor(
return isHandled
}
private fun setupInviteView() {
views.inviteView.callback = this
}
override fun invalidate() = withState(roomDetailViewModel) { state ->
invalidateOptionsMenu()
val summary = state.asyncRoomSummary()
@ -1365,7 +1362,7 @@ class RoomDetailFragment @Inject constructor(
views.jumpToBottomView.count = summary.notificationCount
views.jumpToBottomView.drawBadge = summary.hasUnreadMessages
timelineEventController.update(state)
views.inviteView.isVisible = false
inviteView?.isVisible = false
if (state.tombstoneEvent == null) {
if (state.canSendMessage) {
if (!views.voiceMessageRecorderView.isActive()) {
@ -1386,10 +1383,18 @@ class RoomDetailFragment @Inject constructor(
views.notificationAreaView.render(NotificationAreaView.State.Tombstone(state.tombstoneEvent))
}
} else if (summary?.membership == Membership.INVITE && inviter != null) {
views.inviteView.isVisible = true
views.inviteView.render(inviter, VectorInviteView.Mode.LARGE, state.changeMembershipState)
// Intercept click event
views.inviteView.setOnClickListener { }
views.inviteViewStub.inflateIfNeeded<VectorInviteView> {
inviteView = it
}
views.composerLayout.isVisible = false
views.voiceMessageRecorderView.isVisible = false
inviteView?.apply {
callback = this@RoomDetailFragment
isVisible = true
render(inviter, VectorInviteView.Mode.LARGE, state.changeMembershipState)
setOnClickListener { }
}
Unit
} else if (state.asyncInviter.complete) {
vectorBaseActivity.finish()
}

View File

@ -39,13 +39,13 @@ import im.vector.app.features.home.room.detail.timeline.factory.MergedHeaderItem
import im.vector.app.features.home.room.detail.timeline.factory.ReadReceiptsItemFactory
import im.vector.app.features.home.room.detail.timeline.factory.TimelineItemFactory
import im.vector.app.features.home.room.detail.timeline.factory.TimelineItemFactoryParams
import im.vector.app.features.home.room.detail.timeline.helper.TimelineEventsGroups
import im.vector.app.features.home.room.detail.timeline.helper.ContentDownloadStateTrackerBinder
import im.vector.app.features.home.room.detail.timeline.helper.ContentUploadStateTrackerBinder
import im.vector.app.features.home.room.detail.timeline.helper.TimelineControllerInterceptorHelper
import im.vector.app.features.home.room.detail.timeline.helper.TimelineEventDiffUtilCallback
import im.vector.app.features.home.room.detail.timeline.helper.TimelineEventVisibilityHelper
import im.vector.app.features.home.room.detail.timeline.helper.TimelineEventVisibilityStateChangedListener
import im.vector.app.features.home.room.detail.timeline.helper.TimelineEventsGroups
import im.vector.app.features.home.room.detail.timeline.helper.TimelineMediaSizeProvider
import im.vector.app.features.home.room.detail.timeline.item.BasedMergedItem
import im.vector.app.features.home.room.detail.timeline.item.DaySeparatorItem
@ -276,6 +276,10 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
}
override fun buildModels() {
// Don't build anything if membership is not joined
if (partialState.roomSummary?.membership != Membership.JOIN) {
return
}
val timestamp = System.currentTimeMillis()
val showingForwardLoader = LoadingItem_()

View File

@ -180,7 +180,7 @@
<im.vector.app.features.home.room.detail.composer.VoiceMessageRecorderView
android:id="@+id/voiceMessageRecorderView"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
@ -188,17 +188,16 @@
app:layout_constraintStart_toStartOf="parent"
tools:visibility="visible" />
<im.vector.app.features.invite.VectorInviteView
android:id="@+id/inviteView"
<ViewStub
android:id="@+id/inviteViewStub"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="0dp"
android:background="?android:colorBackground"
android:visibility="gone"
android:layout="@layout/view_stub_invite_layout"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/appBarLayout"
tools:visibility="gone" />
app:layout_constraintTop_toBottomOf="@+id/appBarLayout" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/badgeBarrier"

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<im.vector.app.features.invite.VectorInviteView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"/>