This commit is contained in:
zhongchao
2022-11-11 18:07:24 +08:00
parent 5489eed272
commit e52ba22a56
14 changed files with 104 additions and 134 deletions

View File

@@ -2,17 +2,12 @@ package com.mogo.eagle.core.function.chat.facade.bridge
import android.content.Context
import com.mogo.eagle.core.utilcode.util.Utils
import com.mogo.module.common.MogoApisHandler
import java.lang.ref.WeakReference
internal object BridgeApi {
private var contextHolder: WeakReference<Context>? = null
private val apis by lazy {
MogoApisHandler.getInstance().apis
}
internal fun init(context: Context?) {
context?.let {
contextHolder = WeakReference(context)
@@ -21,5 +16,4 @@ internal object BridgeApi {
internal fun context(): Context = contextHolder?.get() ?: Utils.getApp()
internal fun floatViewManager() = apis?.windowManagerApi
}

View File

@@ -22,6 +22,7 @@ import com.mogo.eagle.core.function.api.chat.biz.ChatConsts
import com.mogo.eagle.core.function.api.chat.biz.HangUpState
import com.mogo.eagle.core.function.api.chat.biz.IMoGoVoiceControlFacade.IMoGoVoiceCallback
import com.mogo.eagle.core.function.api.chat.biz.RefuseState
import com.mogo.eagle.core.function.call.hmi.CallerHmiFloatViewManager
import com.mogo.eagle.core.function.chat.R
import com.mogo.eagle.core.function.chat.facade.MoGoChatFacade
import com.mogo.eagle.core.function.chat.facade.OnCallingInterrupt
@@ -200,7 +201,7 @@ internal class CallChatWindowManager {
log(TAG, "由于对方呼出又挂断,导致来电界面隐藏")
d2.safeCancel()
}
2 -> {
2 -> {
log(TAG, "由于自己主动拒接,导致来电界面隐藏")
d1.safeCancel()
}
@@ -252,8 +253,11 @@ internal class CallChatWindowManager {
private fun getInComingLayoutParams(context: Context): FrameLayout.LayoutParams {
return FrameLayout.LayoutParams(
context.resources.getDimension(R.dimen.module_call_chat_state_incoming_hawk_eye_width).toInt(),
context.resources.getDimension(R.dimen.module_call_chat_state_incoming_hawk_eye_height).toInt())
context.resources.getDimension(R.dimen.module_call_chat_state_incoming_hawk_eye_width)
.toInt(),
context.resources.getDimension(R.dimen.module_call_chat_state_incoming_hawk_eye_height)
.toInt()
)
.also {
it.gravity = Gravity.BOTTOM or Gravity.START
it.marginStart = 40.PX
@@ -264,7 +268,11 @@ internal class CallChatWindowManager {
/**
* 重新开始计时
*/
private fun CoroutineScope.resetInComingTimer(old: Job?, user: UserInfo, incomingView: View): Job {
private fun CoroutineScope.resetInComingTimer(
old: Job?,
user: UserInfo,
incomingView: View
): Job {
old?.safeCancel()
return inComingTimer(user, incomingView)
}
@@ -284,13 +292,13 @@ internal class CallChatWindowManager {
var callingView = LayoutInflater.from(context)
.inflate(R.layout.module_car_chatting_launcher_calling_hawk_eye_view, null)
callingView.isClickable = true
var calling= callingView.findViewById<View>(R.id.module_carchatting_rl_call_view)
var calling = callingView.findViewById<View>(R.id.module_carchatting_rl_call_view)
var head = callingView.findViewById<ImageView>(R.id.module_carchatting_call_head)
var hangUp = callingView.findViewById<View>(R.id.module_carchatting_call_hangUp)
var name = callingView.findViewById<TextView>(R.id.module_carchatting_call_nickname)
var timer = callingView.findViewById<TextView>(R.id.module_carchatting_call_time)
calling.visibility = View.VISIBLE
name.text = "云平台"
name.text = "云平台"
timer.text = context.resources.getString(R.string.module_car_chat_matching_wait)
GlideApp.with(context).load(user.icon)
.apply(
@@ -353,7 +361,7 @@ internal class CallChatWindowManager {
}
hide(callingView)
facade.audioFocus().releaseAudioFocus()
}.also { job = it }
}.also { job = it }
}
if (itx == ON_DESTROY) {
isCallingShow = false
@@ -375,9 +383,9 @@ internal class CallChatWindowManager {
private fun getCallingLayoutParams(context: Context): FrameLayout.LayoutParams {
return FrameLayout.LayoutParams(
context.resources.getDimension(R.dimen.module_call_chat_state_hawk_eye_width).toInt(),
context.resources.getDimension(R.dimen.module_call_chat_state_hawk_eye_height).toInt()
)
context.resources.getDimension(R.dimen.module_call_chat_state_hawk_eye_width).toInt(),
context.resources.getDimension(R.dimen.module_call_chat_state_hawk_eye_height).toInt()
)
.also {
it.gravity = Gravity.BOTTOM or Gravity.START
it.marginStart = 40.PX
@@ -393,17 +401,17 @@ internal class CallChatWindowManager {
}
private fun show(view: View, params: FrameLayout.LayoutParams) {
BridgeApi.floatViewManager()?.addView(view, params, true)
CallerHmiFloatViewManager.addView(view, params, true)
}
private fun hide(view: View) {
if (!ViewCompat.isAttachedToWindow(view)) {
return
}
BridgeApi.floatViewManager()?.removeView(view)
CallerHmiFloatViewManager.removeView(view)
}
private fun playAudioCall(onPlay:(() -> Unit)? = null) {
private fun playAudioCall(onPlay: (() -> Unit)? = null) {
facade.also {
it.audioFocus().requireAudioFocus {
it.media().play(context, R.raw.call, true, AudioManager.STREAM_RING)
@@ -474,7 +482,13 @@ internal class CallChatWindowManager {
* @param onExit: 当前用户退房通知(当前用户主动挂断或对方挂断)
*/
@OptIn(ExperimentalCoroutinesApi::class)
private fun answer(user: UserInfo, onEnter: () -> Unit, onNewEnter: () -> Unit, onExit: () -> Unit, onError: (code: Int, msg: String, extra: Map<String, String>? ) -> Unit) {
private fun answer(
user: UserInfo,
onEnter: () -> Unit,
onNewEnter: () -> Unit,
onExit: () -> Unit,
onError: (code: Int, msg: String, extra: Map<String, String>?) -> Unit
) {
facade.also { itx ->
if (hasAnswered) {
return
@@ -482,7 +496,7 @@ internal class CallChatWindowManager {
hasAnswered = true
itx.answer(user.sn)
.onEach {
when(it) {
when (it) {
is EnterRoomSuccess -> {
onEnter.invoke()
}
@@ -507,7 +521,12 @@ internal class CallChatWindowManager {
}
}
private fun doRefuse(user: UserInfo, notify: Boolean = true, inComingView: View, isAnswerFail: Boolean) {
private fun doRefuse(
user: UserInfo,
notify: Boolean = true,
inComingView: View,
isAnswerFail: Boolean
) {
refuse(user,
onSuccess = {
if (notify) {
@@ -529,7 +548,11 @@ internal class CallChatWindowManager {
}
@OptIn(ExperimentalCoroutinesApi::class)
private fun refuse(user: UserInfo, onSuccess: () -> Unit, onError: (code: Int, msg: String, extra: Map<String, String>?) -> Unit){
private fun refuse(
user: UserInfo,
onSuccess: () -> Unit,
onError: (code: Int, msg: String, extra: Map<String, String>?) -> Unit
) {
facade.also {
if (hasRefused) {
return
@@ -537,7 +560,7 @@ internal class CallChatWindowManager {
hasRefused = true
it.refuse(user.sn)
.onEach { itx ->
when(itx) {
when (itx) {
is RefuseState.Success -> {
onSuccess.invoke()
}
@@ -591,13 +614,17 @@ internal class CallChatWindowManager {
var counter = 1
while (true) {
delay(1000)
emit(1000L * (counter ++))
emit(1000L * (counter++))
}
}
}
@OptIn(ExperimentalCoroutinesApi::class)
private fun hangUp(user: UserInfo, onSuccess: () -> Unit, onError:(code: Int, msg: String, extra: Map<String, String>?) -> Unit) {
private fun hangUp(
user: UserInfo,
onSuccess: () -> Unit,
onError: (code: Int, msg: String, extra: Map<String, String>?) -> Unit
) {
facade.also {
if (hasHangUpped) {
return
@@ -605,13 +632,16 @@ internal class CallChatWindowManager {
hasHangUpped = true
it.handUp(user.sn)
.onEach { itx ->
when(itx) {
when (itx) {
HangUpState.Success -> {
onSuccess.invoke()
}
is HangUpState.Error -> {
hasHangUpped = false
log(TAG, "-- 挂断失败 --: code:: ${itx.code}; msg:: ${itx.msg}; extra:: ${itx.extra}")
log(
TAG,
"-- 挂断失败 --: code:: ${itx.code}; msg:: ${itx.msg}; extra:: ${itx.extra}"
)
onError.invoke(itx.code, itx.msg, itx.extra)
}
else -> {