This commit is contained in:
wangcongtao
2020-08-27 16:47:44 +08:00
parent f7aad35b4b
commit 7078fd3e6b
4 changed files with 47 additions and 49 deletions

View File

@@ -32,6 +32,10 @@ public class LauncherCardRefreshStrategy {
return type;
}
public void next(){
getType();
}
public int getLimit() {
return type.limit;
}

View File

@@ -10,7 +10,6 @@ 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;
@@ -19,7 +18,6 @@ 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.ZhidaoApiService;
import com.mogo.module.service.network.ZhidaoRefreshModel;
import com.mogo.module.service.network.bean.LauncherCardAdvertisementData;
import com.mogo.utils.AppUtils;
@@ -29,12 +27,8 @@ import com.mogo.utils.storage.SharedPrefsMgr;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
@@ -69,6 +63,7 @@ class LauncherCardRefresher {
public static final long ONE_MINUTE = 60 * 1000L;
public static final long ONE_DAY = 24 * 60 * ONE_MINUTE;
private String mLaunchTTSText;
private long mDefaultTTSPlayInterval = 3 * ONE_MINUTE;
private LauncherCardAdvertisementData.LauncherCardAdvertisement mDefaultLauncherCardConfig;
private List< LauncherCardAdvertisementData.LauncherCardAdvertisement > mAdvertisements;
@@ -205,43 +200,17 @@ class LauncherCardRefresher {
return;
}
MogoLatLng latLng = new MogoLatLng( location.getLatitude(), location.getLongitude() );
if ( mRefreshStrategy.getType() == LauncherCardRefreshType.ExploreWay ) {
handleRefreshExplorerWayData( latLng );
} else {
handleRefreshOnlineCarData( latLng );
}
handleRefreshData( latLng, mRefreshStrategy.getType() );
}
private void handleRefreshExplorerWayData( MogoLatLng latLng ) {
private void handleRefreshData( MogoLatLng latLng, LauncherCardRefreshType type ) {
mRefreshModel.refreshDataSync( latLng,
mRefreshStrategy.getRadius(),
mRefreshStrategy.getLimit(),
new RefreshCallback< MarkerResponse >() {
@Override
public void onSuccess( MarkerResponse response ) {
notifyLauncherCardExplorerWayChanged( 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 ) {
notifyLauncherCardExplorerWayChanged( LauncherCardRefreshType.OnlineCar, response );
notifyRefreshChanged( type, response );
mRefreshStrategy = mRefreshStrategy.getNext();
restart();
}
@@ -255,27 +224,43 @@ class LauncherCardRefresher {
}
private boolean notifyLauncherCardExplorerWayChanged( LauncherCardRefreshType type, MarkerResponse response ) {
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() ) {
return false;
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();
}
int size = response.getResult().getExploreWay().size();
speakTTS( tts = String.format( tts, size, mRefreshStrategy.getDesc() ), true );
notifyLauncherCardExplorerWayChanged( String.format( info, size, mRefreshStrategy.getDesc() ), size, tts );
} else {
if ( response.getResult().getOnlineCar() == null || response.getResult().getOnlineCar().isEmpty() ) {
return false;
} 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();
}
int size = response.getResult().getOnlineCar().size();
speakTTS( tts = String.format( tts, size, mRefreshStrategy.getDesc() ), true );
notifyLauncherCardExplorerWayChanged( String.format( info, size, mRefreshStrategy.getDesc() ), size, tts );
}
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;
}
@@ -289,7 +274,7 @@ class LauncherCardRefresher {
AIAssist.getInstance( mContext ).speakTTSVoice( msg );
}
private void notifyLauncherCardExplorerWayChanged( String info, int amount, String tts ) {
private void notifyRefreshChanged( String info, int amount, String tts ) {
Intent intent = new Intent( "com.mogo.launcher.v2x" );
intent.putExtra( "v2x_warning_type", "20000" );
intent.putExtra( "v2x_warining_timeout", 20 * 1000 );
@@ -321,6 +306,9 @@ class LauncherCardRefresher {
if ( !TextUtils.isEmpty( mDefaultLauncherCardConfig.content ) ) {
mLaunchTTSText = mDefaultLauncherCardConfig.content;
}
if ( mDefaultLauncherCardConfig.popupNum > 0 ) {
mDefaultTTSPlayInterval = mDefaultLauncherCardConfig.popupNum * ONE_MINUTE;
}
}
}
@@ -424,7 +412,7 @@ class LauncherCardRefresher {
private void startLoopDefaultConfigStrategy() {
Message msg = Message.obtain();
msg.what = MSG_START_LOOP_DEFAULT_CARD;
mHandler.sendMessageDelayed( msg, 3 * ONE_MINUTE );
mHandler.sendMessageDelayed( msg, mDefaultTTSPlayInterval );
}
/**

View File

@@ -17,6 +17,7 @@ import com.mogo.utils.logger.Logger;
import com.mogo.utils.network.RequestOptions;
import com.mogo.utils.network.utils.GsonUtil;
import java.util.List;
import java.util.Map;
import io.reactivex.android.schedulers.AndroidSchedulers;
@@ -117,6 +118,7 @@ public class RefreshModel {
refreshBody.location = new RefreshBody.LatLon( latLng.lat, latLng.lng );
refreshBody.radius = radius;
refreshBody.dataType.add( ServiceConst.CARD_TYPE_ROAD_CONDITION );
refreshBody.dataType.add( ServiceConst.CARD_TYPE_USER_DATA );
String data = GsonUtil.jsonFromObject( refreshBody );
query.put( "data", data );

View File

@@ -6,6 +6,7 @@ import android.content.Intent;
import com.mogo.module.service.MarkerServiceHandler;
import com.mogo.module.service.intent.IntentHandlerFactory;
import com.mogo.utils.logger.Logger;
public
/**
@@ -15,6 +16,8 @@ public
* 描述
*/
class AccStatusReceiver extends BroadcastReceiver {
private static final String TAG = "AccStatusReceiver";
// 诺威达 acc 状态
public static final String PARAM_ACC_STATUS = "extra_mcu_state";
@@ -24,6 +27,7 @@ class AccStatusReceiver extends BroadcastReceiver {
@Override
public void onReceive( Context context, Intent intent ) {
Logger.d(TAG, "收到诺威达acc广播");
MarkerServiceHandler.init( context );
IntentHandlerFactory.getInstance().handle( context, intent.getAction(), intent );
}