Merge branch 'dev' of gitlab.zhidaoauto.com:ecos/yycp-service/Launcher into dev

This commit is contained in:
tongchenfei
2020-11-17 17:49:20 +08:00
499 changed files with 1735 additions and 14083 deletions

View File

@@ -18,6 +18,11 @@ public class ServiceConst {
*/
public static final String PATH_REFRESH_STRATEGY = "/strategy/refresh";
/**
* tts语音配置
*/
public static final String PATH_TTS_CONFIG = "/ttsserver/tts";
/**
* 倒计时消息
*/

View File

@@ -3,7 +3,6 @@ package com.mogo.module.service.launchercard;
public class LauncherCardRefreshStrategy {
private long interval; // 间隔时间
private LauncherCardRefreshType type = LauncherCardRefreshType.OnlineCar;
private LauncherCardRefreshStrategy next;
@@ -15,10 +14,6 @@ public class LauncherCardRefreshStrategy {
this.msgType = msgType;
}
public void setType( LauncherCardRefreshType type ) {
this.type = type;
}
public int getMsgType() {
return msgType;
}
@@ -27,31 +22,6 @@ public class LauncherCardRefreshStrategy {
return interval;
}
public LauncherCardRefreshType getType() {
return type;
}
public LauncherCardRefreshType getNextType() {
if ( type == LauncherCardRefreshType.ExploreWay ) {
type = LauncherCardRefreshType.OnlineCar;
} else {
type = LauncherCardRefreshType.ExploreWay;
}
return type;
}
public void next(){
getNextType();
}
public int getLimit() {
return type.limit;
}
public String getDesc() {
return type.desc;
}
public int getRadius() {
return 2_000;
}

View File

@@ -2,14 +2,33 @@
package com.mogo.module.service.launchercard;
public enum LauncherCardRefreshType {
ExploreWay( 50, "道路事件" ),
OnlineCar( 20, "车友" );
public int limit;
public String desc;
Weather( "News", "weather", "天气" ),
News( "NearRoads", "news", "新闻" ),
NearRoads( "ExplorerWay", "nearRoads", "近路" ),
// TrafficRestriction( "NearRoads", "trafficRestriction" ),
ExplorerWay( "OnlineCar", "friendAndPois", "道路事件" ),
OnlineCar( "Weather", "friendAndPois", "车友" );
LauncherCardRefreshType( int limit, String desc ) {
this.limit = limit;
private String next;
private String val;
private String desc;
LauncherCardRefreshType( String next, String val, String desc ) {
this.next = next;
this.val = val;
this.desc = desc;
}
public String getNext() {
return next;
}
public String getVal() {
return val;
}
public String getDesc() {
return desc;
}
}

View File

@@ -10,21 +10,25 @@ import android.text.TextUtils;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.network.ParamsProvider;
import com.mogo.commons.network.SubscribeImpl;
import com.mogo.commons.network.Utils;
import com.mogo.commons.voice.AIAssist;
import com.mogo.map.MogoLatLng;
import com.mogo.map.location.MogoLocation;
import com.mogo.module.common.entity.MarkerResponse;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.service.MarkerServiceHandler;
import com.mogo.module.service.R;
import com.mogo.module.service.network.RefreshCallback;
import com.mogo.module.service.network.RefreshModel;
import com.mogo.module.service.network.ZhidaoRefreshModel;
import com.mogo.module.service.network.bean.LauncherCardAdvertisementData;
import com.mogo.module.service.network.bean.TtsConfigBody;
import com.mogo.module.service.network.bean.TtsConfigData;
import com.mogo.service.passport.IMogoTicketCallback;
import com.mogo.utils.AppUtils;
import com.mogo.utils.NetworkUtils;
import com.mogo.utils.glide.GlideApp;
import com.mogo.utils.logger.Logger;
import com.mogo.utils.network.RequestOptions;
import com.mogo.utils.network.utils.GsonUtil;
import com.mogo.utils.storage.SharedPrefsMgr;
import java.util.ArrayList;
@@ -49,15 +53,10 @@ class LauncherCardRefresher {
public static final String KEY_LauncherCardTipCounter = "LauncherCardTipCounter";
public static final String KEY_LauncherCardTipLastTipTime = "LauncherCardTipLastTipTime";
public static final String KEY_LauncherCardExplorerWayAndOnlineCarTipCounter = "LauncherCardExplorerWayAndOnlineCarTipCounter";
public static final String KEY_LauncherCardExplorerWayAndOnlineCarTipLastTipTime = "LauncherCardExplorerWayAndOnlineCarTipLastTipTime";
public static final String KEY_LauncherCardExplorerWayAndOnlineCarTipLastTipType = "LauncherCardExplorerWayAndOnlineCarTipLastTipType";
public static final String KEY_LAST_LOAD_TTS_TYPE = "keyLastLoadTtsType";
private static volatile LauncherCardRefresher sInstance;
// 刷新道路事件/车友
public static final int MSG_EXPLORER_WAY_OR_ONLINE_CAR_DATA = 2020;
// 开始引导策略
public static final int MSG_INDUCE = 2019;
// 刷新卡片默认显示内容
@@ -68,6 +67,10 @@ class LauncherCardRefresher {
public static final int MSG_LOAD_NET_CONFIG = 2023;
// 默认播报
public static final int MSG_START_LOOP_DEFAULT_CARD = 2024;
// 等待网络
public static final int MSG_WAIT_NETWORK = 2025;
public static final long ONE_SECOND = 1000L;
public static final long ONE_MINUTE = 60 * 1000L;
public static final long ONE_DAY = 24 * 60 * ONE_MINUTE;
private String mLaunchTTSText;
@@ -80,11 +83,6 @@ class LauncherCardRefresher {
*/
private int mDefaultConfigCounter = 0;
/**
* 事件/车友播报次数
*/
private int mMsgExplorerWayOrOnlineCarDataCounter = 0;
/**
* 因为缓存ticket失效导致失败的情况需要重新请求ticket然后再次获取数据这里重试3次
*/
@@ -124,6 +122,8 @@ class LauncherCardRefresher {
return;
}
switch ( msg.what ) {
case MSG_WAIT_NETWORK:
trtRequestNetworkConfigStrategy();
case MSG_LOAD_NET_CONFIG:
loadNetworkConfigStrategy();
break;
@@ -135,13 +135,6 @@ class LauncherCardRefresher {
case MSG_INDUCE:
handleInduceStrategy();
break;
case MSG_EXPLORER_WAY_OR_ONLINE_CAR_DATA:
try {
handleRefreshExplorerWayOrOnlineCarMsg();
} catch ( Exception e ) {
Logger.e( TAG, e, "error when refresh launcher card." );
}
break;
case MSG_START_LOOP_DEFAULT_CARD:
renderDefaultLauncherCardConfig( false );
break;
@@ -159,14 +152,8 @@ class LauncherCardRefresher {
private RefreshModel mRefreshModel;
private ZhidaoRefreshModel mZhidaoRefreshModel;
private LauncherCardRefreshStrategy mExplorerWayOrOnlineCarDataStrategy = new LauncherCardRefreshStrategy(
18 * ONE_MINUTE, null, MSG_EXPLORER_WAY_OR_ONLINE_CAR_DATA
);
private LauncherCardRefreshStrategy mInduceStrategy = new LauncherCardRefreshStrategy(
18 * ONE_MINUTE, mExplorerWayOrOnlineCarDataStrategy, MSG_INDUCE
);
private LauncherCardRefreshStrategy mLauncherCardConfigStrategy = new LauncherCardRefreshStrategy(
2 * ONE_MINUTE, mExplorerWayOrOnlineCarDataStrategy, MSG_REFRESH_DEFAULT_CARD
2 * ONE_MINUTE, null, MSG_REFRESH_DEFAULT_CARD
);
private LauncherCardRefreshStrategy mRefreshStrategy = mLauncherCardConfigStrategy;
@@ -178,24 +165,32 @@ class LauncherCardRefresher {
return;
}
Logger.d( TAG, "start" );
mLaunchTTSText = mContext.getString( R.string.module_service_open_app_tip );
mDefaultConfigCounter = 0;
mRefreshTicketCounter = 0;
mMsgExplorerWayOrOnlineCarDataCounter = 0;
mRefreshStrategy = mLauncherCardConfigStrategy;
// 延时加载数据已保证accOn之后网络恢复正常
long delay = ONE_MINUTE;
if ( NetworkUtils.isConnected( mContext ) ) {
delay = 0L;
}
mHandler.sendEmptyMessageDelayed( MSG_LOAD_NET_CONFIG, delay );
trtRequestNetworkConfigStrategy();
startInduceStrategy();
}
private void trtRequestNetworkConfigStrategy() {
if ( NetworkUtils.isConnected( mContext ) && MogoApisHandler.getInstance()
.getApis()
.getMapServiceApi()
.getSingletonLocationClient( mContext )
.getLastKnowLocation() != null ) {
mHandler.sendEmptyMessageDelayed( MSG_LOAD_NET_CONFIG, 0L );
} else {
mHandler.sendEmptyMessageDelayed( MSG_WAIT_NETWORK, 10 * ONE_SECOND );
}
}
/**
* 引导策略:本地策略 & 网络策略
*/
private void startInduceStrategy() {
if ( mRefreshStrategy == null ) {
return;
}
mHandler.sendEmptyMessageDelayed( mRefreshStrategy.getMsgType(), mRefreshStrategy.getInterval() );
mRefreshStop = false;
mStart = true;
@@ -205,11 +200,11 @@ class LauncherCardRefresher {
mRefreshStop = true;
mStart = false;
mHandler.removeMessages( MSG_INDUCE );
mHandler.removeMessages( MSG_EXPLORER_WAY_OR_ONLINE_CAR_DATA );
mHandler.removeMessages( MSG_REFRESH_DEFAULT_CARD );
mHandler.removeMessages( MSG_START_LOOP_DEFAULT_CARD );
mHandler.removeMessages( MSG_REFRESH_ADVERTISEMENT );
mHandler.removeMessages( MSG_LOAD_NET_CONFIG );
mHandler.removeMessages( MSG_WAIT_NETWORK );
Logger.d( TAG, "stop" );
}
@@ -234,8 +229,6 @@ class LauncherCardRefresher {
if ( mAdvertisements != null && !mAdvertisements.isEmpty() ) {
loopRenderAdvertisements( 0 );
startNextRefreshStrategy();
} else {
handleRefreshExplorerWayOrOnlineCarMsg();
}
}
@@ -246,104 +239,10 @@ class LauncherCardRefresher {
restart();
}
private void handleRefreshExplorerWayOrOnlineCarMsg() {
int counter = SharedPrefsMgr.getInstance( mContext ).getInt( KEY_LauncherCardExplorerWayAndOnlineCarTipCounter, 0 );
if ( counter >= 1 ) {
long lastTipTime = SharedPrefsMgr.getInstance( mContext ).getLong( KEY_LauncherCardExplorerWayAndOnlineCarTipLastTipTime, 0L );
if ( System.currentTimeMillis() - lastTipTime < 3 * ONE_DAY ) {
return;
} else {
SharedPrefsMgr.getInstance( mContext ).putInt( KEY_LauncherCardExplorerWayAndOnlineCarTipCounter, 0 );
counter = 0;
SharedPrefsMgr.getInstance( mContext ).putLong( KEY_LauncherCardExplorerWayAndOnlineCarTipLastTipTime, 0L );
}
}
SharedPrefsMgr.getInstance( mContext ).putInt( KEY_LauncherCardExplorerWayAndOnlineCarTipCounter, ++counter );
SharedPrefsMgr.getInstance( mContext ).putLong( KEY_LauncherCardExplorerWayAndOnlineCarTipLastTipTime, System.currentTimeMillis() );
MogoLocation location = MarkerServiceHandler.getMogoLocationClient().getLastKnowLocation();
if ( location == null ) {
restart();
return;
}
mMsgExplorerWayOrOnlineCarDataCounter++;
if ( mMsgExplorerWayOrOnlineCarDataCounter > 1 ) {
return;
}
String type = SharedPrefsMgr.getInstance( mContext ).getString( KEY_LauncherCardExplorerWayAndOnlineCarTipLastTipType, LauncherCardRefreshType.ExploreWay.name() );
LauncherCardRefreshType strategy = LauncherCardRefreshType.valueOf( type );
mRefreshStrategy.setType( strategy );
SharedPrefsMgr.getInstance( mContext ).putString( KEY_LauncherCardExplorerWayAndOnlineCarTipLastTipType, mRefreshStrategy.getNextType().name() );
MogoLatLng latLng = new MogoLatLng( location.getLatitude(), location.getLongitude() );
handleRefreshExplorerWayOrOnlineCarData( latLng, mRefreshStrategy.getType() );
}
private void handleRefreshExplorerWayOrOnlineCarData( MogoLatLng latLng, LauncherCardRefreshType type ) {
mRefreshModel.refreshLauncherCardDataSync( latLng,
mRefreshStrategy.getRadius(),
mRefreshStrategy.getLimit(),
new RefreshCallback< MarkerResponse >() {
@Override
public void onSuccess( MarkerResponse response ) {
notifyRefreshChanged( type, response );
startNextRefreshStrategy();
}
@Override
public void onFail() {
startNextRefreshStrategy();
}
} );
}
private boolean notifyRefreshChanged( LauncherCardRefreshType type, MarkerResponse response ) {
if ( response == null || response.getResult() == null ) {
return false;
}
String tts = mContext.getString( R.string.module_service_launcher_card_tips );
String info = mContext.getString( R.string.module_service_launcher_card_info );
LauncherCardRefreshType target = null;
int size = 0;
if ( type == LauncherCardRefreshType.ExploreWay ) {
if ( response.getResult().getExploreWay() != null && !response.getResult().getExploreWay().isEmpty() ) {
target = type;
size = response.getResult().getExploreWay().size();
} else if ( response.getResult().getOnlineCar() != null && !response.getResult().getOnlineCar().isEmpty() ) {
target = LauncherCardRefreshType.OnlineCar;
size = response.getResult().getOnlineCar().size();
}
} else if ( type == LauncherCardRefreshType.OnlineCar ) {
if ( response.getResult().getOnlineCar() != null && !response.getResult().getOnlineCar().isEmpty() ) {
target = type;
size = response.getResult().getOnlineCar().size();
} else if ( response.getResult().getExploreWay() != null && !response.getResult().getExploreWay().isEmpty() ) {
target = LauncherCardRefreshType.ExploreWay;
size = response.getResult().getExploreWay().size();
}
}
Logger.d( TAG, "返回数据情况:道路事件:%s, 车友: %s", response.getResult().getExploreWay() == null ? 0 : response.getResult().getExploreWay().size(),
response.getResult().getOnlineCar() == null ? 0 : response.getResult().getOnlineCar().size() );
if ( size == 0 ) {
return false;
}
if ( target != type ) {
mRefreshStrategy.next();// 本次请求到的数据类型和播报类型不一致,则下次再次请求本次类型~
}
speakTTS( tts = String.format( tts, size, target.desc ), true );
notifyRefreshChanged( String.format( info, size, target.desc ), size, tts );
return true;
}
private void speakTTS( String msg, boolean checkAppForeground ) {
if ( TextUtils.isEmpty( msg ) ) {
return;
}
if ( checkAppForeground ) {
if ( AppUtils.isAppForeground( mContext ) ) {
return;
@@ -427,6 +326,14 @@ class LauncherCardRefresher {
* 请求广告数据
*/
private void loadNetworkConfigStrategy() {
loadAdvertisementConfig();
requestTtsStrategyConfig();
}
/**
* 请求广告数据
*/
private void loadAdvertisementConfig() {
final Map< String, Object > query = new ParamsProvider.Builder( mContext )
.append( "modelType", 30 )
.build();
@@ -460,9 +367,238 @@ class LauncherCardRefresher {
Logger.e( TAG, "获取配置失败 msg = %s, code = %s", message, code );
}
} );
}
/**
* 请求花式的tts播报内容
*/
private void requestTtsStrategyConfig() {
String name = SharedPrefsMgr.getInstance( mContext ).getString( KEY_LAST_LOAD_TTS_TYPE, LauncherCardRefreshType.Weather.name() );
LauncherCardRefreshType type = LauncherCardRefreshType.valueOf( name );
MogoLocation location = MogoApisHandler.getInstance().getApis().getMapServiceApi().getSingletonLocationClient( mContext ).getLastKnowLocation();
TtsConfigBody body = new TtsConfigBody()
.addType( LauncherCardRefreshType.NearRoads.getVal() )
.addType( LauncherCardRefreshType.News.getVal() )
.addType( LauncherCardRefreshType.ExplorerWay.getVal() )
.addType( LauncherCardRefreshType.Weather.getVal() )
.sn( Utils.getSn() )
.location( new MogoLatLng( location.getLatitude(), location.getLongitude() ) );
final Map< String, Object > query = new ParamsProvider.Builder( mContext )
.append( "data", GsonUtil.jsonFromObject( body ) )
.build();
mRefreshModel.getRefreshApiService().queryBroadCastInfo( query )
.subscribeOn( Schedulers.io() )
.observeOn( AndroidSchedulers.mainThread() )
.subscribe( new SubscribeImpl< TtsConfigData >( RequestOptions.create( mContext ) ) {
@Override
public void onError( Throwable e ) {
super.onError( e );
}
@Override
public void onSuccess( TtsConfigData data ) {
super.onSuccess( data );
if ( data == null || data.result == null ) {
Logger.d( TAG, "获取数据为空" );
return;
}
handleTtsConfig( data, type );
}
@Override
public void onError( String message, int code ) {
super.onError( message, code );
if ( code == 100046 ) {
refreshTicket();
}
Logger.e( TAG, "获取配置失败 msg = %s, code = %s", message, code );
}
} );
}
/**
* 策略:
* 优先车辆限行
* 剩下的按顺序播报
*
* @param data
*/
private void handleTtsConfig( TtsConfigData data, LauncherCardRefreshType type ) {
List< TtsConfigData.TrafficRestriction > trafficRestrictions = data.result.trafficRestriction;
if ( trafficRestrictions != null && !trafficRestrictions.isEmpty() ) {
for ( TtsConfigData.TrafficRestriction trafficRestriction : trafficRestrictions ) {
if ( trafficRestriction == null || TextUtils.isEmpty( trafficRestriction.tts ) ) {
continue;
}
speakTTS( trafficRestriction.tts, false );
return;
}
}
TtsConfigNode weather = new TtsConfigNode( data.result.weather, LauncherCardRefreshType.Weather );
TtsConfigNode news = new TtsConfigNode( data.result.news, LauncherCardRefreshType.News );
TtsConfigNode nearRoads = new TtsConfigNode( data.result.nearRoads, LauncherCardRefreshType.NearRoads );
TtsConfigNode explorerWay = new TtsConfigNode( data.result.friendAndPois, LauncherCardRefreshType.ExplorerWay );
TtsConfigNode onlineCar = new TtsConfigNode( data.result.friendAndPois, LauncherCardRefreshType.OnlineCar );
weather.next = news;
news.next = nearRoads;
nearRoads.next = explorerWay;
explorerWay.next = onlineCar;
onlineCar.next = weather;
TtsConfigNode header = null;
switch ( type ) {
case News:
header = news;
break;
case NearRoads:
header = nearRoads;
break;
case OnlineCar:
header = onlineCar;
break;
case Weather:
header = weather;
break;
case ExplorerWay:
header = explorerWay;
break;
}
TtsConfigNode pointer = header;
do {
if ( handleTtsNode( pointer ) ) {
writeNextLoadType( pointer.type );
return;
}
pointer = pointer.next;
} while ( pointer != header );
}
/**
* 处理每个配置项
*
* @param node
* @return
*/
private boolean handleTtsNode( TtsConfigNode node ) {
if ( node.data == null || node.data.isEmpty() ) {
return false;
}
for ( Object datum : node.data ) {
boolean result = false;
if ( datum instanceof TtsConfigData.Weather ) {
result = handleWeatherTtsConfig( ( ( TtsConfigData.Weather ) datum ) );
} else if ( datum instanceof TtsConfigData.News ) {
result = handleNewsTtsConfig( ( ( TtsConfigData.News ) datum ) );
} else if ( datum instanceof TtsConfigData.NearRoads ) {
result = handleNearRoadsTtsConfig( ( ( TtsConfigData.NearRoads ) datum ) );
} else if ( datum instanceof TtsConfigData.OnlineCarVsExplorerWay ) {
result = handleExplorerWayTtsConfig( ( ( TtsConfigData.OnlineCarVsExplorerWay ) datum ) );
if ( !result ) {
result = handleOnlineCarTtsConfig( ( ( TtsConfigData.OnlineCarVsExplorerWay ) datum ) );
}
}
if ( result ) {
return true;
}
}
return false;
}
/**
* 天气
*
* @param weather
* @return
*/
private boolean handleWeatherTtsConfig( TtsConfigData.Weather weather ) {
if ( weather == null ) {
return false;
}
speakTTS( weather.tts, false );
return true;
}
/**
* 新闻
*
* @param news
* @return
*/
private boolean handleNewsTtsConfig( TtsConfigData.News news ) {
if ( news == null ) {
return false;
}
speakTTS( news.tts, false );
return true;
}
/**
* 常走道路
*
* @param nearRoads
* @return
*/
private boolean handleNearRoadsTtsConfig( TtsConfigData.NearRoads nearRoads ) {
if ( nearRoads == null ) {
return false;
}
speakTTS( nearRoads.tts, false );
return true;
}
/**
* 道路事件
*
* @param explorerWay
* @return
*/
private boolean handleExplorerWayTtsConfig( TtsConfigData.OnlineCarVsExplorerWay explorerWay ) {
if ( explorerWay == null || explorerWay.pois == 0 ) {
return false;
}
String tts = mContext.getString( R.string.module_service_launcher_card_tips );
String info = mContext.getString( R.string.module_service_launcher_card_info );
speakTTS( String.format( tts, explorerWay.pois, LauncherCardRefreshType.ExplorerWay.getDesc() ), false );
notifyRefreshChanged( String.format( info, explorerWay.pois, LauncherCardRefreshType.ExplorerWay ), explorerWay.pois, tts );
return true;
}
/**
* 车友
*
* @param onlineCar
* @return
*/
private boolean handleOnlineCarTtsConfig( TtsConfigData.OnlineCarVsExplorerWay onlineCar ) {
if ( onlineCar == null || onlineCar.friends == 0 ) {
return false;
}
String tts = mContext.getString( R.string.module_service_launcher_card_tips );
String info = mContext.getString( R.string.module_service_launcher_card_info );
speakTTS( String.format( tts, onlineCar.friends, LauncherCardRefreshType.OnlineCar.getDesc() ), false );
notifyRefreshChanged( String.format( info, onlineCar.friends, LauncherCardRefreshType.OnlineCar ), onlineCar.friends, tts );
return true;
}
/**
* 保存下次需要首先播报的内容类型
*
* @param type
*/
private void writeNextLoadType( LauncherCardRefreshType type ) {
SharedPrefsMgr.getInstance( mContext ).putString( KEY_LAST_LOAD_TTS_TYPE, type.getNext() );
Logger.d( TAG, "本次播报:%s下次播报%s", type.getVal(), LauncherCardRefreshType.valueOf( type.getNext() ).getVal() );
}
private void refreshTicket() {
mRefreshTicketCounter++;
Logger.d( TAG, "刷新ticket" );

View File

@@ -0,0 +1,22 @@
package com.mogo.module.service.launchercard;
import java.util.List;
public
/**
* @author congtaowang
* @since 2020/11/17
* <p>
* 描述
*/
class TtsConfigNode {
public List data;
public LauncherCardRefreshType type;
public TtsConfigNode next;
public TtsConfigNode( List data, LauncherCardRefreshType type ) {
this.data = data;
this.type = type;
}
}

View File

@@ -4,6 +4,7 @@ import com.mogo.commons.data.BaseData;
import com.mogo.module.common.entity.MarkerResponse;
import com.mogo.module.service.network.bean.DemoUserInfoEntity;
import com.mogo.module.service.network.bean.HomeCompanyDistanceForPushResponse;
import com.mogo.module.service.network.bean.TtsConfigData;
import java.util.Map;
@@ -40,6 +41,10 @@ public interface RefreshApiService {
Observable< DemoUserInfoEntity > getMockUsers();
@FormUrlEncoded
@POST("/yycp-travel-condition/trajectoryPrediction/calculationNotHomeCompanyDistanceForPush")
Observable< HomeCompanyDistanceForPushResponse > calculationNotHomeCompanyDistanceForPush( @FieldMap Map< String, Object > parameters);
@POST( "/yycp-travel-condition/trajectoryPrediction/calculationNotHomeCompanyDistanceForPush" )
Observable< HomeCompanyDistanceForPushResponse > calculationNotHomeCompanyDistanceForPush( @FieldMap Map< String, Object > parameters );
@FormUrlEncoded
@POST( "/yycp-launcherSnapshot/appCard/queryBroadCastInfo" )
Observable< TtsConfigData > queryBroadCastInfo( @FieldMap Map< String, Object > parameters );
}

View File

@@ -0,0 +1,75 @@
package com.mogo.module.service.network.bean;
import android.os.Parcel;
import android.os.Parcelable;
import com.mogo.map.MogoLatLng;
import java.util.ArrayList;
import java.util.List;
public
/**
* @author congtaowang
* @since 2020/11/17
*
* 请求参数
*/
class TtsConfigBody implements Parcelable {
private MogoLatLng location;
private List< String > dataType;
private String sn;
public TtsConfigBody addType( String type ) {
if ( dataType == null ) {
dataType = new ArrayList<>();
}
dataType.add( type );
return this;
}
public TtsConfigBody sn( String sn ) {
this.sn = sn;
return this;
}
public TtsConfigBody location( MogoLatLng location ) {
this.location = location;
return this;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel( Parcel dest, int flags ) {
dest.writeParcelable( this.location, flags );
dest.writeStringList( this.dataType );
dest.writeString( this.sn );
}
public TtsConfigBody() {
}
protected TtsConfigBody( Parcel in ) {
this.location = in.readParcelable( MogoLatLng.class.getClassLoader() );
this.dataType = in.createStringArrayList();
this.sn = in.readString();
}
public static final Creator< TtsConfigBody > CREATOR = new Creator< TtsConfigBody >() {
@Override
public TtsConfigBody createFromParcel( Parcel source ) {
return new TtsConfigBody( source );
}
@Override
public TtsConfigBody[] newArray( int size ) {
return new TtsConfigBody[size];
}
};
}

View File

@@ -0,0 +1,89 @@
package com.mogo.module.service.network.bean;
import com.google.gson.annotations.SerializedName;
import com.mogo.commons.data.BaseData;
import java.util.List;
public
/**
* @author congtaowang
* @since 2020/11/17
*
* 描述
*/
class TtsConfigData extends BaseData {
public Result result;
public static class Result {
public String sn;
public List< String > dataType;
public List< Weather > weather;
public List< News > news;
public List< NearRoads > nearRoads;
public List< TrafficRestriction > trafficRestriction;
public List< OnlineCarVsExplorerWay > friendAndPois;
}
public static class BaseConfig {
public String tts;
}
public static class Weather extends BaseConfig {
public String time;
public String date;
public String ymd;
public String week;
public String sunrise;
public String high;
public String low;
public String sunset;
public int aqi;
public String fx;
public String fl;
public String type;
public String notice;
}
public static class News extends BaseConfig {
public String title;
public String content;
@SerializedName( "img_width" )
public String imgWidth;
@SerializedName( "full_title" )
public String fullTitle;
@SerializedName( "pdate" )
public String time;
public String src;
@SerializedName( "img_length" )
public String imgLength;
public String img;
public String url;
@SerializedName( "pdate_src" )
public String date;
}
public static class NearRoads extends BaseConfig {
}
public static class TrafficRestriction extends BaseConfig {
}
public static class OnlineCarVsExplorerWay extends BaseConfig {
/**
* 车友数量
*/
public int friends;
/**
* 道路事件数量
*/
public int pois;
}
}

View File

@@ -0,0 +1,20 @@
package com.mogo.module.service.network.bean;
import com.mogo.commons.data.BaseData;
/**
* @author zhuangyan
* @date : 2020/11/17 11:43
* @desc :分体机tts播报信息返回
*/
public class TtsConfigEntity extends BaseData {
private String ttsWord;
public String getTtsWord() {
return ttsWord;
}
public void setTtsWord(String ttsWord) {
this.ttsWord = ttsWord;
}
}

View File

@@ -9,12 +9,15 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.request.RequestOptions;
import com.mogo.map.location.MogoLocation;
import com.mogo.module.carchattingprovider.ICarsChattingProvider;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.api.CallChatApi;
import com.mogo.module.common.entity.MarkerLocation;
import com.mogo.module.common.entity.MarkerOnlineCar;
import com.mogo.module.common.entity.MarkerUserInfo;
import com.mogo.module.common.glide.SkinAbleBitmapTarget;
import com.mogo.module.service.MarkerServiceHandler;
import com.mogo.module.service.R;
@@ -23,8 +26,11 @@ import com.mogo.utils.ResourcesHelper;
import com.mogo.utils.WindowUtils;
import com.mogo.utils.glide.GlideApp;
import com.mogo.utils.logger.Logger;
import com.zhidao.carchattingprovider.CallChattingProviderConstant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author congtaowang
@@ -32,34 +38,50 @@ import java.util.List;
* <p>
* 描述
*/
class OnlineCarPanelAdapter extends RecyclerView.Adapter< OnlineCarPanelAdapter.VH > {
class OnlineCarPanelAdapter extends RecyclerView.Adapter<OnlineCarPanelAdapter.VH> {
private static final String TAG = "OnlineCarPanelAdapter";
private List< MarkerOnlineCar > mDatums;
private List<MarkerOnlineCar> mDatums;
private double mToLon;
private double mToLat;
public OnlineCarPanelAdapter( List< MarkerOnlineCar > mDatums, double mToLon, double mToLat ) {
public OnlineCarPanelAdapter(List<MarkerOnlineCar> mDatums, double mToLon, double mToLat) {
this.mDatums = mDatums;
this.mToLon = mToLon;
this.mToLat = mToLat;
}
public void setDatums( List< MarkerOnlineCar > mDatums ) {
public void setDatums(List<MarkerOnlineCar> mDatums) {
this.mDatums = mDatums;
notifyDataSetChanged();
}
@NonNull
@Override
public OnlineCarPanelAdapter.VH onCreateViewHolder( @NonNull ViewGroup parent, int viewType ) {
return new VH( LayoutInflater.from( parent.getContext() ).inflate( R.layout.module_services_online_car_panel_item, null ) );
public OnlineCarPanelAdapter.VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new VH(LayoutInflater.from(parent.getContext()).inflate(R.layout.module_services_online_car_panel_item, null));
}
@Override
public void onBindViewHolder( @NonNull OnlineCarPanelAdapter.VH holder, int position ) {
holder.bind( mDatums.get( position ), mToLon, mToLat );
public void onBindViewHolder(@NonNull OnlineCarPanelAdapter.VH holder, int position) {
holder.bind(mDatums.get(position), mToLon, mToLat);
holder.call.setOnClickListener(view -> {
//TODO 拨打电话
Map<String, String> params = new HashMap<>();
MarkerUserInfo userInfo = mDatums.get(position).getUserInfo();
params.put(CallChattingProviderConstant.CCPROVIDER_SN, userInfo.getSn());
params.put(CallChattingProviderConstant.CCPROVIDER_USER_IMG, userInfo.getUserHead());
params.put(CallChattingProviderConstant.CCPROVIDER_USER_AGE, userInfo.getAgeNumber() + "");
params.put(CallChattingProviderConstant.CCPROVIDER_NICK_NAME, userInfo.getUserName());
params.put(CallChattingProviderConstant.CCPROVIDER_USER_SEX, userInfo.getGender() + "");
MarkerLocation location = mDatums.get(position).getLocation();
params.put(CallChattingProviderConstant.CCPROVIDER_ADDRESS, location.getAddress());
params.put(CallChattingProviderConstant.CCPROVIDER_LAT, location.getLat() + "");
params.put(CallChattingProviderConstant.CCPROVIDER_LON, location.getLon() + "");
ICarsChattingProvider carChatting = MarkerServiceHandler.getCarChatting();
carChatting.call(params);
});
}
@Override
@@ -73,43 +95,50 @@ class OnlineCarPanelAdapter extends RecyclerView.Adapter< OnlineCarPanelAdapter.
private TextView nickname;
private TextView distance;
private TextView detail;
private TextView call;
public VH( @NonNull View itemView ) {
super( itemView );
RecyclerView.LayoutParams params = new RecyclerView.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT );
params.bottomMargin = ResourcesHelper.getDimensionPixelSize( itemView.getContext(), R.dimen.module_services_panel_item_marginBottom );
itemView.setLayoutParams( params );
avatar = itemView.findViewById( R.id.module_services_id_panel_item_avatar );
nickname = itemView.findViewById( R.id.module_services_id_panel_item_nickname );
distance = itemView.findViewById( R.id.module_services_id_panel_item_distance );
detail = itemView.findViewById( R.id.module_services_id_panel_item_detail );
public VH(@NonNull View itemView) {
super(itemView);
RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.bottomMargin = ResourcesHelper.getDimensionPixelSize(itemView.getContext(), R.dimen.module_services_panel_item_marginBottom);
itemView.setLayoutParams(params);
avatar = itemView.findViewById(R.id.module_services_id_panel_item_avatar);
nickname = itemView.findViewById(R.id.module_services_id_panel_item_nickname);
distance = itemView.findViewById(R.id.module_services_id_panel_item_distance);
detail = itemView.findViewById(R.id.module_services_id_panel_item_detail);
call = itemView.findViewById(R.id.module_services_id_panel_item_call);
}
public void bind( MarkerOnlineCar car, double lon, double lat ) {
RequestOptions options = new RequestOptions().circleCrop().placeholder( R.drawable.module_common_default_user_head ).error( R.drawable.module_common_default_user_head );
GlideApp.with( itemView.getContext() ).asBitmap().apply( options ).load( car.getUserInfo().getUserHead() ).into( new SkinAbleBitmapTarget( avatar, options ) );
nickname.setText( car.getUserInfo().getUserName() );
String content = getDistanceStr( car.getLocation(), lon, lat );
distance.setText( content );
detail.setOnClickListener( view -> {
MogoApisHandler.getInstance().getApis().getAnalyticsApi().track( "Mogoer_List_click", null );
public void bind(MarkerOnlineCar car, double lon, double lat) {
RequestOptions options = new RequestOptions().circleCrop().placeholder(R.drawable.module_common_default_user_head).error(R.drawable.module_common_default_user_head);
GlideApp.with(itemView.getContext()).asBitmap().apply(options).load(car.getUserInfo().getUserHead()).into(new SkinAbleBitmapTarget(avatar, options));
nickname.setText(car.getUserInfo().getUserName());
String content = getDistanceStr(car.getLocation(), lon, lat);
distance.setText(content);
detail.setOnClickListener(view -> {
MogoApisHandler.getInstance().getApis().getAnalyticsApi().track("Mogoer_List_click", null);
try {
CallChatApi.getInstance().showUserWindow( itemView.getContext(), car );
} catch ( Exception e ) {
Logger.e( TAG, e, "detail.OnClick" );
CallChatApi.getInstance().showUserWindow(itemView.getContext(), car);
} catch (Exception e) {
Logger.e(TAG, e, "detail.OnClick");
}
} );
});
// call.setOnClickListener(view -> {
// //TODO 拨打电话
//
//
// });
}
private String getDistanceStr( MarkerLocation location, double lon, double lat ) {
if ( location == null ) {
private String getDistanceStr(MarkerLocation location, double lon, double lat) {
if (location == null) {
return "未知";
}
float distance = Utils.calculateLineDistance( location.getLon(), location.getLat(), lon, lat );
if ( distance >= 1000 ) {
return String.format( "%.1f千米", distance / 1000 );
float distance = Utils.calculateLineDistance(location.getLon(), location.getLat(), lon, lat);
if (distance >= 1000) {
return String.format("%.1f千米", distance / 1000);
} else {
return String.format( "%.1f米", distance );
return String.format("%.1f米", distance);
}
}
}

View File

@@ -0,0 +1,26 @@
package com.mogo.module.service.ttsConfig;
import com.mogo.commons.data.BaseData;
import com.mogo.module.service.network.bean.TtsConfigEntity;
import java.util.Map;
import io.reactivex.Observable;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
/**
* @author zhuangyan
* @date : 2020/11/16 15:09
* @desc :
*/
public interface TtsConfigApiService {
/**
* 查询语音Tts 的
*
*/
@FormUrlEncoded
@POST("/yycp-tmcServer/tmcServer/car/reportTraffic/v1")
Observable<TtsConfigEntity> inquireForTts(@FieldMap Map<String, Object> parames);
}

View File

@@ -0,0 +1,72 @@
package com.mogo.module.service.ttsConfig;
import android.util.Log;
import com.alibaba.android.arouter.launcher.ARouter;
import com.mogo.commons.data.BaseData;
import com.mogo.commons.network.ParamsProvider;
import com.mogo.commons.network.SubscribeImpl;
import com.mogo.commons.network.Utils;
import com.mogo.module.service.network.RefreshCallback;
import com.mogo.module.service.network.RefreshModel;
import com.mogo.module.service.network.bean.TtsConfigEntity;
import com.mogo.service.MogoServicePaths;
import com.mogo.service.network.IMogoNetwork;
import com.mogo.utils.logger.Logger;
import com.mogo.utils.network.RequestOptions;
import java.util.Map;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import static com.mogo.commons.AbsMogoApplication.getApp;
/**
* @author zhuangyan
* @date : 2020/11/16 15:04
* @desc :
*/
public class TtsConfigModleData {
private static final String TAG = "TrafficModelData";
private final TtsConfigApiService mTtsConfigApiService;
public TtsConfigModleData() {
IMogoNetwork network = (IMogoNetwork) ARouter.getInstance().build(MogoServicePaths.PATH_SERVICES_NETWORK).navigation(getApp().getApplicationContext());
mTtsConfigApiService = network.create(TtsConfigApiService.class, RefreshModel.getNetHost());
}
/**
* 独立app根据后台配置 播放tts
* @param
* @param
* @param
*/
public void playTts(RefreshCallback<TtsConfigEntity> ttsCallback) {
final ParamsProvider.Builder builder = new ParamsProvider.Builder( getApp().getApplicationContext());
Map<String, Object> parameters = builder.build();
parameters.put("sn", Utils.getSn());
Log.d("zytest","playTts获取语音配置的网络请求");
// parameters.put("data", GsonUtil.jsonFromObject(uploadTrafficEntity));
mTtsConfigApiService.inquireForTts(parameters)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<TtsConfigEntity>(RequestOptions.create( getApp().getApplicationContext())) {
@Override
public void onError(Throwable e) {
super.onError(e);
ttsCallback.onFail();
}
@Override
public void onSuccess(TtsConfigEntity o) {
super.onSuccess(o);
ttsCallback.onSuccess(o);
}
});
}
}

View File

@@ -0,0 +1,39 @@
package com.mogo.module.service.ttsConfig;
import android.content.Context;
import android.util.Log;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.facade.template.IProvider;
import com.mogo.module.service.ServiceConst;
import com.mogo.module.service.network.RefreshCallback;
import com.mogo.module.service.network.bean.TtsConfigEntity;
/**
* @author zhuangyan
* @date : 2020/11/16 15:01
* @desc :进入页面的时候 根据配置 播放tts语音
*/
@Route( path = ServiceConst.PATH_TTS_CONFIG )
public class TtsConfigProvider implements IProvider {
private final String TAG = "TtsConfigProvider";
private TtsConfigModleData mTtsModleData;
@Override
public void init(Context context) {
Log.d(TAG, "TtsConfigProvider provider init……");
if (mTtsModleData==null) {
mTtsModleData=new TtsConfigModleData();
}
mTtsModleData.playTts(new RefreshCallback<TtsConfigEntity>() {
@Override
public void onSuccess(TtsConfigEntity o) {
}
@Override
public void onFail() {
}
});
}
}

View File

@@ -37,6 +37,14 @@ public class GlobalUnwakeConst {
*/
public static final String UNWAKE_UPLOAD_REAL_TIME_TRAFFIC = "command_upload_real_time_traffic";
/**
* 唤醒词查询出行动态
*/
public static final String VOICE_QUERY_HISTORY_INDEX = "com.zhidao.query.trip.event";
/**
* 唤醒词查询周边事件
*/
public static final String VOICE_QUERY_SURROUNDING_INDEX = "com.zhidao.query.nearby.event";
/**
* 唤醒词查询热心指数
*/

View File

@@ -23,6 +23,8 @@ import static com.mogo.module.service.unwake.GlobalUnwakeConst.VOICE_CMD_PUB_ROA
import static com.mogo.module.service.unwake.GlobalUnwakeConst.VOICE_CMD_PUB_TROUBLE_HELP;
import static com.mogo.module.service.unwake.GlobalUnwakeConst.VOICE_CMD_SHARE_DIALOG_CLOSE;
import static com.mogo.module.service.unwake.GlobalUnwakeConst.VOICE_QUERY_HEART_INDEX;
import static com.mogo.module.service.unwake.GlobalUnwakeConst.VOICE_QUERY_HISTORY_INDEX;
import static com.mogo.module.service.unwake.GlobalUnwakeConst.VOICE_QUERY_SURROUNDING_INDEX;
/**
* 全局免唤醒管理
@@ -48,6 +50,8 @@ public class GlobalUnwakeManager implements IProvider, IMogoIntentListener, IMog
intentManager.registerIntentListener(VOICE_CMD_NO_REPLY_SHARE_DIALOG_CLOSE, this);
intentManager.registerIntentListener(UNWAKE_UPLOAD_ROAD_CONDITION, this);
intentManager.registerIntentListener(VOICE_QUERY_HEART_INDEX, this);
intentManager.registerIntentListener(VOICE_QUERY_HISTORY_INDEX, this);
intentManager.registerIntentListener(VOICE_QUERY_SURROUNDING_INDEX, this);
// 免唤醒词注册,全局免唤醒
AIAssist.getInstance(context).registerUnWakeupCommand(UNWAKE_UPLOAD_REAL_TIME_TRAFFIC,