智慧出行固定引流 TTS 改为引导播报
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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" );
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user