From bd9af07fb86c893dac28d7542387c1047f298200 Mon Sep 17 00:00:00 2001 From: tongchenfei Date: Wed, 13 May 2020 17:05:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=86=E5=A4=87=E6=8E=A5=E5=85=A5=E8=AF=AD?= =?UTF-8?q?=E9=9F=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/share/ShareVoiceCmdReceiver.kt | 43 +++++++++++++++---- .../com/mogo/module/share/bean/ShareBtn.kt | 2 +- .../module/share/constant/ShareConstants.java | 25 +++++++---- .../share/dialog/LaucherShareDialog.java | 28 +++++------- .../mogo/module/share/manager/UploadHelper.kt | 23 ++++++++++ 5 files changed, 85 insertions(+), 36 deletions(-) create mode 100644 modules/mogo-module-share/src/main/java/com/mogo/module/share/manager/UploadHelper.kt diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/ShareVoiceCmdReceiver.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/ShareVoiceCmdReceiver.kt index 5a0d662a84..57f39019d6 100644 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/ShareVoiceCmdReceiver.kt +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/ShareVoiceCmdReceiver.kt @@ -4,22 +4,49 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.mogo.module.share.constant.ShareConstants -import com.mogo.module.share.constant.ShareConstants.VOICE_CMD_PUB_TROUBLE_HELP +import com.mogo.module.share.constant.ShareConstants.* +import com.mogo.module.share.manager.UploadHelper import com.mogo.utils.logger.Logger /** * 用于接收唤醒词指令,现在只接收 com.zhidao.speech.awake.notify 这一条广播 */ class ShareVoiceCmdReceiver : BroadcastReceiver() { + private val TAG = "ShareVoiceCmdReceiver" override fun onReceive(context: Context, intent: Intent) { // 接收唤醒词指令 - val command = intent.getStringExtra("command") - Logger.d("ShareCmdReceiver", "收到唤醒词指令: $command") - if (command == VOICE_CMD_PUB_TROUBLE_HELP) { - // 开启服务,准备上报求助 - val seekHelp = Intent(context, VoiceCmdService::class.java) - seekHelp.putExtra(ShareConstants.VOICE_CMD_SERVICE_EVENT_KEY, ShareConstants.VOICE_CMD_SERVICE_SEEK_HELP) - context.startService(seekHelp) + val command = intent.getStringExtra("command")?:"" + Logger.d(TAG, "收到唤醒词指令: $command") + when (command) { + VOICE_CMD_PUB_TROUBLE_HELP -> { + // 开启服务,准备上报求助 + val seekHelp = Intent(context, VoiceCmdService::class.java) + seekHelp.putExtra(ShareConstants.VOICE_CMD_SERVICE_EVENT_KEY, ShareConstants.VOICE_CMD_SERVICE_SEEK_HELP) + context.startService(seekHelp) + } + VOICE_CMD_GO_TO_SHARE ->{ + when (intent.getStringExtra("ob") ?: "") { + "积水"->{ + UploadHelper.upload(context, TYPE_STAGNANT_WATER) + } + "积冰"->{ + UploadHelper.upload(context, TYPE_ROAD_ICY) + } + "大雾"->{ + UploadHelper.upload(context, TYPE_DENSE_FOG) + } + "事故"->{ + UploadHelper.upload(context, TYPE_ACCIDENT) + } + } + } + VOICE_CMD_PUB_ROAD_CONDITION->{ + if(intent.getStringExtra("ob")?:"" == "路况") { + // 上报实时路况 + Logger.d(TAG, "分享框准备触发上报实时路况") + UploadHelper.upload(context, TYPE_REAL_TIME_TRAFFIC) + } + } } } } \ No newline at end of file diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/ShareBtn.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/ShareBtn.kt index 5dc5675a02..bbadda8f06 100644 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/ShareBtn.kt +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/bean/ShareBtn.kt @@ -6,4 +6,4 @@ package com.mogo.module.share.bean * @param icon 分享按钮图标资源,暂时用不到,默认为空,以后如果引入服务端配置按钮,图片资源可以用这个参数 * @param iconRes 分享按钮图标本地资源id,默认是-1 */ -data class ShareBtn(var type: Int, var icon: String = "", var iconRes: Int = -1, var content: String) +data class ShareBtn(var type: String, var icon: String = "", var iconRes: Int = -1, var content: String) diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/constant/ShareConstants.java b/modules/mogo-module-share/src/main/java/com/mogo/module/share/constant/ShareConstants.java index 9d5e0e6881..8a676c9061 100644 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/constant/ShareConstants.java +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/constant/ShareConstants.java @@ -19,15 +19,22 @@ public class ShareConstants { public static final String VOICE_CMD_SERVICE_EVENT_KEY = "type"; public static final int VOICE_CMD_SERVICE_SEEK_HELP = 1; + // 此处只记录了事故、实时路况、道路积水、道路结冰、浓雾,至于拥堵、交通检查和封路是在extention模块里面管理 public static final String VOICE_CMD_PUB_TROUBLE_HELP = "com.zhidao.auxiliaryDriving.pubTroubleHelp"; + public static final String VOICE_CMD_GO_TO_SHARE = "com.zhidao.share"; + /** + * 这个是实时路况,不是拥堵,拥堵放在了extention模块里面处理 + */ + public static final String VOICE_CMD_PUB_ROAD_CONDITION = "com.zhidao.pathfinder.report" + + ".roadCondition"; - public static final int TYPE_BLOCK = 1; - public static final int TYPE_TRAFFIC_CHECK = 2; - public static final int TYPE_CLOSURE = 3; - public static final int TYPE_ACCIDENT = 4; - public static final int TYPE_REAL_TIME_TRAFFIC = 5; - public static final int TYPE_SEEK_HELP = 6; - public static final int TYPE_STAGNANT_WATER = 7; - public static final int TYPE_ROAD_ICY = 8; - public static final int TYPE_DENSE_FOG = 9; + public static final String TYPE_BLOCK = "1"; + public static final String TYPE_TRAFFIC_CHECK = "2"; + public static final String TYPE_CLOSURE = "3"; + public static final String TYPE_ACCIDENT = "10013"; + public static final String TYPE_REAL_TIME_TRAFFIC = "10015"; + public static final String TYPE_SEEK_HELP = "6"; + public static final String TYPE_STAGNANT_WATER = "10008"; + public static final String TYPE_ROAD_ICY = "10011"; + public static final String TYPE_DENSE_FOG = "10010"; } diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/dialog/LaucherShareDialog.java b/modules/mogo-module-share/src/main/java/com/mogo/module/share/dialog/LaucherShareDialog.java index 60c33b3acc..4e167b9c92 100644 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/dialog/LaucherShareDialog.java +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/dialog/LaucherShareDialog.java @@ -25,6 +25,7 @@ import com.mogo.module.share.constant.ShareConstants; import com.mogo.module.share.listener.OnShareBtnClickListener; import com.mogo.module.share.manager.ISeekHelpListener; import com.mogo.module.share.manager.SeekHelpManager; +import com.mogo.module.share.manager.UploadHelper; import com.mogo.service.IMogoServiceApis; import com.mogo.service.MogoServicePaths; import com.mogo.service.analytics.IMogoAnalytics; @@ -106,19 +107,18 @@ public class LaucherShareDialog implements View.OnClickListener { private void initListener() { - adapter.setOnShareBtnClickListener(new OnShareBtnClickListener() { @Override public void onShareBtnClick(@NotNull ShareBtn shareBtn) { Logger.d(TAG,"分享按钮点击: "+shareBtn); -// traceData("1"); -// if (shareBtn.getType() == ShareConstants.TYPE_SEEK_HELP) { -// // 点击发起求助 -// SeekHelpManager.INSTANCE.seekHelp(mContext,seekListener,true); -// }else{ -// sendShareReceiver(shareBtn.getType() + ""); -// dismiss(); -// } + traceData("1"); + if (ShareConstants.TYPE_SEEK_HELP.equalsIgnoreCase(shareBtn.getType())) { + // 点击发起求助 + SeekHelpManager.INSTANCE.seekHelp(mContext,seekListener,true); + }else{ + sendShareReceiver(shareBtn.getType()); + dismiss(); + } } }); @@ -211,15 +211,7 @@ public class LaucherShareDialog implements View.OnClickListener { * 发送广播 1拥堵,2交通检查,3封路 */ private void sendShareReceiver(String type) { - mStatusManager.setUploadingStatus("CARD_TYPE_ROAD_CONDITION", true); - - Logger.d("LaucherShareDialog", "LaucherShareDialog sendShareReceiver ---->"); - Intent intent = new Intent(); - intent.setAction("com.zhidao.roadcondition.share"); - intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); - intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - intent.putExtra("type", type); - mContext.sendBroadcast(intent); + UploadHelper.INSTANCE.upload(mContext, type); } /** diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/manager/UploadHelper.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/manager/UploadHelper.kt new file mode 100644 index 0000000000..a5edbc9e34 --- /dev/null +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/manager/UploadHelper.kt @@ -0,0 +1,23 @@ +package com.mogo.module.share.manager + +import android.content.Context +import android.content.Intent +import com.mogo.module.share.ShareControl +import com.mogo.module.share.dialog.LaucherShareDialog +import com.mogo.utils.logger.Logger + +/** + * 上报工具类 + */ +object UploadHelper { + fun upload(context:Context, type: String) { + ShareControl.getInstance(context).mogoServiceApis.statusManagerApi.setUploadingStatus("CARD_TYPE_ROAD_CONDITION", true) + Logger.d("UploadHelper", "upload ---->") + val intent = Intent() + intent.action = "com.zhidao.roadcondition.share" + intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND) + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES) + intent.putExtra("type", type) + context.sendBroadcast(intent) + } +} \ No newline at end of file