stash
This commit is contained in:
@@ -9,12 +9,12 @@ import com.mogo.map.marker.IMogoMarkerManager;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.module.carchattingprovider.ICarsChattingProvider;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.module.common.entity.MarkerResponse;
|
||||
import com.mogo.module.common.entity.MarkerShowEntity;
|
||||
import com.mogo.module.gps.simulator.IMogoGpsSimulatorManager;
|
||||
import com.mogo.module.service.marker.MapMarkerManager;
|
||||
import com.mogo.service.IMogoServiceApis;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.adas.IMogoADASController;
|
||||
import com.mogo.service.analytics.IMogoAnalytics;
|
||||
import com.mogo.service.cardmanager.IMogoCardManager;
|
||||
@@ -69,7 +69,7 @@ public class MarkerServiceHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
sApis = ( IMogoServiceApis ) ARouter.getInstance().build( MogoServicePaths.PATH_SERVICE_APIS ).navigation( context );
|
||||
sApis = MogoApisHandler.getInstance().getApis();
|
||||
sMapService = sApis.getMapServiceApi();
|
||||
sImageloader = sApis.getImageLoaderApi();
|
||||
sMogoStatusManager = sApis.getStatusManagerApi();
|
||||
|
||||
@@ -15,6 +15,9 @@ import android.view.MotionEvent;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.commons.network.ParamsProvider;
|
||||
import com.mogo.commons.network.SubscribeImpl;
|
||||
import com.mogo.commons.storage.SpStorage;
|
||||
import com.mogo.commons.voice.AIAssist;
|
||||
import com.mogo.commons.voice.IMogoVoiceCmdCallBack;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
@@ -38,6 +41,9 @@ import com.mogo.module.service.launchercard.LauncherCardRefresher;
|
||||
import com.mogo.module.service.marker.MapMarkerManager;
|
||||
import com.mogo.module.service.network.RefreshCallback;
|
||||
import com.mogo.module.service.network.RefreshModel;
|
||||
import com.mogo.module.service.network.bean.HomeCompanyDistanceForPushData;
|
||||
import com.mogo.module.service.network.bean.HomeCompanyDistanceForPushResponse;
|
||||
import com.mogo.module.service.onlinecar.panel.NavigationTargetInfo;
|
||||
import com.mogo.module.service.receiver.MogoReceiver;
|
||||
import com.mogo.module.service.refresh.AutoRefreshStrategy;
|
||||
import com.mogo.module.service.refresh.CustomRefreshStrategy;
|
||||
@@ -60,10 +66,16 @@ import com.mogo.service.statusmanager.StatusDescriptor;
|
||||
import com.mogo.utils.UiThreadHandler;
|
||||
import com.mogo.utils.WorkThreadHandler;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.RequestOptions;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -243,7 +255,7 @@ public class MogoServices implements IMogoMapListener,
|
||||
/**
|
||||
* 自动刷新回调
|
||||
*/
|
||||
private RefreshCallback mAutoRefreshCallback = new RefreshCallback<MarkerResponse>() {
|
||||
private RefreshCallback mAutoRefreshCallback = new RefreshCallback< MarkerResponse >() {
|
||||
@Override
|
||||
public void onSuccess( MarkerResponse o ) {
|
||||
MapMarkerManager.getInstance().onSyncMarkerResponse( o );
|
||||
@@ -390,6 +402,7 @@ public class MogoServices implements IMogoMapListener,
|
||||
mIntentManager.registerIntentListener( MogoReceiver.ACTION_AUTO_NAVI_RECEIVER, this );
|
||||
mIntentManager.registerIntentListener( MogoReceiver.ACTION_AUTO_NAVI_SEND, this );
|
||||
mIntentManager.registerIntentListener( MogoReceiver.ACTION_MOGO, this );
|
||||
mIntentManager.registerIntentListener( ServiceConst.COMMAND_ONLINE_CAR_PANEL, this );
|
||||
|
||||
mADASController = MarkerServiceHandler.getADASController();
|
||||
mLauncher = MarkerServiceHandler.getLauncher();
|
||||
@@ -484,7 +497,7 @@ public class MogoServices implements IMogoMapListener,
|
||||
filter.addAction( MogoReceiver.ACTION_AUTO_NAVI_RECEIVER );
|
||||
filter.addAction( MogoReceiver.ACTION_AUTO_NAVI_SEND );
|
||||
filter.addAction( MogoReceiver.ACTION_MOGO );
|
||||
filter.addAction(MogoReceiver.ACTION_TXZ_BLOCK_SEARCH);
|
||||
filter.addAction( MogoReceiver.ACTION_TXZ_BLOCK_SEARCH );
|
||||
try {
|
||||
context.getApplicationContext().registerReceiver( mAIAssistReceiver, filter );
|
||||
Logger.i( TAG, "register voice receiver." );
|
||||
@@ -842,6 +855,7 @@ public class MogoServices implements IMogoMapListener,
|
||||
@Override
|
||||
public void onIntentReceived( String command, Intent intent ) {
|
||||
|
||||
|
||||
if ( ServiceConst.COMMAND_NEXT.equals( command ) ) {
|
||||
onActionDone( MogoAction.Next );
|
||||
} else if ( ServiceConst.COMMAND_PREVIOUS.equals( command ) ) {
|
||||
@@ -925,4 +939,48 @@ public class MogoServices implements IMogoMapListener,
|
||||
AIAssist.getInstance( mContext ).registerUnWakeupCommand( ServiceConst.CMD_BACK, ServiceConst.CMD_BACK_WORDS, this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartNavi() {
|
||||
String json = SpStorage.getNavigationTarget();
|
||||
if ( !TextUtils.isEmpty( json ) ) {
|
||||
try {
|
||||
NavigationTargetInfo info = GsonUtil.objectFromJson( json, NavigationTargetInfo.class );
|
||||
|
||||
Logger.d( TAG, "info = %s", info );
|
||||
|
||||
HomeCompanyDistanceForPushData data = new HomeCompanyDistanceForPushData();
|
||||
data.lat = Double.valueOf( info.getToPoiLatitude() );
|
||||
data.lon = Double.valueOf( info.getToPoiLongitude() );
|
||||
|
||||
final Map< String, Object > query = new ParamsProvider.Builder( mContext ).build();
|
||||
query.put( "data", GsonUtil.jsonFromObject( data ) );
|
||||
mRefreshModel.getRefreshApiService().calculationNotHomeCompanyDistanceForPush( query )
|
||||
.subscribeOn( Schedulers.io() )
|
||||
.observeOn( AndroidSchedulers.mainThread() )
|
||||
.subscribe( new SubscribeImpl< HomeCompanyDistanceForPushResponse >( RequestOptions.create( mContext ) ) {
|
||||
@Override
|
||||
public void onSuccess( HomeCompanyDistanceForPushResponse o ) {
|
||||
super.onSuccess( o );
|
||||
if ( o != null && o.result != null ) {
|
||||
Logger.d( TAG, "calculationNotHomeCompanyDistanceForPush result %s", o.result.pushFlag );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError( Throwable e ) {
|
||||
super.onError( e );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError( String message, int code ) {
|
||||
super.onError( message, code );
|
||||
}
|
||||
} );
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "onStartNavi" );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,6 @@ public class ServiceConst {
|
||||
public static final int MSG_REQUEST_DATA = 0x201;
|
||||
|
||||
/**
|
||||
*
|
||||
* 锁车消息
|
||||
*/
|
||||
public static final int MSG_LOCK_CAR = 0x202;
|
||||
@@ -159,7 +158,7 @@ public class ServiceConst {
|
||||
};
|
||||
|
||||
public static final String CMD_BACK = "back";
|
||||
public static final String[] CMD_BACK_WORDS = new String[]{"关闭", "返回"};
|
||||
public static final String[] CMD_BACK_WORDS = new String[]{"关闭", "返回"};
|
||||
|
||||
|
||||
/**
|
||||
@@ -203,4 +202,10 @@ public class ServiceConst {
|
||||
|
||||
public static final int ONLINE_SEARCH_LIMIT = 20;
|
||||
public static final int ONLINE_SEARCH_RADIUS = 2_000;
|
||||
|
||||
/**
|
||||
* 查找目的地车友
|
||||
*/
|
||||
public static final String COMMAND_ONLINE_CAR_PANEL = "com.zhidao.search.riders";
|
||||
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ public class IntentHandlerFactory {
|
||||
mHandlers.put( MogoReceiver.ACTION_VOICE_READY, new AIAssistIntentHandler() );
|
||||
mHandlers.put( ServiceConst.COMMAND_BACK, WholeVoiceCommandIntentHandler.getInstance() );
|
||||
mHandlers.put( MogoReceiver.ACTION_MOGO, new MogoControllerIntentHandler() );
|
||||
mHandlers.put( ServiceConst.COMMAND_ONLINE_CAR_PANEL, new OnlineCarPanelIntentHandler() );
|
||||
}
|
||||
|
||||
private static final class InstanceHolder {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.mogo.module.service.intent;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.mogo.module.service.MarkerServiceHandler;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/9/21
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
class OnlineCarPanelIntentHandler implements IntentHandler {
|
||||
|
||||
@Override
|
||||
public void handle( Context context, Intent intent ) {
|
||||
if ( MarkerServiceHandler.getMogoStatusManager().isMainPageOnResume() ) {
|
||||
MarkerServiceHandler.getApis().getOnlineCarPanelApi().showPanel();
|
||||
} else {
|
||||
Intent start = new Intent( Intent.ACTION_VIEW );
|
||||
start.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
|
||||
start.setData( Uri.parse( "mogo://launcher/main/switch2?type=showOnlineCarPanel" ) );
|
||||
context.startActivity( start );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -243,7 +243,7 @@ class LauncherCardRefresher {
|
||||
}
|
||||
|
||||
private void handleRefreshExplorerWayOrOnlineCarData( MogoLatLng latLng, LauncherCardRefreshType type ) {
|
||||
mRefreshModel.refreshDataSync( latLng,
|
||||
mRefreshModel.refreshLauncherCardDataSync( latLng,
|
||||
mRefreshStrategy.getRadius(),
|
||||
mRefreshStrategy.getLimit(),
|
||||
new RefreshCallback< MarkerResponse >() {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mogo.module.service.network;
|
||||
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 java.util.Map;
|
||||
|
||||
@@ -37,4 +38,8 @@ public interface RefreshApiService {
|
||||
*/
|
||||
@GET( "/yycp-launcherSnapshot/mock/getMockUserInfos" )
|
||||
Observable< DemoUserInfoEntity > getMockUsers();
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("/yycp-travel-condition/trajectoryPrediction/calculationNotHomeCompanyDistanceForPush")
|
||||
Observable< HomeCompanyDistanceForPushResponse > calculationNotHomeCompanyDistanceForPush( @FieldMap Map< String, Object > parameters);
|
||||
}
|
||||
|
||||
@@ -65,51 +65,6 @@ public class RefreshModel {
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshData( MogoLatLng latLng, int radius, int limit, final RefreshCallback callback ) {
|
||||
if ( mRefreshApiService != null ) {
|
||||
final Map< String, Object > query = new ParamsProvider.Builder( mContext ).build();
|
||||
final RefreshBody refreshBody = new RefreshBody();
|
||||
refreshBody.limit = limit;
|
||||
refreshBody.location = new RefreshBody.LatLon( latLng.lat, latLng.lng );
|
||||
refreshBody.radius = radius;
|
||||
refreshBody.dataType.add( ServiceConst.CARD_TYPE_ROAD_CONDITION );
|
||||
|
||||
String data = GsonUtil.jsonFromObject( refreshBody );
|
||||
query.put( "data", data );
|
||||
Logger.d( TAG, data );
|
||||
|
||||
|
||||
mRefreshApiService.refreshData( query )
|
||||
.subscribeOn( Schedulers.io() )
|
||||
.observeOn( AndroidSchedulers.mainThread() )
|
||||
.subscribe( new SubscribeImpl< BaseData >( RequestOptions.create( mContext ) ) {
|
||||
@Override
|
||||
public void onSuccess( BaseData o ) {
|
||||
super.onSuccess( o );
|
||||
if ( callback != null ) {
|
||||
callback.onSuccess( o );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError( Throwable e ) {
|
||||
super.onError( e );
|
||||
if ( callback != null ) {
|
||||
callback.onFail();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError( String message, int code ) {
|
||||
super.onError( message, code );
|
||||
if ( callback != null ) {
|
||||
callback.onFail();
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshExplorerWayData( MogoLatLng latLng, int radius, int limit, final RefreshCallback callback ) {
|
||||
if ( mRefreshApiService != null ) {
|
||||
final Map< String, Object > query = new ParamsProvider.Builder( mContext ).build();
|
||||
@@ -155,7 +110,7 @@ public class RefreshModel {
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshDataSync( MogoLatLng latLng, int radius, int limit, final RefreshCallback callback ) {
|
||||
public void refreshLauncherCardDataSync( MogoLatLng latLng, int radius, int limit, final RefreshCallback callback ) {
|
||||
if ( mRefreshApiService != null ) {
|
||||
final Map< String, Object > query = new ParamsProvider.Builder( mContext ).build();
|
||||
final RefreshBody refreshBody = new RefreshBody();
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.mogo.module.service.network.bean;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/9/22
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
class HomeCompanyDistanceForPushData {
|
||||
|
||||
public double lon;
|
||||
public double lat;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.mogo.module.service.network.bean;
|
||||
|
||||
import com.mogo.commons.data.BaseData;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/9/22
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
class HomeCompanyDistanceForPushResponse extends BaseData {
|
||||
|
||||
public HomeCompanyDistanceForPushResult result;
|
||||
|
||||
public static class HomeCompanyDistanceForPushResult {
|
||||
public boolean pushFlag;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.mogo.module.service.onlinecar.panel;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/9/21
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
class ContainerHandler {
|
||||
|
||||
public static int sContainerId = 0;
|
||||
public static FragmentActivity sAttachContext;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.mogo.module.service.onlinecar.panel;
|
||||
|
||||
import com.mogo.commons.mvp.IView;
|
||||
import com.mogo.module.common.entity.MarkerOnlineCar;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/9/21
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
interface IOnlineCarPanelView extends IView {
|
||||
|
||||
void renderOnlineCarList( List< MarkerOnlineCar > onlineCars );
|
||||
|
||||
void renderEmptyUi( OnlineCarStrategy strategy );
|
||||
|
||||
void renderNoNavigationInfoUi();
|
||||
|
||||
void renderErrorUi();
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.mogo.module.service.onlinecar.panel;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/9/21
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
class NavigationTargetInfo {
|
||||
|
||||
|
||||
/**
|
||||
* FromPoiName : 东城区小黄庄北街2号
|
||||
* FromPoiAddr : 在中国银行(北京安贞桥支行)附近
|
||||
* FromPoiLongitude : 116.41082763671875
|
||||
* FromPoiLatitude : 39.96831130981445
|
||||
* ToPoiName : 北京市北京市北小营镇宏大工业开发中心A座7号
|
||||
* ToPoiLongitude : 116.74490356445312
|
||||
* ToPoiLatitude : 40.19820785522461
|
||||
*/
|
||||
private String FromPoiName;
|
||||
private String FromPoiAddr;
|
||||
private String FromPoiLongitude;
|
||||
private String FromPoiLatitude;
|
||||
private String ToPoiName;
|
||||
private String ToPoiLongitude;
|
||||
private String ToPoiLatitude;
|
||||
|
||||
public String getFromPoiName() {
|
||||
return FromPoiName;
|
||||
}
|
||||
|
||||
public void setFromPoiName( String FromPoiName ) {
|
||||
this.FromPoiName = FromPoiName;
|
||||
}
|
||||
|
||||
public String getFromPoiAddr() {
|
||||
return FromPoiAddr;
|
||||
}
|
||||
|
||||
public void setFromPoiAddr( String FromPoiAddr ) {
|
||||
this.FromPoiAddr = FromPoiAddr;
|
||||
}
|
||||
|
||||
public String getFromPoiLongitude() {
|
||||
return FromPoiLongitude;
|
||||
}
|
||||
|
||||
public void setFromPoiLongitude( String FromPoiLongitude ) {
|
||||
this.FromPoiLongitude = FromPoiLongitude;
|
||||
}
|
||||
|
||||
public String getFromPoiLatitude() {
|
||||
return FromPoiLatitude;
|
||||
}
|
||||
|
||||
public void setFromPoiLatitude( String FromPoiLatitude ) {
|
||||
this.FromPoiLatitude = FromPoiLatitude;
|
||||
}
|
||||
|
||||
public String getToPoiName() {
|
||||
return ToPoiName;
|
||||
}
|
||||
|
||||
public void setToPoiName( String ToPoiName ) {
|
||||
this.ToPoiName = ToPoiName;
|
||||
}
|
||||
|
||||
public String getToPoiLongitude() {
|
||||
return ToPoiLongitude;
|
||||
}
|
||||
|
||||
public void setToPoiLongitude( String ToPoiLongitude ) {
|
||||
this.ToPoiLongitude = ToPoiLongitude;
|
||||
}
|
||||
|
||||
public String getToPoiLatitude() {
|
||||
return ToPoiLatitude;
|
||||
}
|
||||
|
||||
public void setToPoiLatitude( String ToPoiLatitude ) {
|
||||
this.ToPoiLatitude = ToPoiLatitude;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.mogo.module.service.onlinecar.panel;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.strategy.IMogoOnlineCarListPanelProvider;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/9/21
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
@Route( path = MogoServicePaths.PATH_ONLINE_CAR_PANEL )
|
||||
class OnlineCarListPanelProvider implements IMogoOnlineCarListPanelProvider {
|
||||
|
||||
private static final String TAG = "OnlineCarListPanelProvider";
|
||||
|
||||
@Override
|
||||
public void initContainer( int containerId, FragmentActivity activity ) {
|
||||
ContainerHandler.sContainerId = containerId;
|
||||
ContainerHandler.sAttachContext = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showPanel() {
|
||||
if ( isFragmentExist( ContainerHandler.sAttachContext ) ) {
|
||||
return;
|
||||
}
|
||||
Fragment fragment = new OnlineCarPanelFragment();
|
||||
ContainerHandler.sAttachContext
|
||||
.getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace( ContainerHandler.sContainerId, fragment, TAG )
|
||||
.commitNowAllowingStateLoss();
|
||||
}
|
||||
|
||||
private boolean isFragmentExist( Context context ) {
|
||||
if ( !( context instanceof FragmentActivity ) ) {
|
||||
Logger.w( TAG, "context is not a instance of FragmentActivity" );
|
||||
return false;
|
||||
}
|
||||
Fragment fragment = null;
|
||||
return ( fragment = ( ( FragmentActivity ) context )
|
||||
.getSupportFragmentManager()
|
||||
.findFragmentByTag( TAG ) ) != null && fragment.isAdded();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hidePanel() {
|
||||
Fragment fragment = ContainerHandler.sAttachContext.getSupportFragmentManager().findFragmentByTag( TAG );
|
||||
if ( fragment != null ) {
|
||||
ContainerHandler.sAttachContext
|
||||
.getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.remove( fragment )
|
||||
.commitNowAllowingStateLoss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
ContainerHandler.sContainerId = 0;
|
||||
ContainerHandler.sAttachContext = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.mogo.module.service.onlinecar.panel;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.module.common.entity.MarkerLocation;
|
||||
import com.mogo.module.common.entity.MarkerOnlineCar;
|
||||
import com.mogo.module.common.glide.SkinAbleBitmapTarget;
|
||||
import com.mogo.module.service.MarkerServiceHandler;
|
||||
import com.mogo.module.service.R;
|
||||
import com.mogo.module.service.Utils;
|
||||
import com.mogo.utils.ResourcesHelper;
|
||||
import com.mogo.utils.WindowUtils;
|
||||
import com.mogo.utils.glide.GlideApp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/9/21
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
class OnlineCarPanelAdapter extends RecyclerView.Adapter< OnlineCarPanelAdapter.VH > {
|
||||
|
||||
private List< MarkerOnlineCar > mDatums;
|
||||
|
||||
public OnlineCarPanelAdapter( List< MarkerOnlineCar > mDatums ) {
|
||||
this.mDatums = 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 ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder( @NonNull OnlineCarPanelAdapter.VH holder, int position ) {
|
||||
holder.bind( mDatums.get( position ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mDatums == null ? 0 : mDatums.size();
|
||||
}
|
||||
|
||||
public static class VH extends RecyclerView.ViewHolder {
|
||||
|
||||
private ImageView avatar;
|
||||
private TextView nickname;
|
||||
private TextView distance;
|
||||
private TextView 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 );
|
||||
}
|
||||
|
||||
public void bind( MarkerOnlineCar car ) {
|
||||
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() );
|
||||
distance.setText( content );
|
||||
detail.setOnClickListener( view -> {
|
||||
MogoApisHandler.getInstance().getApis().getAnalyticsApi().track( "Mogoer_List_click", null );
|
||||
} );
|
||||
}
|
||||
|
||||
private String getDistanceStr( MarkerLocation location ) {
|
||||
MogoLocation mogoLocation = MarkerServiceHandler.getApis().getMapServiceApi().getSingletonLocationClient( itemView.getContext() ).getLastKnowLocation();
|
||||
if ( location == null ) {
|
||||
return "";
|
||||
}
|
||||
if ( mogoLocation == null ) {
|
||||
return "";
|
||||
}
|
||||
float distance = Utils.calculateLineDistance( location.getLon(), location.getLat(), mogoLocation.getLongitude(), mogoLocation.getLatitude() );
|
||||
if ( distance >= 1000 ) {
|
||||
return String.format( "%.1fKM", distance / 1000 );
|
||||
} else {
|
||||
return String.format( "%.1fM", distance );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.mogo.module.service.onlinecar.panel;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.mogo.commons.mvp.MvpFragment;
|
||||
import com.mogo.commons.voice.AIAssist;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.module.common.entity.MarkerOnlineCar;
|
||||
import com.mogo.module.service.MarkerServiceHandler;
|
||||
import com.mogo.module.service.R;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/9/21
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class OnlineCarPanelFragment extends MvpFragment< IOnlineCarPanelView, OnlineCarPanelPresenter > implements IOnlineCarPanelView {
|
||||
|
||||
private RecyclerView mList;
|
||||
private View mRefreshPanel;
|
||||
private View mErrorPanel;
|
||||
|
||||
private OnlineCarPanelAdapter mOnlineCarPanelAdapter;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.module_services_fragment_online_car_panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
findViewById( R.id.module_services_id_close ).setOnClickListener( view -> {
|
||||
MarkerServiceHandler.getApis().getOnlineCarPanelApi().hidePanel();
|
||||
} );
|
||||
mList = findViewById( R.id.module_services_id_recycler_view );
|
||||
mRefreshPanel = findViewById( R.id.module_services_id_load_strategy_container );
|
||||
mErrorPanel = findViewById( R.id.module_services_id_error_container );
|
||||
|
||||
mList.setLayoutManager( new LinearLayoutManager( getContext(), LinearLayoutManager.VERTICAL, false ) );
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected OnlineCarPanelPresenter createPresenter() {
|
||||
return new OnlineCarPanelPresenter( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderOnlineCarList( List< MarkerOnlineCar > onlineCars ) {
|
||||
mRefreshPanel.setVisibility( View.GONE );
|
||||
mErrorPanel.setVisibility( View.GONE );
|
||||
mList.setVisibility( View.VISIBLE );
|
||||
if ( mOnlineCarPanelAdapter == null ) {
|
||||
mOnlineCarPanelAdapter = new OnlineCarPanelAdapter( onlineCars );
|
||||
mList.setAdapter( mOnlineCarPanelAdapter );
|
||||
} else {
|
||||
mOnlineCarPanelAdapter.setDatums( onlineCars );
|
||||
}
|
||||
AIAssist.getInstance( getContext() ).speakTTSVoice( String.format( "为您找到%s个车友", onlineCars.size() ) );
|
||||
Map< String, Object > properties = new HashMap<>();
|
||||
properties.put( "number", onlineCars.size() );
|
||||
MogoApisHandler.getInstance().getApis().getAnalyticsApi().track( "Mogoer_List_number", properties );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderEmptyUi( OnlineCarStrategy strategy ) {
|
||||
mErrorPanel.setVisibility( View.GONE );
|
||||
mList.setVisibility( View.GONE );
|
||||
mRefreshPanel.setVisibility( View.VISIBLE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderNoNavigationInfoUi() {
|
||||
mList.setVisibility( View.GONE );
|
||||
mRefreshPanel.setVisibility( View.GONE );
|
||||
mErrorPanel.setVisibility( View.VISIBLE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderErrorUi() {
|
||||
mList.setVisibility( View.GONE );
|
||||
mRefreshPanel.setVisibility( View.GONE );
|
||||
mErrorPanel.setVisibility( View.VISIBLE );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.mogo.module.service.onlinecar.panel;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
|
||||
import com.mogo.commons.mvp.Presenter;
|
||||
import com.mogo.commons.storage.SpStorage;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.module.common.entity.MarkerResponse;
|
||||
import com.mogo.module.service.network.RefreshCallback;
|
||||
import com.mogo.module.service.network.RefreshModel;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/9/21
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
class OnlineCarPanelPresenter extends Presenter< IOnlineCarPanelView > implements RefreshCallback< MarkerResponse > {
|
||||
|
||||
public static final int LIMIT = 20;
|
||||
private RefreshModel mRefreshModel;
|
||||
private OnlineCarStrategy mStrategy;
|
||||
private NavigationTargetInfo mNavigationTargetInfo;
|
||||
|
||||
public OnlineCarPanelPresenter( IOnlineCarPanelView view ) {
|
||||
super( view );
|
||||
mRefreshModel = new RefreshModel( getContext() );
|
||||
mStrategy = OnlineCarStrategy.Default;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate( @NonNull LifecycleOwner owner ) {
|
||||
super.onCreate( owner );
|
||||
String json = SpStorage.getNavigationTarget();
|
||||
if ( TextUtils.isEmpty( json ) ) {
|
||||
mView.renderNoNavigationInfoUi();
|
||||
return;
|
||||
}
|
||||
mNavigationTargetInfo = GsonUtil.objectFromJson( json, NavigationTargetInfo.class );
|
||||
loadOnlineCar();
|
||||
}
|
||||
|
||||
public void loadOnlineCar() {
|
||||
if ( mNavigationTargetInfo == null ) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
double toLat = Double.valueOf( mNavigationTargetInfo.getToPoiLatitude() );
|
||||
double toLon = Double.valueOf( mNavigationTargetInfo.getToPoiLongitude() );
|
||||
mRefreshModel.queryOnLineCarWithRoute( new MogoLatLng( toLat, toLon ),
|
||||
false,
|
||||
false,
|
||||
mStrategy.getRadius(),
|
||||
LIMIT,
|
||||
this
|
||||
);
|
||||
} catch ( Exception e ) {
|
||||
mView.renderNoNavigationInfoUi();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess( MarkerResponse o ) {
|
||||
if ( o == null || o.getResult() == null ) {
|
||||
mView.renderErrorUi();
|
||||
} else {
|
||||
if ( o.getResult().getOnlineCar() == null || o.getResult().getOnlineCar().isEmpty() ) {
|
||||
mView.renderEmptyUi( mStrategy );
|
||||
} else {
|
||||
mView.renderOnlineCarList( o.getResult().getOnlineCar() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail() {
|
||||
mView.renderErrorUi();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.mogo.module.service.onlinecar.panel;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/9/21
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
enum OnlineCarStrategy {
|
||||
|
||||
Strategy3( 40_000, null ),
|
||||
Strategy2( 20_000, Strategy3 ),
|
||||
Default( 10_000, Strategy2 ),
|
||||
;
|
||||
|
||||
private int radius;
|
||||
private OnlineCarStrategy next;
|
||||
|
||||
OnlineCarStrategy( int radius, OnlineCarStrategy next ) {
|
||||
this.radius = radius;
|
||||
this.next = next;
|
||||
}
|
||||
|
||||
public int getRadius() {
|
||||
return radius;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user