|
|
@@ -2,36 +2,70 @@ package com.tencent.qcloud.tuikit.tuicallkit.view.component.floatview
|
|
|
|
|
|
import android.content.Context
|
|
|
import android.view.LayoutInflater
|
|
|
+import android.view.View
|
|
|
import android.view.ViewGroup
|
|
|
-import android.widget.FrameLayout
|
|
|
-import android.widget.ImageView
|
|
|
import android.widget.RelativeLayout
|
|
|
-import android.widget.TextView
|
|
|
+import androidx.appcompat.widget.AppCompatImageView
|
|
|
+import androidx.appcompat.widget.AppCompatTextView
|
|
|
+import com.adealink.frame.aab.util.getCompatString
|
|
|
+import com.adealink.frame.image.view.NetworkImageView
|
|
|
import com.adealink.weparty.call.R
|
|
|
+import com.adealink.weparty.commonui.ext.gone
|
|
|
+import com.adealink.weparty.commonui.ext.show
|
|
|
+import com.adealink.weparty.commonui.imageview.AvatarView
|
|
|
import com.tencent.cloud.tuikit.engine.call.TUICallDefine
|
|
|
+import com.tencent.cloud.tuikit.engine.call.TUICallDefine.MediaType
|
|
|
import com.tencent.qcloud.tuicore.util.DateTimeUtil
|
|
|
import com.tencent.qcloud.tuikit.tuicallkit.manager.EngineManager
|
|
|
-import com.tencent.qcloud.tuikit.tuicallkit.utils.ImageLoader
|
|
|
import com.tencent.qcloud.tuikit.tuicallkit.view.component.videolayout.VideoView
|
|
|
import com.tencent.qcloud.tuikit.tuicallkit.view.component.videolayout.VideoViewFactory
|
|
|
import com.tencent.qcloud.tuikit.tuicallkit.view.root.BaseCallView
|
|
|
import com.tencent.qcloud.tuikit.tuicallkit.viewmodel.component.floatview.FloatingWindowViewModel
|
|
|
import com.trtc.tuikit.common.livedata.Observer
|
|
|
-import com.adealink.weparty.R as APP_R
|
|
|
|
|
|
class FloatingWindowView(context: Context) : BaseCallView(context) {
|
|
|
|
|
|
- private var layoutAvatar: FrameLayout? = null
|
|
|
+ private var videoContainer: View? = null
|
|
|
private var layoutVideoView: RelativeLayout? = null
|
|
|
- private var imageAudioIcon: ImageView? = null
|
|
|
- private var textCallStatus: TextView? = null
|
|
|
- private var imageAvatar: ImageView? = null
|
|
|
+ private var videoBgView: NetworkImageView? = null
|
|
|
private var videoView: VideoView? = null
|
|
|
+ private var videoTimerView: AppCompatTextView? = null
|
|
|
+
|
|
|
+ private var chatContainer: View? = null
|
|
|
+ private var chatBgView: NetworkImageView? = null
|
|
|
+ private var chatAvatarView: AvatarView? = null
|
|
|
+ private var chatTimerView: AppCompatTextView? = null
|
|
|
+ private var chatCurrencyImageView: AppCompatImageView? = null
|
|
|
+ private var chatCurrencyTextView: AppCompatImageView? = null
|
|
|
+ private var chatCurrencyChangedView: AppCompatImageView? = null
|
|
|
+
|
|
|
private var viewModel: FloatingWindowViewModel = FloatingWindowViewModel()
|
|
|
- private val observer: Observer<Any> = Observer {
|
|
|
+
|
|
|
+ private val mediaType: MediaType?
|
|
|
+ get() = viewModel.mediaType?.get()
|
|
|
+
|
|
|
+ private val callStatus: TUICallDefine.Status?
|
|
|
+ get() = viewModel.selfUser?.callStatus?.get()
|
|
|
+
|
|
|
+ private val videoAvailable: Boolean
|
|
|
+ get() = viewModel.remoteUser?.videoAvailable?.get() ?: false
|
|
|
+
|
|
|
+ private val mediaTypeObserver: Observer<MediaType> = Observer {
|
|
|
updateView(it)
|
|
|
}
|
|
|
|
|
|
+ private val timeCountObserver: Observer<Int> = Observer {
|
|
|
+ updateTimer(it)
|
|
|
+ }
|
|
|
+
|
|
|
+ private val callStatusObserver: Observer<TUICallDefine.Status> = Observer {
|
|
|
+ updateCallStatus()
|
|
|
+ }
|
|
|
+
|
|
|
+ private val videoAvailableObserver: Observer<Boolean> = Observer {
|
|
|
+ updateWhenVideoAvailable()
|
|
|
+ }
|
|
|
+
|
|
|
init {
|
|
|
initView(context)
|
|
|
addObserver()
|
|
|
@@ -43,99 +77,153 @@ class FloatingWindowView(context: Context) : BaseCallView(context) {
|
|
|
}
|
|
|
|
|
|
override fun addObserver() {
|
|
|
- viewModel?.mediaType?.observe(observer)
|
|
|
- viewModel?.timeCount?.observe(observer)
|
|
|
- viewModel?.selfUser?.callStatus?.observe(observer)
|
|
|
- viewModel.remoteUser?.videoAvailable?.observe(observer)
|
|
|
+ viewModel.mediaType?.observe(mediaTypeObserver)
|
|
|
+ viewModel.timeCount?.observe(timeCountObserver)
|
|
|
+ viewModel.selfUser?.callStatus?.observe(callStatusObserver)
|
|
|
+ viewModel.remoteUser.videoAvailable?.observe(videoAvailableObserver)
|
|
|
}
|
|
|
|
|
|
override fun removeObserver() {
|
|
|
- viewModel?.mediaType?.removeObserver(observer)
|
|
|
- viewModel?.timeCount?.removeObserver(observer)
|
|
|
- viewModel?.selfUser?.callStatus?.removeObserver(observer)
|
|
|
- viewModel.remoteUser?.videoAvailable?.removeObserver(observer)
|
|
|
+ viewModel.mediaType?.removeObserver(mediaTypeObserver)
|
|
|
+ viewModel.timeCount?.removeObserver(timeCountObserver)
|
|
|
+ viewModel.selfUser?.callStatus?.removeObserver(callStatusObserver)
|
|
|
+ viewModel.remoteUser?.videoAvailable?.removeObserver(videoAvailableObserver)
|
|
|
}
|
|
|
|
|
|
private fun initView(context: Context) {
|
|
|
- LayoutInflater.from(context).inflate(R.layout.tuicallkit_float_call_view, this)
|
|
|
- layoutVideoView = findViewById(R.id.rl_video_view)
|
|
|
- imageAvatar = findViewById(R.id.iv_avatar)
|
|
|
- textCallStatus = findViewById(R.id.tv_call_status)
|
|
|
- imageAudioIcon = findViewById(R.id.iv_audio_view_icon)
|
|
|
- layoutAvatar = findViewById(R.id.fl_avatar)
|
|
|
-
|
|
|
- updateView(null)
|
|
|
+ LayoutInflater.from(context).inflate(R.layout.call_float_call_view, this)
|
|
|
+ val videoContainer = findViewById<View>(R.id.v_video)
|
|
|
+ if (videoContainer != null) {
|
|
|
+ layoutVideoView = videoContainer.findViewById(R.id.rl_video_view)
|
|
|
+ videoBgView = videoContainer.findViewById(R.id.iv_bg)
|
|
|
+ videoTimerView = videoContainer.findViewById(R.id.tv_call_timer)
|
|
|
+ }
|
|
|
+
|
|
|
+ val chatViewContainer = findViewById<View>(R.id.v_chat)
|
|
|
+ if (chatViewContainer != null) {
|
|
|
+ this.chatContainer = chatViewContainer
|
|
|
+ chatBgView = chatViewContainer.findViewById(R.id.iv_bg)
|
|
|
+ chatAvatarView = chatViewContainer.findViewById(R.id.iv_avatar)
|
|
|
+ chatTimerView = chatViewContainer.findViewById(R.id.tv_call_timer)
|
|
|
+ chatCurrencyImageView = chatViewContainer.findViewById(R.id.iv_currency)
|
|
|
+ chatCurrencyTextView = chatViewContainer.findViewById(R.id.tv_currency)
|
|
|
+ chatCurrencyChangedView = chatViewContainer.findViewById(R.id.tv_currency_changed)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun reset() {
|
|
|
+ VideoViewFactory.instance.clear()
|
|
|
+ clear()
|
|
|
+ viewModel.stopFloatService()
|
|
|
}
|
|
|
|
|
|
- private fun updateView(it: Any?) {
|
|
|
- if (it != null && it is Int && it > 0) {
|
|
|
- textCallStatus?.post {
|
|
|
- textCallStatus?.text = DateTimeUtil.formatSecondsTo00(it)
|
|
|
+ private fun updateView(mediaType: MediaType) {
|
|
|
+ when (mediaType) {
|
|
|
+ MediaType.Audio -> {
|
|
|
+ videoContainer?.gone()
|
|
|
+ chatContainer?.show()
|
|
|
+ updateCallStatus()
|
|
|
}
|
|
|
- return
|
|
|
- }
|
|
|
- if (viewModel.mediaType.get() == TUICallDefine.MediaType.Audio
|
|
|
- || viewModel.scene.get() == TUICallDefine.Scene.GROUP_CALL
|
|
|
- ) {
|
|
|
- imageAudioIcon?.visibility = VISIBLE
|
|
|
- textCallStatus?.visibility = VISIBLE
|
|
|
- layoutVideoView?.visibility = GONE
|
|
|
- layoutAvatar?.visibility = GONE
|
|
|
- if (viewModel.selfUser?.callStatus?.get() == TUICallDefine.Status.Waiting) {
|
|
|
- textCallStatus?.text = context.getString(R.string.tuicallkit_wait_response)
|
|
|
- } else if (viewModel.selfUser?.callStatus?.get() == TUICallDefine.Status.Accept) {
|
|
|
- textCallStatus?.text = DateTimeUtil.formatSecondsTo00(viewModel.timeCount.get())
|
|
|
- } else {
|
|
|
- VideoViewFactory.instance.clear()
|
|
|
- clear()
|
|
|
- viewModel.stopFloatService()
|
|
|
+
|
|
|
+ MediaType.Video -> {
|
|
|
+ videoContainer?.show()
|
|
|
+ chatContainer?.gone()
|
|
|
+ updateCallStatus()
|
|
|
+ }
|
|
|
+
|
|
|
+ MediaType.Unknown -> {
|
|
|
+ //Ntd.
|
|
|
}
|
|
|
- } else if (viewModel.mediaType.get() == TUICallDefine.MediaType.Video) {
|
|
|
- imageAudioIcon?.visibility = GONE
|
|
|
- if (viewModel.selfUser?.callStatus?.get() == TUICallDefine.Status.Waiting) {
|
|
|
- layoutVideoView?.visibility = VISIBLE
|
|
|
- layoutAvatar?.visibility = GONE
|
|
|
- textCallStatus?.visibility = VISIBLE
|
|
|
- textCallStatus?.text = context.getString(R.string.tuicallkit_wait_response)
|
|
|
- textCallStatus?.setTextColor(context.resources.getColor(R.color.tuicallkit_color_white))
|
|
|
- videoView = VideoViewFactory.instance.createVideoView(viewModel.selfUser, context)
|
|
|
- if (videoView != null && videoView?.parent != null) {
|
|
|
- (videoView?.parent as ViewGroup).removeView(videoView)
|
|
|
- layoutVideoView?.removeAllViews()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun updateCallStatus() {
|
|
|
+ when (mediaType) {
|
|
|
+ MediaType.Audio -> {
|
|
|
+ when (callStatus) {
|
|
|
+ TUICallDefine.Status.Waiting -> {
|
|
|
+ chatTimerView?.text = getCompatString(R.string.call_wait_response)
|
|
|
+ }
|
|
|
+
|
|
|
+ TUICallDefine.Status.Accept -> {
|
|
|
+ chatTimerView?.text = DateTimeUtil.formatSecondsTo00(viewModel.timeCount.get())
|
|
|
+ }
|
|
|
+
|
|
|
+ TUICallDefine.Status.None, null -> {
|
|
|
+ reset()
|
|
|
+ }
|
|
|
}
|
|
|
- layoutVideoView?.addView(videoView)
|
|
|
- } else if (viewModel.selfUser?.callStatus?.get() == TUICallDefine.Status.Accept) {
|
|
|
- if (viewModel.remoteUser?.videoAvailable?.get() == true) {
|
|
|
- layoutVideoView?.visibility = VISIBLE
|
|
|
- layoutAvatar?.visibility = GONE
|
|
|
- textCallStatus?.visibility = GONE
|
|
|
- videoView = VideoViewFactory.instance.createVideoView(viewModel.remoteUser, context)
|
|
|
- if (videoView != null && videoView?.parent != null) {
|
|
|
- (videoView?.parent as ViewGroup).removeView(videoView)
|
|
|
- layoutVideoView?.removeAllViews()
|
|
|
+ }
|
|
|
+
|
|
|
+ MediaType.Video -> {
|
|
|
+ when (callStatus) {
|
|
|
+ TUICallDefine.Status.Waiting -> {
|
|
|
+ videoTimerView?.text = getCompatString(R.string.call_wait_response)
|
|
|
+ updateWhenVideoAvailable()
|
|
|
}
|
|
|
- layoutVideoView?.addView(videoView)
|
|
|
- EngineManager.instance.startRemoteView(
|
|
|
- viewModel.remoteUser?.id,
|
|
|
- videoView?.getVideoView(),
|
|
|
- null
|
|
|
- )
|
|
|
- } else {
|
|
|
- layoutVideoView?.visibility = GONE
|
|
|
- layoutAvatar?.visibility = VISIBLE
|
|
|
-
|
|
|
- ImageLoader.loadImage(
|
|
|
- context,
|
|
|
- imageAvatar,
|
|
|
-// viewModel.remoteUser?.avatar?.get(),
|
|
|
- APP_R.drawable.common_default_avatar_ic
|
|
|
- )
|
|
|
+
|
|
|
+ TUICallDefine.Status.Accept -> {
|
|
|
+ videoTimerView?.text = DateTimeUtil.formatSecondsTo00(viewModel.timeCount.get())
|
|
|
+ updateWhenVideoAvailable()
|
|
|
+ }
|
|
|
+
|
|
|
+ TUICallDefine.Status.None, null -> {
|
|
|
+ reset()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ MediaType.Unknown, null -> {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun updateWhenVideoAvailable() {
|
|
|
+ if (videoAvailable) {
|
|
|
+ layoutVideoView?.show()
|
|
|
+ videoView = VideoViewFactory.instance.createVideoView(viewModel.selfUser, context)
|
|
|
+ if (videoView != null && videoView?.parent != null) {
|
|
|
+ (videoView?.parent as ViewGroup).removeView(videoView)
|
|
|
+ layoutVideoView?.removeAllViews()
|
|
|
+ }
|
|
|
+ layoutVideoView?.addView(videoView)
|
|
|
+ EngineManager.instance.startRemoteView(
|
|
|
+ viewModel.remoteUser.id,
|
|
|
+ videoView?.getVideoView(),
|
|
|
+ null
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ //呼叫等待
|
|
|
+ layoutVideoView?.gone()
|
|
|
+// layoutVideoView?.visibility = GONE
|
|
|
+// layoutAvatar?.visibility = VISIBLE
|
|
|
+// ImageLoader.loadImage(
|
|
|
+// context,
|
|
|
+// imageAvatar,
|
|
|
+//// viewModel.remoteUser?.avatar?.get(),
|
|
|
+// APP_R.drawable.common_default_avatar_ic
|
|
|
+// )
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun updateTimer(timer: Int) {
|
|
|
+ when (mediaType) {
|
|
|
+ MediaType.Audio -> {
|
|
|
+ chatTimerView?.post {
|
|
|
+ chatTimerView?.text = DateTimeUtil.formatSecondsTo00(timer)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ MediaType.Video -> {
|
|
|
+ videoTimerView?.post {
|
|
|
+ videoTimerView?.text = DateTimeUtil.formatSecondsTo00(timer)
|
|
|
}
|
|
|
- } else {
|
|
|
- VideoViewFactory.instance.clear()
|
|
|
- clear()
|
|
|
- viewModel.stopFloatService()
|
|
|
}
|
|
|
+
|
|
|
+ MediaType.Unknown, null -> TODO()
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|