Using ViewStub for voice recoridng & reply to views

This commit is contained in:
Sylvain Berfini 2021-11-10 15:31:44 +01:00
parent dfa6175b71
commit b067a49cd0
4 changed files with 43 additions and 7 deletions

View file

@ -32,6 +32,7 @@ import android.widget.PopupWindow
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
import androidx.core.view.doOnPreDraw import androidx.core.view.doOnPreDraw
import androidx.databinding.DataBindingUtil import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
@ -493,6 +494,10 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
false false
} }
binding.setCancelReplyToClickListener {
chatSendingViewModel.cancelReply()
}
binding.setScrollToBottomClickListener { binding.setScrollToBottomClickListener {
scrollToFirstUnreadMessageOrBottom(true) scrollToFirstUnreadMessageOrBottom(true)
} }
@ -536,6 +541,18 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
} }
} }
) )
binding.stubbedMessageToReplyTo.setOnInflateListener { _, inflated ->
Log.i("[Chat Room] Replying to message layout inflated")
val binding = DataBindingUtil.bind<ViewDataBinding>(inflated)
binding?.lifecycleOwner = viewLifecycleOwner
}
binding.stubbedVoiceRecording.setOnInflateListener { _, inflated ->
Log.i("[Chat Room] Voice recording layout inflated")
val binding = DataBindingUtil.bind<ViewDataBinding>(inflated)
binding?.lifecycleOwner = viewLifecycleOwner
}
} }
override fun deleteItems(indexesOfItemToDelete: ArrayList<Int>) { override fun deleteItems(indexesOfItemToDelete: ArrayList<Int>) {

View file

@ -10,12 +10,16 @@
<variable <variable
name="data" name="data"
type="org.linphone.activities.main.chat.data.ChatMessageData" /> type="org.linphone.activities.main.chat.data.ChatMessageData" />
<variable
name="inflatedVisibility"
type="Integer" />
</data> </data>
<RelativeLayout <RelativeLayout
android:background="@{data.chatMessage.isOutgoing ? @color/chat_bubble_outgoing_color : @color/chat_bubble_incoming_color, default=@color/chat_bubble_incoming_color}" android:background="@{data.chatMessage.isOutgoing ? @color/chat_bubble_outgoing_color : @color/chat_bubble_incoming_color, default=@color/chat_bubble_incoming_color}"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:visibility="@{inflatedVisibility}">
<LinearLayout <LinearLayout
android:id="@+id/reply_layout" android:id="@+id/reply_layout"

View file

@ -7,6 +7,9 @@
<variable <variable
name="viewModel" name="viewModel"
type="org.linphone.activities.main.chat.viewmodels.ChatMessageSendingViewModel" /> type="org.linphone.activities.main.chat.viewmodels.ChatMessageSendingViewModel" />
<variable
name="inflatedVisibility"
type="Integer" />
</data> </data>
<RelativeLayout <RelativeLayout
@ -14,7 +17,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingTop="10dp" android:paddingTop="10dp"
android:paddingBottom="10dp"> android:paddingBottom="10dp"
android:visibility="@{inflatedVisibility}">
<ImageView <ImageView
android:id="@+id/cancel_recording" android:id="@+id/cancel_recording"

View file

@ -26,6 +26,9 @@
<variable <variable
name="voiceRecordingTouchListener" name="voiceRecordingTouchListener"
type="android.view.View.OnTouchListener" /> type="android.view.View.OnTouchListener" />
<variable
name="cancelReplyToClickListener"
type="android.view.View.OnClickListener" />
<variable <variable
name="scrollToBottomClickListener" name="scrollToBottomClickListener"
type="android.view.View.OnClickListener"/> type="android.view.View.OnClickListener"/>
@ -152,16 +155,24 @@
android:background="?attr/lightToolbarBackgroundColor" android:background="?attr/lightToolbarBackgroundColor"
android:orientation="vertical"> android:orientation="vertical">
<include <ViewStub
android:id="@+id/stubbed_message_to_reply_to"
android:visibility="@{chatSendingViewModel.isPendingAnswer ? View.VISIBLE : View.GONE, default=gone}" android:visibility="@{chatSendingViewModel.isPendingAnswer ? View.VISIBLE : View.GONE, default=gone}"
app:inflatedVisibility="@{chatSendingViewModel.isPendingAnswer ? View.VISIBLE : View.GONE}"
app:data="@{chatSendingViewModel.pendingChatMessageToReplyTo}" app:data="@{chatSendingViewModel.pendingChatMessageToReplyTo}"
app:cancelClickListener="@{() -> chatSendingViewModel.cancelReply()}" android:layout="@layout/chat_message_reply"
layout="@layout/chat_message_reply" /> app:cancelClickListener="@{cancelReplyToClickListener}"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<include <ViewStub
android:id="@+id/stubbed_voice_recording"
android:visibility="@{chatSendingViewModel.isPendingVoiceRecord ? View.VISIBLE : View.GONE, default=gone}" android:visibility="@{chatSendingViewModel.isPendingVoiceRecord ? View.VISIBLE : View.GONE, default=gone}"
app:inflatedVisibility="@{chatSendingViewModel.isPendingVoiceRecord ? View.VISIBLE : View.GONE}"
app:viewModel="@{chatSendingViewModel}" app:viewModel="@{chatSendingViewModel}"
layout="@layout/chat_message_voice_recording" /> android:layout="@layout/chat_message_voice_recording"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View <View
android:visibility="@{chatSendingViewModel.isPendingVoiceRecord &amp;&amp; chatSendingViewModel.attachments.size() > 0 ? View.VISIBLE : View.GONE, default=gone}" android:visibility="@{chatSendingViewModel.isPendingVoiceRecord &amp;&amp; chatSendingViewModel.attachments.size() > 0 ? View.VISIBLE : View.GONE, default=gone}"