1. 1.1.3需求策略修改。
This commit is contained in:
@@ -3,13 +3,20 @@ package com.mogo.module.service.launchercard;
|
||||
public class LauncherCardRefreshStrategy {
|
||||
|
||||
private long interval; // 间隔时间
|
||||
private LauncherCardRefreshType type = LauncherCardRefreshType.OnlineCar;
|
||||
private static LauncherCardRefreshType type = LauncherCardRefreshType.OnlineCar;
|
||||
|
||||
private LauncherCardRefreshStrategy next;
|
||||
|
||||
public LauncherCardRefreshStrategy( long interval, LauncherCardRefreshStrategy next ) {
|
||||
private int msgType;// 触发的消息类型
|
||||
|
||||
public LauncherCardRefreshStrategy( long interval, LauncherCardRefreshStrategy next, int msgType ) {
|
||||
this.interval = interval;
|
||||
this.next = next;
|
||||
this.msgType = msgType;
|
||||
}
|
||||
|
||||
public int getMsgType() {
|
||||
return msgType;
|
||||
}
|
||||
|
||||
public long getInterval() {
|
||||
|
||||
@@ -38,7 +38,9 @@ class LauncherCardRefresher {
|
||||
private static volatile LauncherCardRefresher sInstance;
|
||||
|
||||
public static final int MSG_REFRESH = 2020;
|
||||
public static final int MSG_TTS_TIP = 2021;
|
||||
public static final long ONE_MINUTE = 60 * 1000L;
|
||||
public static final long HALF_ONE_MINUTE = 30 * 1000L;
|
||||
|
||||
private LauncherCardRefresher( Context context ) {
|
||||
mContext = context;
|
||||
@@ -71,10 +73,19 @@ class LauncherCardRefresher {
|
||||
if ( mRefreshStop ) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
handleRefreshMsg();
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error when refresh launcher card." );
|
||||
switch ( msg.what ) {
|
||||
case MSG_REFRESH:
|
||||
try {
|
||||
handleRefreshMsg();
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error when refresh launcher card." );
|
||||
}
|
||||
break;
|
||||
case MSG_TTS_TIP:
|
||||
playTTS();
|
||||
mRefreshStrategy = mRefreshStrategy.getNext();
|
||||
restart();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -84,8 +95,15 @@ class LauncherCardRefresher {
|
||||
private boolean mStart = false;
|
||||
private RefreshModel mRefreshModel;
|
||||
private LauncherCardRefreshStrategy mRefreshStrategy = new LauncherCardRefreshStrategy(
|
||||
1 * ONE_MINUTE,
|
||||
new LauncherCardRefreshStrategy( 1 * ONE_MINUTE, null )
|
||||
2 * ONE_MINUTE,
|
||||
new LauncherCardRefreshStrategy(
|
||||
3 * ONE_MINUTE,
|
||||
new LauncherCardRefreshStrategy(
|
||||
20 * ONE_MINUTE,
|
||||
null,
|
||||
MSG_REFRESH ),
|
||||
MSG_REFRESH ),
|
||||
MSG_TTS_TIP
|
||||
);
|
||||
|
||||
public void start() {
|
||||
@@ -108,7 +126,7 @@ class LauncherCardRefresher {
|
||||
SharedPrefsMgr.getInstance( mContext ).putLong( KEY_LauncherCardTipLastTipTime, 0L );
|
||||
}
|
||||
}
|
||||
mHandler.sendEmptyMessageDelayed( MSG_REFRESH, mRefreshStrategy.getInterval() );
|
||||
mHandler.sendEmptyMessageDelayed( mRefreshStrategy.getMsgType(), mRefreshStrategy.getInterval() );
|
||||
Logger.d( TAG, "start" );
|
||||
mRefreshStop = false;
|
||||
mStart = true;
|
||||
@@ -121,6 +139,7 @@ class LauncherCardRefresher {
|
||||
mRefreshStop = true;
|
||||
mStart = false;
|
||||
mHandler.removeMessages( MSG_REFRESH );
|
||||
mHandler.removeMessages( MSG_TTS_TIP );
|
||||
Logger.d( TAG, "stop" );
|
||||
}
|
||||
|
||||
@@ -130,7 +149,8 @@ class LauncherCardRefresher {
|
||||
}
|
||||
mRefreshStop = false;
|
||||
mHandler.removeMessages( MSG_REFRESH );
|
||||
mHandler.sendEmptyMessageDelayed( MSG_REFRESH, mRefreshStrategy.getInterval() );
|
||||
mHandler.removeMessages( MSG_TTS_TIP );
|
||||
mHandler.sendEmptyMessageDelayed( mRefreshStrategy.getMsgType(), mRefreshStrategy.getInterval() );
|
||||
}
|
||||
|
||||
private void handleRefreshMsg() {
|
||||
@@ -142,66 +162,77 @@ class LauncherCardRefresher {
|
||||
restart();
|
||||
return;
|
||||
}
|
||||
MogoLatLng latLng = new MogoLatLng( location.getLatitude(), location.getLongitude() );
|
||||
if ( mRefreshStrategy.getType() == LauncherCardRefreshType.ExploreWay ) {
|
||||
mRefreshModel.refreshDataSync( new MogoLatLng( location.getLatitude(), location.getLongitude() ),
|
||||
mRefreshStrategy.getRadius(),
|
||||
mRefreshStrategy.getLimit(),
|
||||
new RefreshCallback< MarkerResponse >() {
|
||||
@Override
|
||||
public void onSuccess( MarkerResponse response ) {
|
||||
notifyLauncherCard( LauncherCardRefreshType.ExploreWay, response );
|
||||
mRefreshStrategy = mRefreshStrategy.getNext();
|
||||
restart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail() {
|
||||
mRefreshStrategy = mRefreshStrategy.getNext();
|
||||
restart();
|
||||
}
|
||||
} );
|
||||
handleRefreshExplorerWayData( latLng );
|
||||
} else {
|
||||
mRefreshModel.queryOnLineCarWithRoute( new MogoLatLng( location.getLatitude(), location.getLongitude() ),
|
||||
false,
|
||||
true,
|
||||
mRefreshStrategy.getRadius(),
|
||||
mRefreshStrategy.getLimit(),
|
||||
new RefreshCallback< MarkerResponse >() {
|
||||
@Override
|
||||
public void onSuccess( MarkerResponse response ) {
|
||||
notifyLauncherCard( LauncherCardRefreshType.OnlineCar, response );
|
||||
mRefreshStrategy = mRefreshStrategy.getNext();
|
||||
restart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail() {
|
||||
mRefreshStrategy = mRefreshStrategy.getNext();
|
||||
restart();
|
||||
}
|
||||
} );
|
||||
handleRefreshOnlineCarData( latLng );
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyLauncherCard( LauncherCardRefreshType type, MarkerResponse response ) {
|
||||
private void handleRefreshExplorerWayData( MogoLatLng latLng ) {
|
||||
mRefreshModel.refreshDataSync( latLng,
|
||||
mRefreshStrategy.getRadius(),
|
||||
mRefreshStrategy.getLimit(),
|
||||
new RefreshCallback< MarkerResponse >() {
|
||||
@Override
|
||||
public void onSuccess( MarkerResponse response ) {
|
||||
notifyLauncherCard( LauncherCardRefreshType.ExploreWay, response );
|
||||
mRefreshStrategy = mRefreshStrategy.getNext();
|
||||
restart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail() {
|
||||
mRefreshStrategy = mRefreshStrategy.getNext();
|
||||
restart();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
private void handleRefreshOnlineCarData( MogoLatLng latLng ) {
|
||||
mRefreshModel.queryOnLineCarWithRoute( latLng,
|
||||
false,
|
||||
true,
|
||||
mRefreshStrategy.getRadius(),
|
||||
mRefreshStrategy.getLimit(),
|
||||
new RefreshCallback< MarkerResponse >() {
|
||||
@Override
|
||||
public void onSuccess( MarkerResponse response ) {
|
||||
notifyLauncherCard( LauncherCardRefreshType.OnlineCar, response );
|
||||
mRefreshStrategy = mRefreshStrategy.getNext();
|
||||
restart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail() {
|
||||
mRefreshStrategy = mRefreshStrategy.getNext();
|
||||
restart();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
private boolean notifyLauncherCard( LauncherCardRefreshType type, MarkerResponse response ) {
|
||||
if ( response == null || response.getResult() == null ) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
String tts = mContext.getString( R.string.module_service_launcher_card_tips );
|
||||
String info = mContext.getString( R.string.module_service_launcher_card_info );
|
||||
if ( type == LauncherCardRefreshType.ExploreWay ) {
|
||||
if ( response.getResult().getExploreWay() == null || response.getResult().getExploreWay().isEmpty() ) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
speakTTS( String.format( tts, response.getResult().getExploreWay().size(), mRefreshStrategy.getDesc() ) );
|
||||
notifyLauncherCard( String.format( info, response.getResult().getExploreWay().size(), mRefreshStrategy.getDesc() ) );
|
||||
} else {
|
||||
if ( response.getResult().getOnlineCar() == null || response.getResult().getOnlineCar().isEmpty() ) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
speakTTS( String.format( tts, response.getResult().getOnlineCar().size(), mRefreshStrategy.getDesc() ) );
|
||||
notifyLauncherCard( String.format( info, response.getResult().getOnlineCar().size(), mRefreshStrategy.getDesc() ) );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void speakTTS( String msg ) {
|
||||
@@ -220,4 +251,12 @@ class LauncherCardRefresher {
|
||||
intent.putExtra( "v2x_warning_info", info );
|
||||
mContext.sendBroadcast( intent );
|
||||
}
|
||||
|
||||
private void playTTS() {
|
||||
try {
|
||||
AIAssist.getInstance( mContext ).speakTTSVoice( mContext.getString( R.string.module_service_open_app_tip ) );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user