[2.13.0-merge]yakun and code style

This commit is contained in:
zhongchao
2022-11-21 18:07:52 +08:00
844 changed files with 3197 additions and 29173 deletions

View File

@@ -1,11 +1,12 @@
package com.mogo.eagle.core.function.chat.facade.analytics
import com.mogo.commons.analytics.AnalyticsUtils
import com.mogo.eagle.core.function.api.chat.biz.IMoGoAnalyticsFacade
import com.mogo.eagle.core.function.chat.facade.bridge.BridgeApi
object ChatAnalyticsFacade: IMoGoAnalyticsFacade {
override fun track(eventType: String, data: Map<String, Any>?) {
BridgeApi.analytics()?.track(eventType, data)
AnalyticsUtils.track(eventType, data)
}
}

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,13 +16,4 @@ internal object BridgeApi {
internal fun context(): Context = contextHolder?.get() ?: Utils.getApp()
internal fun intentManager() = apis?.intentManagerApi
internal fun statusManager() = apis?.statusManagerApi
internal fun analytics() = apis?.analyticsApi
internal fun topViewManager() = apis?.topViewManager
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
@@ -30,8 +31,8 @@ import com.mogo.eagle.core.function.chat.facade.bridge.BridgeApi
import com.mogo.eagle.core.function.chat.facade.utils.log
import com.mogo.eagle.core.function.chat.facade.voice.VoiceControlFacade.REQUEST_CLOUD_VOICE_CALL
import com.mogo.eagle.core.utilcode.kotlin.*
import com.mogo.eagle.core.utilcode.mogo.glide.GlideRoundedCornersTransform
import com.mogo.eagle.core.utilcode.mogo.glide.GlideRoundedCornersTransform.CornerType.LEFT
import com.mogo.eagle.core.utilcode.mogo.glide.transform.GlideRoundedCornersTransform
import com.mogo.eagle.core.utilcode.mogo.glide.transform.GlideRoundedCornersTransform.CornerType.LEFT
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.Channel.Factory.RENDEZVOUS
@@ -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 -> {

View File

@@ -3,13 +3,14 @@ package com.mogo.eagle.core.function.chat.facade.voice
import android.content.Context
import android.content.Intent
import com.mogo.commons.AbsMogoApplication
import com.mogo.commons.module.intent.IMogoIntentListener
import com.mogo.commons.module.intent.IntentManager
import com.mogo.commons.voice.AIAssist
import com.mogo.commons.voice.IMogoVoiceCmdCallBack
import com.mogo.eagle.core.function.api.chat.biz.IMoGoVoiceControlFacade
import com.mogo.eagle.core.function.api.chat.biz.IMoGoVoiceControlFacade.IMoGoVoiceCallback
import com.mogo.eagle.core.function.chat.facade.bridge.BridgeApi
import com.mogo.eagle.core.function.chat.facade.utils.log
import com.mogo.service.intent.IMogoIntentListener
import java.lang.ref.WeakReference
import java.util.concurrent.CopyOnWriteArrayList
import java.util.concurrent.atomic.AtomicBoolean
@@ -48,10 +49,6 @@ object VoiceControlFacade: IMoGoVoiceControlFacade, IMogoVoiceCmdCallBack, IMogo
private var onSpeechFinish: WeakReference<onSpeedFinish>? = null
private val intentManager by lazy {
BridgeApi.intentManager()
}
override fun speak(context: Context, content: String, listener: IMoGoVoiceCallback) {
listeners += WeakReference(listener)
AIAssist.getInstance(context).speakTTSVoiceWithLevel(content,AIAssist.LEVEL3 ,this)
@@ -123,10 +120,8 @@ object VoiceControlFacade: IMoGoVoiceControlFacade, IMogoVoiceCmdCallBack, IMogo
}
hasRegister.set(true)
AIAssist.getInstance(BridgeApi.context()).registerUnWakeupCommand(VOICE_REGISTER_CANCEL_CALL, customCancelCallArray, this)
intentManager?.also {
it.registerIntentListener(VOICE_INTENT_CANCEL_CALL_COMMAND, this)
it.registerIntentListener(VOICE_INTENT_REFUSE_CALL, this)
}
IntentManager.getInstance().registerIntentListener(VOICE_INTENT_CANCEL_CALL_COMMAND, this)
IntentManager.getInstance().registerIntentListener(VOICE_INTENT_REFUSE_CALL, this)
}
override fun registerInviteJoinTeam(context: Context, listener: IMoGoVoiceCallback) {
@@ -156,13 +151,13 @@ object VoiceControlFacade: IMoGoVoiceControlFacade, IMogoVoiceCmdCallBack, IMogo
override fun registerIntentInComingCall(listener: IMoGoVoiceCallback) {
listeners += WeakReference(listener)
intentManager?.registerIntentListener(VOICE_INTENT_ANSWER_CALL, this)
intentManager?.registerIntentListener(VOICE_INTENT_REFUSE_CALL, this)
IntentManager.getInstance().registerIntentListener(VOICE_INTENT_ANSWER_CALL, this)
IntentManager.getInstance().registerIntentListener(VOICE_INTENT_REFUSE_CALL, this)
}
override fun unRegisterIntentInComingCall(context: Context) {
intentManager?.unregisterIntentListener(VOICE_INTENT_ANSWER_CALL, this)
intentManager?.unregisterIntentListener(VOICE_INTENT_REFUSE_CALL, this)
IntentManager.getInstance().unregisterIntentListener(VOICE_INTENT_ANSWER_CALL, this)
IntentManager.getInstance().unregisterIntentListener(VOICE_INTENT_REFUSE_CALL, this)
}
override fun speakAndRegisterCall(onCmdAgree: (Boolean) -> Unit, onSpeakFinish: () -> Unit, listener: IMoGoVoiceCallback) {
@@ -204,10 +199,8 @@ object VoiceControlFacade: IMoGoVoiceControlFacade, IMogoVoiceCmdCallBack, IMogo
hasRegister.set(false)
listeners.clear()
AIAssist.getInstance(BridgeApi.context()).unregisterUnWakeupCommand(VOICE_REGISTER_CANCEL_CALL, this)
intentManager?.also {
it.unregisterIntentListener(VOICE_INTENT_CANCEL_CALL_COMMAND, this)
it.unregisterIntentListener(VOICE_INTENT_REFUSE_CALL, this)
}
IntentManager.getInstance().unregisterIntentListener(VOICE_INTENT_CANCEL_CALL_COMMAND, this)
IntentManager.getInstance().unregisterIntentListener(VOICE_INTENT_REFUSE_CALL, this)
}
override fun onIntentReceived(cmd: String?, intent: Intent?) {