opt logic

This commit is contained in:
tongchenfei
2021-01-19 19:56:32 +08:00
parent 302b4c436c
commit d187af5d98
13 changed files with 283 additions and 60 deletions

View File

@@ -85,7 +85,8 @@ public class OchBusProvider implements IMogoOCH {
@Override
public void onMsgReceived(List<OchBusStation> obj) {
// todo 刷新界面
// 刷新列表
busFragment.getPresenter().getStationListFromSocket(obj);
}
};

View File

@@ -0,0 +1,24 @@
package com.mogo.och.bus.bean;
/**
* 公交驶离车站,同步服务端请求参数封装
*
* @author tongchenfei
*/
public class OchBusLeaveStationRequest {
private final String sn;
private final int siteId;
public OchBusLeaveStationRequest(String sn, int siteId) {
this.sn = sn;
this.siteId = siteId;
}
public String getSn() {
return sn;
}
public int getSiteId() {
return siteId;
}
}

View File

@@ -8,10 +8,12 @@ package com.mogo.och.bus.bean;
public class OchBusRoutesRequest {
double lat;
double lon;
String sn;
public OchBusRoutesRequest(double lat, double lon) {
public OchBusRoutesRequest(String sn, double lat, double lon) {
this.lat = lat;
this.lon = lon;
this.sn = sn;
}
public double getLat() {
@@ -29,4 +31,12 @@ public class OchBusRoutesRequest {
public void setLon(double lon) {
this.lon = lon;
}
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
}

View File

@@ -18,7 +18,10 @@ public class OchBusRoutesResponse extends BaseData {
this.result = result;
}
@Override
public String toString() {
return "OchBusRoutesResponse{" +
"result=" + result +
'}';
}
}

View File

@@ -8,20 +8,20 @@ import java.util.List;
* @author tongchenfei
*/
public class OchBusRoutesResult {
private List<OchBusStation> siteData;
private List<OchBusStation> site;
public List<OchBusStation> getSiteData() {
return siteData;
public List<OchBusStation> getSite() {
return site;
}
public void setSiteData(List<OchBusStation> siteData) {
this.siteData = siteData;
public void setSite(List<OchBusStation> site) {
this.site = site;
}
@Override
public String toString() {
return "OchBusRoutesResult{" +
"siteData=" + siteData +
"site=" + site +
'}';
}
}

View File

@@ -6,8 +6,6 @@ package com.mogo.och.bus.bean;
* @author tongchenfei
*/
public class OchBusStation {
private double distance;
private String _id;
private int lineId;
private int siteId;
private String siteName;
@@ -18,22 +16,10 @@ public class OchBusStation {
private double lon;
private String siteDesc;
private int siteState;
private int isCurrentSite;
private int siteColor;
private String peoples;
public double getDistance() {
return distance;
}
public void setDistance(double distance) {
this.distance = distance;
}
public String get_id() {
return _id;
}
public void set_id(String _id) {
this._id = _id;
}
public int getLineId() {
return lineId;
@@ -115,12 +101,34 @@ public class OchBusStation {
this.siteState = siteState;
}
public int getIsCurrentSite() {
return isCurrentSite;
}
public void setIsCurrentSite(int isCurrentSite) {
this.isCurrentSite = isCurrentSite;
}
public int getSiteColor() {
return siteColor;
}
public void setSiteColor(int siteColor) {
this.siteColor = siteColor;
}
public String getPeoples() {
return peoples;
}
public void setPeoples(String peoples) {
this.peoples = peoples;
}
@Override
public String toString() {
return "OchBusStation{" +
"distance=" + distance +
", _id='" + _id + '\'' +
", lineId=" + lineId +
"lineId=" + lineId +
", siteId=" + siteId +
", siteName='" + siteName + '\'' +
", cityCode='" + cityCode + '\'' +
@@ -130,6 +138,9 @@ public class OchBusStation {
", lon=" + lon +
", siteDesc='" + siteDesc + '\'' +
", siteState=" + siteState +
", isCurrentSite=" + isCurrentSite +
", siteColor=" + siteColor +
", peoples='" + peoples + '\'' +
'}';
}
}

View File

@@ -1,6 +1,8 @@
package com.mogo.och.bus.fragment;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.Group;
@@ -8,11 +10,12 @@ import androidx.constraintlayout.widget.Group;
import com.mogo.commons.mvp.MvpFragment;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.view.OnPreventFastClickListener;
import com.mogo.och.bus.R;
import com.mogo.och.bus.bean.OchBusStation;
import com.mogo.och.bus.presenter.OchBusPresenter;
import com.mogo.och.bus.R;
import com.mogo.utils.logger.Logger;
import java.util.ArrayList;
import java.util.List;
@@ -24,7 +27,9 @@ import java.util.List;
public class OchBusFragment extends MvpFragment<OchBusFragment, OchBusPresenter> {
private static final String TAG = "OchBusFragment";
private Group groupOchBus;
private List<OchBusStation> stationList;
private final List<OchBusStation> stationList = new ArrayList<>();
private Button btnExecute;
private TextView tvNotice;
@Override
protected int getLayoutId() {
@@ -40,6 +45,14 @@ public class OchBusFragment extends MvpFragment<OchBusFragment, OchBusPresenter>
showOchBus();
}
});
btnExecute = findViewById(R.id.btnExecute);
btnExecute.setOnClickListener(new OnPreventFastClickListener() {
@Override
public void onClickImpl(View v) {
mPresenter.autoDriveToNextStation();
}
});
tvNotice = findViewById(R.id.vBusRoute);
}
@NonNull
@@ -71,19 +84,44 @@ public class OchBusFragment extends MvpFragment<OchBusFragment, OchBusPresenter>
}
public void refreshBusStations(List<OchBusStation> busStationList) {
if (busStationList == null) {
// todo 获取小巴数据失败
}else{
// todo 渲染小巴路线数据
if (getActivity() == null) {
return;
}
getActivity().runOnUiThread(() -> {
if (busStationList == null) {
// todo 获取小巴数据失败
} else {
// todo 渲染小巴路线数据
stationList.clear();
stationList.addAll(busStationList);
for (int i = 0; i < stationList.size(); i++) {
OchBusStation station = stationList.get(i);
if (station.getIsCurrentSite() == OchBusPresenter.STATION_STATUS_LEAVING) {
tvNotice.setText("正在从 " + i + "站驶向" + (i + 1) + "");
btnExecute.setVisibility(View.GONE);
break;
} else if (station.getIsCurrentSite() == OchBusPresenter.STATION_STATUS_STOPED) {
tvNotice.setText("车辆正停在" + i + "");
btnExecute.setVisibility(View.VISIBLE);
if (i == stationList.size() - 1) {
btnExecute.setText("单程结束");
}else if(i == 0){
btnExecute.setText("准备出发");
}else{
btnExecute.setText("乘客已上车,准备出发");
}
break;
}
}
}
});
}
public void hideOchBus() {
groupOchBus.setVisibility(View.GONE);
}
private void queryStationListIfNecessary(){
private void queryStationListIfNecessary() {
if (stationList == null || stationList.isEmpty()) {
mPresenter.queryBusRoutes();
}

View File

@@ -1,5 +1,6 @@
package com.mogo.och.bus.net;
import com.mogo.commons.data.BaseData;
import com.mogo.och.bus.bean.OchBusRoutesResponse;
import io.reactivex.Observable;
@@ -26,4 +27,15 @@ public interface IOchBusApiService {
@Headers({"Content-Type:application/json;charset=UTF-8"})
@POST("/yycp-onlinecar-hailing/onlineCarHailing/site/querySiteByCoordinate/v1")
Observable<OchBusRoutesResponse> querySiteByCoordinate(@Body RequestBody requestBody);
/**
* 公交车驶离车站时,通知服务端
* @param requestBody 请求参数 {"sn":"","siteId":"车站id"}
* @return 无返回值
*/
@Headers({"Content-Type:application/json;charset=UTF-8"})
@POST("/yycp-onlinecar-hailing/onlineCarHailing/site/siteCrashCheck/v1")
Observable<BaseData> leaveStation(@Body RequestBody requestBody);
}

View File

@@ -1,18 +1,28 @@
package com.mogo.och.bus.presenter;
import com.mogo.commons.data.BaseData;
import com.mogo.commons.mvp.Presenter;
import com.mogo.commons.network.SubscribeImpl;
import com.mogo.commons.network.Utils;
import com.mogo.map.location.MogoLocation;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.constants.HostConst;
import com.mogo.och.bus.bean.OchBusLeaveStationRequest;
import com.mogo.och.bus.bean.OchBusRoutesRequest;
import com.mogo.och.bus.bean.OchBusRoutesResponse;
import com.mogo.och.bus.bean.OchBusStation;
import com.mogo.och.bus.fragment.OchBusFragment;
import com.mogo.och.bus.net.IOchBusApiService;
import com.mogo.service.adas.IMogoAdasOCHCallback;
import com.mogo.service.adas.RemoteControlAutoPilotParameters;
import com.mogo.service.adas.entity.AdasOCHData;
import com.mogo.utils.logger.Logger;
import com.mogo.utils.network.RequestOptions;
import com.mogo.utils.network.utils.GsonUtil;
import java.util.ArrayList;
import java.util.List;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
@@ -23,12 +33,24 @@ import okhttp3.RequestBody;
*
* @author tongchenfei
*/
public class OchBusPresenter extends Presenter<OchBusFragment> {
public class OchBusPresenter extends Presenter<OchBusFragment> implements IMogoAdasOCHCallback {
private static final String TAG = "OchBusPresenter";
private static final int VEHICAL_TYPE = 10;
public static final int STATION_STATUS_IDLE = 0;
public static final int STATION_STATUS_STOPED = 1;
public static final int STATION_STATUS_LEAVING = 2;
public static final int STATION_STATUS_ARRIVING = 3;
public OchBusPresenter(OchBusFragment view) {
super(view);
MogoApisHandler.getInstance().getApis().getAdasControllerApi().addAdasOCHCallback(this);
}
private final List<OchBusStation> stationList = new ArrayList<>();
private int currentStationIndex = 0;
public void queryBusRoutes() {
double lat = 0;
double lon = 0;
@@ -37,10 +59,10 @@ public class OchBusPresenter extends Presenter<OchBusFragment> {
lat = lastLocation.getLatitude();
lon = lastLocation.getLongitude();
}
OchBusRoutesRequest request = new OchBusRoutesRequest(lat,lon);
OchBusRoutesRequest request = new OchBusRoutesRequest(Utils.getSn(),lat, lon);
RequestBody requestBody = RequestBody.create(MediaType.get("application/json"), GsonUtil.jsonFromObject(request));
MogoApisHandler.getInstance().getApis().getNetworkApi()
.create(IOchBusApiService.class, HostConst.HAILING_HOST)
.create(IOchBusApiService.class, HostConst.OCH_DOMAIN)
.querySiteByCoordinate(requestBody)
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<OchBusRoutesResponse>(RequestOptions.create(getContext())) {
@@ -49,15 +71,18 @@ public class OchBusPresenter extends Presenter<OchBusFragment> {
public void onSuccess(OchBusRoutesResponse o) {
super.onSuccess(o);
Logger.d(TAG, "获取到小巴路线数据: " + o);
if (mView != null) {
// mView.refreshBusStations(o.getResult().getSiteData());
if (mView != null && o.getResult() != null && o.getResult().getSite() != null) {
stationList.clear();
stationList.addAll(o.getResult().getSite());
refreshCurrentStation();
mView.refreshBusStations(stationList);
}
}
@Override
public void onError(Throwable e) {
super.onError(e);
Logger.e(TAG,e,"获取小巴路线图失败");
Logger.e(TAG, e, "获取小巴路线图失败");
if (mView != null) {
mView.refreshBusStations(null);
}
@@ -73,4 +98,91 @@ public class OchBusPresenter extends Presenter<OchBusFragment> {
}
});
}
public void getStationListFromSocket(List<OchBusStation> stations) {
// 接收长连接消息好像没啥用
// stationList.clear();
// stationList.addAll(stations);
// refreshCurrentStation();
// if (mView != null) {
// mView.refreshBusStationsInUiThread(stationList);
// }
}
public void autoDriveToNextStation() {
if (currentStationIndex >= stationList.size() - 1) {
// 当前站是最后一站,结束当前行程
travelOver();
return;
}
OchBusStation currentStation = stationList.get(currentStationIndex);
OchBusStation nextStation = stationList.get(currentStationIndex + 1);
currentStation.setIsCurrentSite(STATION_STATUS_LEAVING);
nextStation.setIsCurrentSite(STATION_STATUS_ARRIVING);
RemoteControlAutoPilotParameters parameters = new RemoteControlAutoPilotParameters();
parameters.startLatLon = new RemoteControlAutoPilotParameters.AutoPilotLonLat(currentStation.getLat(), currentStation.getLon());
parameters.endLatLon = new RemoteControlAutoPilotParameters.AutoPilotLonLat(nextStation.getLat(), nextStation.getLon());
parameters.vehicleType = VEHICAL_TYPE;
MogoApisHandler.getInstance().getApis().getAdasControllerApi().aiCloudToAdasData(parameters);
RequestBody request = RequestBody.create(MediaType.get("application/json"), GsonUtil.jsonFromObject(new OchBusLeaveStationRequest(Utils.getSn(), currentStation.getSiteId())));
MogoApisHandler.getInstance().getApis().getNetworkApi()
.create(IOchBusApiService.class, HostConst.OCH_DOMAIN)
.leaveStation(request).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<BaseData>(RequestOptions.create(getContext())) {
@Override
public void onError(String message, int code) {
super.onError(message, code);
Logger.d(TAG, "leave station error: " + message);
}
@Override
public void onError(Throwable e) {
super.onError(e);
Logger.e(TAG,e,"leave station exception");
}
});
if (mView != null) {
mView.refreshBusStations(stationList);
}
}
private void refreshCurrentStation() {
currentStationIndex = 0;
for (OchBusStation station : stationList) {
// 如果数据表发生更新,获取当前所在车站
if (station.getIsCurrentSite() == STATION_STATUS_STOPED || station.getIsCurrentSite() == STATION_STATUS_LEAVING) {
// 处于停靠或驶离时,是当前车站
break;
}
currentStationIndex++;
}
}
@Override
public void onArriveAt(AdasOCHData data) {
// 当前站改为IDLE下一站改为STATION_STATUS_STOPEDcurrentStationIndex增加1
stationList.get(currentStationIndex++).setIsCurrentSite(STATION_STATUS_IDLE);
stationList.get(currentStationIndex).setIsCurrentSite(STATION_STATUS_STOPED);
if (mView != null) {
mView.refreshBusStations(stationList);
}
}
private void travelOver(){
if (currentStationIndex >= stationList.size()) {
Logger.e(TAG, "index out of station list");
return;
}
// 始发站改为Stoped其他站改为Idle
stationList.get(currentStationIndex).setIsCurrentSite(STATION_STATUS_IDLE);
currentStationIndex = 0;
stationList.get(currentStationIndex).setIsCurrentSite(STATION_STATUS_STOPED);
if (mView != null) {
mView.refreshBusStations(stationList);
}
}
}

View File

@@ -1,30 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
android:layout_height="match_parent">
<Button
android:id="@+id/btnEnterOchBus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnEnterOchBus"
android:text="进入网约车小巴"
android:textSize="40sp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<View
<Button
android:id="@+id/btnExecute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="准备出发"
android:textSize="30sp"
app:layout_constraintRight_toRightOf="@id/vBusRoute"
app:layout_constraintTop_toBottomOf="@id/vBusRoute" />
<TextView
android:id="@+id/vBusRoute"
android:layout_width="600px"
android:layout_height="300px"
android:background="#0f0"
android:id="@+id/vBusRoute"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
android:gravity="center"
android:text="notice"
android:textSize="30sp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Group
android:id="@+id/groupOchBus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/groupOchBus"
app:constraint_referenced_ids="vBusRoute" />
app:constraint_referenced_ids="vBusRoute,btnExecute" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -18,8 +18,6 @@ public class HostConst {
public static final String STRATEGY_PUSH_HOST = "http://dzt-strategyPush.zhidaozhixing.com";
public static final String TRAVEL_CONDITION_HOST = "http://dzt-travelCondition.zhidaozhixing.com";
public static final String TMC_HOST = "http://dzt-tmcServer.zhidaozhixing.com";
public static final String HAILING_HOST = "http://dzt-hailing.zhidaozhixing.com";
public static final String IM_SOCKET_DOMAIN = "dzt-im.zhidaozhixing.com";
public static final String WEBSOCKET_DOMAIN = "dzt-Instant.zhidaozhixing.com";

View File

@@ -384,7 +384,9 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
mMove2CurrentLocation.setVisibility(View.VISIBLE);
mUploadRoadCondition.setVisibility(View.VISIBLE);
groupUserHead.setVisibility(View.VISIBLE);
seekHelpGroup.setVisibility(View.VISIBLE);
if(MogoApisHandler.getInstance().getApis().getStatusManagerApi().isSeekHelping()) {
seekHelpGroup.setVisibility(View.VISIBLE);
}
// mWeatherContainer.setVisibility(View.VISIBLE);
// mMsgContainer.setVisibility(View.VISIBLE);

View File

@@ -315,7 +315,7 @@
android:id="@+id/groupTopViewDebug"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
android:visibility="gone"
app:constraint_referenced_ids="btnShowDrawableTipNoSize,btnShowDrawableTip,btnShowTextTip,btnDebugCtrlNaviView,btnDebugCtrlSubView,btnDebugCtrlTopView,btnDebugAddBottomLayerView" />
<include