new#优化代码
This commit is contained in:
@@ -1,84 +0,0 @@
|
||||
package com.mogo.module.v2x.adapter.holder;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mogo.module.common.entity.MarkerExploreWay;
|
||||
import com.mogo.module.common.entity.MarkerLocation;
|
||||
import com.mogo.module.common.entity.V2XEventShowEntity;
|
||||
import com.mogo.module.v2x.R;
|
||||
import com.mogo.module.v2x.scenario.view.IV2XWindow;
|
||||
import com.mogo.module.v2x.voice.V2XVoiceCallbackListener;
|
||||
import com.mogo.module.v2x.voice.V2XVoiceConstants;
|
||||
import com.mogo.module.v2x.voice.V2XVoiceManager;
|
||||
|
||||
|
||||
/**
|
||||
* created by wujifei on 2020/12/29 20:39
|
||||
* describe:线路推荐
|
||||
*/
|
||||
public class V2XRecommendRouteVH extends V2XBaseViewHolder<V2XEventShowEntity> {
|
||||
private TextView mTvAddress;
|
||||
private ImageView mIvToNav, mIvClose;
|
||||
private MarkerExploreWay mNoveltyInfo;
|
||||
|
||||
public V2XRecommendRouteVH(ViewGroup viewGroup, IV2XWindow v2XWindow) {
|
||||
super(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_v2x_recommend_route, viewGroup, false), v2XWindow);
|
||||
mTvAddress = itemView.findViewById(R.id.tvAddress);
|
||||
mIvToNav = itemView.findViewById(R.id.ivToNav);
|
||||
mIvClose = itemView.findViewById(R.id.ivClose);
|
||||
mIvToNav.setOnClickListener(v -> triggerStartNavi(mNoveltyInfo));
|
||||
mIvClose.setOnClickListener(v -> delayedCloseWindow());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView(V2XEventShowEntity v2XEventShowEntity) {
|
||||
MarkerLocation markerLocation = new MarkerLocation();
|
||||
markerLocation.setLon(v2XEventShowEntity.getV2XRecommendRouteEntity().getToPoint().get(0));
|
||||
markerLocation.setLat(v2XEventShowEntity.getV2XRecommendRouteEntity().getToPoint().get(1));
|
||||
mNoveltyInfo = new MarkerExploreWay();
|
||||
mNoveltyInfo.setLocation(markerLocation);
|
||||
mTvAddress.setText("前往 " + v2XEventShowEntity.getV2XRecommendRouteEntity().getFormatAddress());
|
||||
registerUnwakeNavi();
|
||||
|
||||
}
|
||||
|
||||
private V2XVoiceCallbackListener mStartNavi = (command, intent) -> {
|
||||
try {
|
||||
triggerStartNavi(mNoveltyInfo);
|
||||
Log.d("V2XRecommendRouteVH", "mStartNavi ------");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
};
|
||||
|
||||
private V2XVoiceCallbackListener mCancleNavi = (command, intent) -> {
|
||||
try {
|
||||
//取消导航
|
||||
unRegisterUnwakeNavi();
|
||||
delayedCloseWindow();
|
||||
Log.d("V2XRecommendRouteVH", "cancleNavi ------");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
};
|
||||
|
||||
private void registerUnwakeNavi() {
|
||||
V2XVoiceManager.INSTANCE
|
||||
.registerWakeCmd(V2XVoiceConstants.V2X_CONFIRM_ACTION,
|
||||
mStartNavi)
|
||||
.registerWakeCmd(V2XVoiceConstants.V2X_CANCLE_ACTION,
|
||||
mCancleNavi);
|
||||
}
|
||||
|
||||
private void unRegisterUnwakeNavi() {
|
||||
V2XVoiceManager.INSTANCE
|
||||
.unRegisterWakeCmd(V2XVoiceConstants.V2X_CONFIRM_ACTION)
|
||||
.unRegisterWakeCmd(V2XVoiceConstants.V2X_CANCLE_ACTION);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.mogo.module.v2x.adapter.holder
|
||||
|
||||
import android.content.Intent
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import com.mogo.commons.voice.AIAssist
|
||||
import com.mogo.commons.voice.VoicePreemptType
|
||||
import com.mogo.module.common.entity.MarkerExploreWay
|
||||
import com.mogo.module.common.entity.MarkerLocation
|
||||
import com.mogo.module.common.entity.V2XEventShowEntity
|
||||
import com.mogo.module.v2x.R
|
||||
import com.mogo.module.v2x.scenario.view.IV2XWindow
|
||||
import com.mogo.module.v2x.utils.V2XUtils
|
||||
import com.mogo.module.v2x.voice.V2XVoiceCallbackListener
|
||||
import com.mogo.module.v2x.voice.V2XVoiceConstants
|
||||
import com.mogo.module.v2x.voice.V2XVoiceManager.registerUnWakeVoice
|
||||
import com.mogo.module.v2x.voice.V2XVoiceManager.unRegisterUnWakeVoice
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* created by wujifei on 2020/12/31 16:10
|
||||
* describe:
|
||||
*/
|
||||
class V2XRecommendRouteVH(viewGroup: ViewGroup, v2XWindow: IV2XWindow<*>) : V2XBaseViewHolder<V2XEventShowEntity>(
|
||||
LayoutInflater.from(viewGroup.context).inflate(R.layout.item_v2x_recommend_route, viewGroup, false), v2XWindow), V2XVoiceCallbackListener {
|
||||
private var mTvAddress: TextView? = null
|
||||
private var mIvToNav: ImageView? = null
|
||||
private var mIvClose: ImageView? = null
|
||||
private var mNoveltyInfo: MarkerExploreWay? = null
|
||||
private val mainScope = MainScope()
|
||||
|
||||
init {
|
||||
mTvAddress = itemView.findViewById<TextView>(R.id.tvAddress)
|
||||
mIvToNav = itemView.findViewById<ImageView>(R.id.ivToNav)
|
||||
mIvClose = itemView.findViewById<ImageView>(R.id.ivClose)
|
||||
mIvToNav?.setOnClickListener { triggerStartNavi(mNoveltyInfo) }
|
||||
mIvClose?.setOnClickListener { delayedCloseWindow() }
|
||||
itemView.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
|
||||
override fun onViewAttachedToWindow(view: View) {
|
||||
registerUnwakeNavi()
|
||||
mainScope.launch {
|
||||
delay(1000 * 20)
|
||||
delayedCloseWindow()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewDetachedFromWindow(view: View) {
|
||||
unRegisterUnwakeNavi()
|
||||
AIAssist.getInstance(V2XUtils.getApp()).breakOffSpeak()
|
||||
mainScope.cancel()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
override fun initView(viewData: V2XEventShowEntity?) {
|
||||
viewData?.let {
|
||||
val markerLocation = MarkerLocation()
|
||||
markerLocation.lon = it.getV2XRecommendRouteEntity().getToPoint().get(0)
|
||||
markerLocation.lat = it.getV2XRecommendRouteEntity().getToPoint().get(1)
|
||||
mNoveltyInfo = MarkerExploreWay()
|
||||
mNoveltyInfo?.setLocation(markerLocation)
|
||||
mTvAddress!!.text = "前往 ${it.getV2XRecommendRouteEntity().getFormatAddress()}"
|
||||
AIAssist.getInstance(V2XUtils.getApp()).speakTTSVoice(it.getV2XRecommendRouteEntity().getTts(), VoicePreemptType.PREEMPT_TYPE_IMMEADIATELY, null)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onCallback(command: String?, intent: Intent?) {
|
||||
when (command) {
|
||||
V2XVoiceConstants.V2X_CONFIRM_ACTION -> triggerStartNavi(mNoveltyInfo)
|
||||
V2XVoiceConstants.V2X_CANCLE_ACTION -> delayedCloseWindow()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun registerUnwakeNavi() {
|
||||
registerUnWakeVoice(V2XVoiceConstants.V2X_CONFIRM_ACTION, this)
|
||||
registerUnWakeVoice(V2XVoiceConstants.V2X_CANCLE_ACTION, this)
|
||||
}
|
||||
|
||||
private fun unRegisterUnwakeNavi() {
|
||||
unRegisterUnWakeVoice(V2XVoiceConstants.V2X_CONFIRM_ACTION)
|
||||
unRegisterUnWakeVoice(V2XVoiceConstants.V2X_CANCLE_ACTION)
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,12 @@
|
||||
package com.mogo.module.v2x.scenario.scene.destination
|
||||
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.mogo.commons.voice.AIAssist
|
||||
import com.mogo.commons.voice.VoicePreemptType
|
||||
import com.mogo.module.common.entity.V2XMessageEntity
|
||||
import com.mogo.module.common.entity.V2XRecommendRouteEntity
|
||||
import com.mogo.module.v2x.R
|
||||
import com.mogo.module.v2x.V2XServiceManager
|
||||
import com.mogo.module.v2x.scenario.impl.AbsV2XScenario
|
||||
import com.mogo.module.v2x.utils.V2XUtils
|
||||
import com.mogo.service.windowview.IMogoTopViewStatusListener
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* created by wujifei on 2020/12/29 17:57
|
||||
@@ -52,7 +44,7 @@ class V2XRecommendRouteScenario : AbsV2XScenario<V2XRecommendRouteEntity>() {
|
||||
v2XWindow?.let {
|
||||
val layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
V2XUtils.getApp().resources.getDimension(R.dimen.module_v2x_fatigue_driving_window_height_ground).toInt())
|
||||
V2XServiceManager.getMogoTopViewManager().addView(it.view, layoutParams, mogoTopViewStatusListener)
|
||||
V2XServiceManager.getMogoTopViewManager().addView(it.view, layoutParams)
|
||||
it.show(v2XMessageEntity.content)
|
||||
|
||||
}
|
||||
@@ -80,29 +72,5 @@ class V2XRecommendRouteScenario : AbsV2XScenario<V2XRecommendRouteEntity>() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
val mogoTopViewStatusListener: IMogoTopViewStatusListener = object : IMogoTopViewStatusListener {
|
||||
private val mainScope = MainScope()
|
||||
override fun onViewAdded(view: View?) {
|
||||
AIAssist.getInstance(V2XUtils.getApp()).speakTTSVoice(v2XMessageEntity.content.getTts(),VoicePreemptType.PREEMPT_TYPE_IMMEADIATELY,null)
|
||||
mainScope.launch {
|
||||
delay(1000 * 20)
|
||||
closeWindow()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewRemoved(view: View?) {
|
||||
AIAssist.getInstance(V2XUtils.getApp()).breakOffSpeak()
|
||||
mainScope.cancel()
|
||||
}
|
||||
|
||||
override fun beforeViewAddAnim(view: View?) {
|
||||
|
||||
}
|
||||
|
||||
override fun beforeViewRemoveAnim(view: View?) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user