|
|
@@ -55,9 +55,11 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
|
|
|
private String loaction;
|
|
|
private String address;
|
|
|
|
|
|
- private double companyLatitude;
|
|
|
- private double companyLongitude;
|
|
|
- private int companyDistance;
|
|
|
+ // private double companyLatitude;
|
|
|
+// private double companyLongitude;
|
|
|
+// private int companyDistance;
|
|
|
+ private List<WorkLocationBean> locationList;
|
|
|
+ private WorkLocationBean companyLocation;
|
|
|
|
|
|
private boolean isMacInNet = false;//服务器上是否有mac地址
|
|
|
private boolean isSubmiting = false;
|
|
|
@@ -154,7 +156,6 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
|
|
|
|
|
|
//设置位置信息
|
|
|
private void setBaiduLocation() throws Exception {
|
|
|
- log("setBaiduLocation");
|
|
|
boolean isLocation = MyApplication.getInstance().getBdLocationHelper().locationOk();
|
|
|
if (!isLocation) {
|
|
|
if (iWorkView != null) {
|
|
|
@@ -175,10 +176,17 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
|
|
|
//获取与公司距离
|
|
|
private String getDistance() {
|
|
|
try {
|
|
|
- String dis = getInstence().getDistance(companyLongitude, companyLatitude, latitude, longitude);
|
|
|
- distance = Double.valueOf(dis);
|
|
|
- if (StringUtils.isEmpty(dis)) return "";
|
|
|
- return "约" + dis + "米";
|
|
|
+ if (ListUtils.isEmpty(locationList)) return "";
|
|
|
+ for (WorkLocationBean b : locationList) {
|
|
|
+ String dis = getInstence().getDistance(b.getLatitude(), b.getLongitude(),
|
|
|
+ latitude, longitude);
|
|
|
+ if (StringUtils.isEmpty(dis)) continue;
|
|
|
+ if (distance == 0 || distance > Double.valueOf(dis)) {
|
|
|
+ distance = Double.valueOf(dis);
|
|
|
+ companyLocation = b;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "约" + distance + "米";
|
|
|
} catch (Exception e) {
|
|
|
return "";
|
|
|
}
|
|
|
@@ -187,21 +195,26 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
|
|
|
private final int ADDRESS_CHANGE = 0x14;
|
|
|
|
|
|
public void gotoLocationActivity(Activity ct) {
|
|
|
+ if (companyLocation == null) {
|
|
|
+ iWorkView.showToast("没有可以选择的地址", R.color.load_error);
|
|
|
+ return;
|
|
|
+ }
|
|
|
Intent intent = new Intent(ct, LocationSearchActivity.class);
|
|
|
intent.putExtra("type", 1);
|
|
|
intent.putExtra("title", "地点微调");
|
|
|
intent.putExtra("single", true);
|
|
|
intent.putExtra("radius", 300);
|
|
|
intent.putExtra("isSort", true);
|
|
|
- intent.putExtra("latlng", new LatLng(companyLongitude, companyLatitude));
|
|
|
+ intent.putExtra("latlng", companyLocation.getLatitude());
|
|
|
intent.putExtra("resultCode", ADDRESS_CHANGE);
|
|
|
intent.putExtra("resultName", "resultName");
|
|
|
ct.startActivityForResult(intent, ADDRESS_CHANGE);
|
|
|
}
|
|
|
|
|
|
private void getPoi() {
|
|
|
+ if (companyLocation == null) return;
|
|
|
//公司地址必须反过来
|
|
|
- final LatLng compayLng = new LatLng(companyLongitude, companyLatitude);
|
|
|
+ final LatLng compayLng = new LatLng(companyLocation.getLongitude(), companyLocation.getLatitude());
|
|
|
LatLng latLng = new LatLng(latitude, longitude);
|
|
|
BaiduMapUtil.getInstence().getNearInfo(500, 0, latLng,
|
|
|
"公司", new BaiduMapUtil.OnSearchPoiListener() {
|
|
|
@@ -212,7 +225,7 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
|
|
|
if (ListUtils.isEmpty(pois)) return;
|
|
|
for (int i = 0; i < pois.size(); i++) {
|
|
|
double dis = BaiduMapUtil.getInstence().distance(compayLng, pois.get(i).location);
|
|
|
- if (companyDistance < dis) {
|
|
|
+ if (companyLocation.getInnerdistance() < dis) {
|
|
|
pois.remove(i);
|
|
|
i--;
|
|
|
}
|
|
|
@@ -239,27 +252,17 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
|
|
|
return;
|
|
|
}
|
|
|
JSONObject object = JSON.parseObject(message);
|
|
|
- int innerdistance = handerLocation(object);
|
|
|
+ handerLocation(object);
|
|
|
isFree = object.getBoolean("ifNeedSignCard");
|
|
|
if (isFree) {
|
|
|
loadLog(null, time);
|
|
|
return;
|
|
|
}
|
|
|
- boolean comaddressset = object.getBooleanValue("comaddressset");
|
|
|
- if (comaddressset) {
|
|
|
- companyLongitude = object.getDoubleValue("longitude");
|
|
|
- companyLatitude = object.getDoubleValue("latitude");
|
|
|
- companyDistance = object.getIntValue("distance");
|
|
|
- innerdistance = object.getIntValue("innerdistance");
|
|
|
- }
|
|
|
try {
|
|
|
- getPoi();
|
|
|
- if (companyLongitude == 0 || companyLatitude == 0 && iWorkView != null)
|
|
|
+ if (ListUtils.isEmpty(locationList) && iWorkView != null)
|
|
|
iWorkView.showToast(R.string.not_addr_message, R.color.load_warning);
|
|
|
- PreferenceUtils.putInt("distance", companyDistance);
|
|
|
- PreferenceUtils.putInt("innerdistance", innerdistance);
|
|
|
- PreferenceUtils.putFloat("longitude", (float) companyLongitude);
|
|
|
- PreferenceUtils.putFloat("latitude", (float) companyLatitude);
|
|
|
+ else getPoi();
|
|
|
+
|
|
|
setBaiduLocation();
|
|
|
} catch (ClassCastException e) {
|
|
|
if (e != null)
|
|
|
@@ -290,17 +293,20 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
|
|
|
loadLog(models, time);
|
|
|
}
|
|
|
|
|
|
- private int handerLocation(JSONObject object) {
|
|
|
+ private void handerLocation(JSONObject object) {
|
|
|
JSONArray array = object.getJSONArray("comAddressdata");
|
|
|
if (ListUtils.isEmpty(array)) {
|
|
|
//TODO 为空时候
|
|
|
- return 0;
|
|
|
+ return;
|
|
|
}
|
|
|
- List<WorkLocationBean> beanList = new ArrayList<>();
|
|
|
+ if (ListUtils.isEmpty(locationList))
|
|
|
+ locationList = new ArrayList<>();
|
|
|
+ else locationList.clear();
|
|
|
WorkLocationBean bean = null;
|
|
|
JSONObject o = null;
|
|
|
float dis = 0;
|
|
|
for (int i = 0; i < array.size(); i++) {
|
|
|
+ o = array.getJSONObject(i);
|
|
|
bean = new WorkLocationBean();
|
|
|
int id = o.getInteger("CS_ID");
|
|
|
int innerdistance = o.getInteger("CS_INNERDISTANCE");//办公距离
|
|
|
@@ -316,15 +322,16 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
|
|
|
bean.setShortName(shortname);
|
|
|
bean.setWorkaddr(workaddr);
|
|
|
bean.setInnerdistance(innerdistance);
|
|
|
- beanList.add(bean);
|
|
|
+ locationList.add(bean);
|
|
|
if (dis == 0) {
|
|
|
dis = BaiduMapUtil.getInstence().autoDistance(location);
|
|
|
+ companyLocation = bean;
|
|
|
} else if (dis > BaiduMapUtil.getInstence().autoDistance(location)) {
|
|
|
dis = BaiduMapUtil.getInstence().autoDistance(location);
|
|
|
+ companyLocation = bean;
|
|
|
}
|
|
|
}
|
|
|
- boolean saveOk = WorkLocationDao.getInstance().clearAndInsert(beanList);
|
|
|
- return 0;
|
|
|
+ boolean saveOk = WorkLocationDao.getInstance().clearAndInsert(locationList);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -496,7 +503,7 @@ public class WorkPresenter implements HttpHandler.OnResultListener, IWorkPresent
|
|
|
if (iWorkView != null)
|
|
|
iWorkView.showToast(R.string.not_signin_agin, R.color.load_warning);
|
|
|
return false;
|
|
|
- } else if (companyDistance == 0 || distance == 0 || companyDistance < distance) {
|
|
|
+ } else if (distance == 0 || companyLocation == null || companyLocation.getInnerdistance() < distance) {
|
|
|
if (iWorkView != null)
|
|
|
iWorkView.showToast(R.string.too_long, R.color.load_warning);
|
|
|
return false;
|