|
|
@@ -11,7 +11,6 @@ import com.baidu.mapapi.search.core.PoiInfo;
|
|
|
import com.baidu.mapapi.search.core.SearchResult;
|
|
|
import com.baidu.mapapi.search.poi.PoiResult;
|
|
|
import com.xzjmyk.pm.activity.AppConfig;
|
|
|
-import com.xzjmyk.pm.activity.BdLocationHelper;
|
|
|
import com.xzjmyk.pm.activity.MyApplication;
|
|
|
import com.xzjmyk.pm.activity.R;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.model.oa.SelectAimModel;
|
|
|
@@ -39,32 +38,25 @@ public class SelectAimPresenter implements HttpHandler.OnResultListener {
|
|
|
private ISelectAim iSelectAim;
|
|
|
private final int LOAD = 0x11;
|
|
|
private final int LOAD_CUSTOMER = 0x12;//拜访计划客户名称数据
|
|
|
- private BdLocationHelper locationHelper;
|
|
|
private List<SelectAimModel> models;//从服务其返回的数据列表
|
|
|
- private String keyWork;
|
|
|
- private boolean seachChina = false;
|
|
|
private List<SelectAimModel> keyList;//搜索企业筛选的人员
|
|
|
+ private int seachMapType = 0;//下拉百度地图数据类型 1.获取附近数据 2.获取全国数据 2.获取城市数据
|
|
|
+ private String keyWork;
|
|
|
private boolean isB2b;
|
|
|
|
|
|
|
|
|
public SelectAimPresenter(ISelectAim iSelectAim) {
|
|
|
+ if (iSelectAim == null) {
|
|
|
+ new NullPointerException("ISelectAim is null");
|
|
|
+ }
|
|
|
this.iSelectAim = iSelectAim;
|
|
|
}
|
|
|
|
|
|
- /******
|
|
|
- * start 对外接口
|
|
|
- **********/
|
|
|
- public void start() {
|
|
|
- locationHelper = MyApplication.getInstance().getBdLocationHelper();
|
|
|
- loadOutAddress();
|
|
|
- }
|
|
|
-
|
|
|
/******
|
|
|
* start 对外接口
|
|
|
**********/
|
|
|
public void start(int type) {
|
|
|
isB2b = ApiUtils.getApiModel() instanceof ApiPlatform;
|
|
|
- locationHelper = MyApplication.getInstance().getBdLocationHelper();
|
|
|
if (type == 1) {
|
|
|
loadCustomerData();
|
|
|
} else {
|
|
|
@@ -116,7 +108,6 @@ public class SelectAimPresenter implements HttpHandler.OnResultListener {
|
|
|
|
|
|
//从服务器获取数据
|
|
|
private void loadOutAddress() {
|
|
|
- log("loadOutAddress");
|
|
|
if (!MyApplication.getInstance().isNetworkActive()) {
|
|
|
if (iSelectAim != null)
|
|
|
iSelectAim.showToast(R.string.networks_out, R.color.load_error);
|
|
|
@@ -159,18 +150,19 @@ public class SelectAimPresenter implements HttpHandler.OnResultListener {
|
|
|
|
|
|
//下载附近数据
|
|
|
private void loadNeer() {
|
|
|
- BaiduMapUtil.getInstence().getNearInfo(200, 0, locationHelper.getLocation(), listener);
|
|
|
+ seachMapType = 1;
|
|
|
+ BaiduMapUtil.getInstence().getNearInfo(200, 0, MyApplication.getInstance().getBdLocationHelper().getLocation(), listener);
|
|
|
}
|
|
|
|
|
|
//下载全国数据
|
|
|
private void loadDataByChina() {
|
|
|
- seachChina = true;
|
|
|
+ seachMapType = 2;
|
|
|
BaiduMapUtil.getInstence().searchByInputOnChina(StringUtils.isEmpty(keyWork) ? "" : keyWork, 0, listener);
|
|
|
}
|
|
|
|
|
|
//下载本城市数据
|
|
|
private void loadDataByCity() {
|
|
|
- seachChina = false;
|
|
|
+ seachMapType = 3;
|
|
|
BaiduMapUtil.getInstence().searchByInput(StringUtils.isEmpty(keyWork) ? "" : keyWork, 0, listener);
|
|
|
}
|
|
|
|
|
|
@@ -178,49 +170,42 @@ public class SelectAimPresenter implements HttpHandler.OnResultListener {
|
|
|
@Override
|
|
|
public void result(SearchResult result) {
|
|
|
if (StringUtils.isEmpty(keyWork) && !ListUtils.isEmpty(models)) {
|
|
|
+ for (SelectAimModel e : models)
|
|
|
+ e.setFirst(false);
|
|
|
iSelectAim.showModel(models);
|
|
|
return;
|
|
|
}
|
|
|
- if (result == null) {
|
|
|
- if (seachChina) {
|
|
|
+ if (result == null || ListUtils.isEmpty(((PoiResult) result).getAllPoi())) {
|
|
|
+ if (seachMapType == 1) {
|
|
|
+ loadDataByChina();
|
|
|
+ return;
|
|
|
+ } else if (seachMapType == 2) {
|
|
|
loadDataByCity();
|
|
|
return;
|
|
|
} else {
|
|
|
showEmpty();
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
- PoiResult poiResult = (PoiResult) result;
|
|
|
- List<PoiInfo> chches = poiResult.getAllPoi();
|
|
|
- if (ListUtils.isEmpty(chches)) {
|
|
|
- if (seachChina) {
|
|
|
- loadDataByCity();
|
|
|
return;
|
|
|
- } else {//搜索城市为空数据
|
|
|
- showEmpty();
|
|
|
}
|
|
|
} else {
|
|
|
List<SelectAimModel> models = new ArrayList<>();
|
|
|
SelectAimModel model = null;
|
|
|
boolean isFirst = true;
|
|
|
+ List<PoiInfo> chches = ((PoiResult) result).getAllPoi();
|
|
|
for (int i = 0; i < chches.size(); i++) {
|
|
|
- if (StringUtils.isEmpty(chches.get(i).name) || StringUtils.isEmpty(chches.get(i).address)) {
|
|
|
- chches.remove(i);
|
|
|
- i--;
|
|
|
+ if (StringUtils.isEmpty(chches.get(i).name) || StringUtils.isEmpty(chches.get(i).address))
|
|
|
+ continue;
|
|
|
+ model = new SelectAimModel();
|
|
|
+ model.setType(3);
|
|
|
+ model.setName(chches.get(i).name);
|
|
|
+ model.setAddress(chches.get(i).address);
|
|
|
+ model.setLatLng(chches.get(i).location);
|
|
|
+ if (isFirst) {
|
|
|
+ model.setFirst(true);
|
|
|
+ isFirst = false;
|
|
|
} else {
|
|
|
- model = new SelectAimModel();
|
|
|
- model.setType(3);
|
|
|
- model.setName(chches.get(i).name);
|
|
|
- model.setAddress(chches.get(i).address);
|
|
|
- model.setLatLng(chches.get(i).location);
|
|
|
- if (isFirst) {
|
|
|
- model.setFirst(true);
|
|
|
- isFirst = false;
|
|
|
- } else {
|
|
|
- model.setFirst(false);
|
|
|
- }
|
|
|
- models.add(model);
|
|
|
+ model.setFirst(false);
|
|
|
}
|
|
|
+ models.add(model);
|
|
|
}
|
|
|
if (ListUtils.isEmpty(models)) {
|
|
|
showEmpty();
|
|
|
@@ -238,13 +223,13 @@ public class SelectAimPresenter implements HttpHandler.OnResultListener {
|
|
|
|
|
|
@Override
|
|
|
public void result(int what, boolean isJSON, String message, Bundle bundle) {
|
|
|
- if (what == LOAD && isJSON) {
|
|
|
- JSONArray array = JSON.parseObject(message).getJSONArray("data");
|
|
|
- handleDada(array);
|
|
|
- } else if (what == LOAD_CUSTOMER) {
|
|
|
- JSONArray array = JSON.parseObject(message).getJSONArray("customers");
|
|
|
- handleDadaForCustomer(array);
|
|
|
-
|
|
|
+ if (isJSON && (what == LOAD || what == LOAD_CUSTOMER)) {
|
|
|
+ JSONArray array = JSON.parseObject(message).getJSONArray(what == LOAD ? "data" : "customers");
|
|
|
+ if (what == LOAD) {
|
|
|
+ handleDada(array);
|
|
|
+ } else {
|
|
|
+ handleDadaForCustomer(array);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -265,14 +250,12 @@ public class SelectAimPresenter implements HttpHandler.OnResultListener {
|
|
|
}
|
|
|
SelectAimModel model = null;
|
|
|
JSONObject object = null;
|
|
|
-
|
|
|
String company = isB2b ? "company" : "MD_COMPANY";
|
|
|
String address = isB2b ? "md_address" : "MD_ADDRESS";
|
|
|
String md_latitude = isB2b ? "md_latitude" : "MD_LATITUDE";
|
|
|
String md_longitude = isB2b ? "md_longitude" : "MD_LONGITUDE";
|
|
|
String md_visitcount = isB2b ? "md_visitcount" : "MD_VISITCOUNT";
|
|
|
String md_visittime = isB2b ? "md_visittime" : "MD_VISITTIME";
|
|
|
-
|
|
|
List<SelectAimModel> models = new ArrayList<>();
|
|
|
for (int i = 0; i < array.size(); i++) {
|
|
|
try {
|
|
|
@@ -345,16 +328,11 @@ public class SelectAimPresenter implements HttpHandler.OnResultListener {
|
|
|
}
|
|
|
|
|
|
private void showEmpty() {
|
|
|
- List<SelectAimModel> models = new ArrayList<>();
|
|
|
- SelectAimModel model = new SelectAimModel();
|
|
|
- model.setType(1);
|
|
|
- models.add(model);
|
|
|
if (!StringUtils.isEmpty(keyWork)) {//有搜索
|
|
|
if (keyList == null || hasEmpty(keyList)) {
|
|
|
keyList = new ArrayList<>();
|
|
|
}
|
|
|
- if (ListUtils.isEmpty(keyList))
|
|
|
- keyList.addAll(models);
|
|
|
+
|
|
|
show(keyList);
|
|
|
} else
|
|
|
show(models);
|