|
@@ -15,6 +15,13 @@ import android.widget.LinearLayout;
|
|
|
import android.widget.ListView;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+import com.amap.api.services.core.LatLonPoint;
|
|
|
+import com.amap.api.services.geocoder.GeocodeAddress;
|
|
|
+import com.amap.api.services.geocoder.GeocodeQuery;
|
|
|
+import com.amap.api.services.geocoder.GeocodeResult;
|
|
|
+import com.amap.api.services.geocoder.GeocodeSearch;
|
|
|
+import com.amap.api.services.geocoder.RegeocodeResult;
|
|
|
+import com.common.library.cache.Cache;
|
|
|
import com.common.library.okhttp.callback.Callback;
|
|
|
import com.common.library.pulltorefresh.PullToRefreshBase;
|
|
|
import com.common.library.pulltorefresh.PullToRefreshListView;
|
|
@@ -25,11 +32,13 @@ import com.ynstkz.shitu.android.activity.OrgDetailActivity;
|
|
|
import com.ynstkz.shitu.android.activity.OrgListActivity;
|
|
|
import com.ynstkz.shitu.android.adapter.OrgFilterListAdapter;
|
|
|
import com.ynstkz.shitu.android.adapter.OrgListAdapter;
|
|
|
+import com.ynstkz.shitu.android.adapter.OrgNavigationGridAdapter;
|
|
|
import com.ynstkz.shitu.android.application.STSign;
|
|
|
import com.ynstkz.shitu.android.base.BaseFragment;
|
|
|
import com.ynstkz.shitu.android.bean.LocationDataBean;
|
|
|
import com.ynstkz.shitu.android.bean.OrgItemBean;
|
|
|
import com.ynstkz.shitu.android.bean.OrgListBean;
|
|
|
+import com.ynstkz.shitu.android.bean.OrgNavigationBean;
|
|
|
import com.ynstkz.shitu.android.common.Constants;
|
|
|
import com.ynstkz.shitu.android.data.RequestGroup;
|
|
|
import com.ynstkz.shitu.android.data.SharedPreferencesUtils;
|
|
@@ -53,7 +62,8 @@ import okhttp3.Response;
|
|
|
* 作者:fuchangle on 2018/1/29 11:43
|
|
|
*/
|
|
|
|
|
|
-public class OrgListFragment extends BaseFragment implements PullToRefreshBase.OnRefreshListener2<ListView> {
|
|
|
+public class OrgListFragment extends BaseFragment implements PullToRefreshBase.OnRefreshListener2<ListView>,
|
|
|
+ GeocodeSearch.OnGeocodeSearchListener {
|
|
|
|
|
|
@Bind(R.id.tv_location)
|
|
|
TextView tvLocation;
|
|
@@ -79,6 +89,12 @@ public class OrgListFragment extends BaseFragment implements PullToRefreshBase.O
|
|
|
EditText editSearch;
|
|
|
@Bind(R.id.ll_phone_server)
|
|
|
LinearLayout llPhoneServer;
|
|
|
+ @Bind(R.id.tv_filter_location)
|
|
|
+ TextView tvFilterLocation;
|
|
|
+ @Bind(R.id.tv_filter_org)
|
|
|
+ TextView tvFilterOrg;
|
|
|
+ @Bind(R.id.tv_filter_order)
|
|
|
+ TextView tvFilterOrder;
|
|
|
|
|
|
private int pageNumber;
|
|
|
private List<OrgItemBean> listOrg;
|
|
@@ -89,6 +105,8 @@ public class OrgListFragment extends BaseFragment implements PullToRefreshBase.O
|
|
|
private String sortType;
|
|
|
|
|
|
private String agencyTypeId;
|
|
|
+ private int filterIndex;
|
|
|
+ private OrgNavigationBean orgNavigationBean;
|
|
|
|
|
|
@Override
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
@@ -131,6 +149,7 @@ public class OrgListFragment extends BaseFragment implements PullToRefreshBase.O
|
|
|
llFilterNearby.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
+ filterIndex = 1;
|
|
|
llFilterContent.setVisibility(View.VISIBLE);
|
|
|
List<String> orgFilterLocation = Arrays.asList(getResources().getStringArray(R.array.org_filter_location));
|
|
|
showFilterContent(orgFilterLocation);
|
|
@@ -141,9 +160,21 @@ public class OrgListFragment extends BaseFragment implements PullToRefreshBase.O
|
|
|
llFilterOrg.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
- llFilterContent.setVisibility(View.VISIBLE);
|
|
|
- List<String> orgFilterLocation = Arrays.asList(getResources().getStringArray(R.array.org_filter_org));
|
|
|
- showFilterContent(orgFilterLocation);
|
|
|
+ filterIndex = 2;
|
|
|
+ Cache<OrgNavigationBean> cache = new Cache();
|
|
|
+ OrgNavigationBean orgNavigationBean = cache.get("OrgNavigationBean");
|
|
|
+ if(orgNavigationBean != null && "200".equals(orgNavigationBean.getCode())){
|
|
|
+ llFilterContent.setVisibility(View.VISIBLE);
|
|
|
+ OrgListFragment.this.orgNavigationBean = orgNavigationBean;
|
|
|
+ if(orgNavigationBean.getData() != null && orgNavigationBean.getData().size() > 0){
|
|
|
+ List<String> orgFilterLocation = new ArrayList<>();
|
|
|
+ for(int i=0; i<orgNavigationBean.getData().size(); i++){
|
|
|
+ String orgName = orgNavigationBean.getData().get(i).getTitle();
|
|
|
+ orgFilterLocation.add(orgName);
|
|
|
+ }
|
|
|
+ showFilterContent(orgFilterLocation);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -151,6 +182,7 @@ public class OrgListFragment extends BaseFragment implements PullToRefreshBase.O
|
|
|
llFilterOrder.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
+ filterIndex = 3;
|
|
|
llFilterContent.setVisibility(View.VISIBLE);
|
|
|
List<String> orgFilterLocation = Arrays.asList(getResources().getStringArray(R.array.org_filter_order));
|
|
|
showFilterContent(orgFilterLocation);
|
|
@@ -201,6 +233,44 @@ public class OrgListFragment extends BaseFragment implements PullToRefreshBase.O
|
|
|
STSign.getInstance().openPhoneServer(getActivity());
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 选择城市
|
|
|
+ */
|
|
|
+ lvFilterContent.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
|
+ String content = (String) adapterView.getAdapter().getItem(i);
|
|
|
+ if(filterIndex == 1) {
|
|
|
+ getAmapGeocode(content);
|
|
|
+ tvFilterLocation.setText(content);
|
|
|
+ } else if (filterIndex == 2){
|
|
|
+ tvFilterOrg.setText(content);
|
|
|
+ if(orgNavigationBean != null){
|
|
|
+ if(orgNavigationBean.getData() != null && orgNavigationBean.getData().size() > 0){
|
|
|
+ for(int j=0; j<orgNavigationBean.getData().size(); j++){
|
|
|
+ String orgName = orgNavigationBean.getData().get(j).getTitle();
|
|
|
+ if(content.equals(orgName)){
|
|
|
+ agencyTypeId = orgNavigationBean.getData().get(j).getTypeId();
|
|
|
+ getOrgList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (filterIndex == 3){
|
|
|
+ tvFilterOrder.setText(content);
|
|
|
+ if(i == 0){
|
|
|
+ sortType = "1";
|
|
|
+ } else if (i == 1) {
|
|
|
+ sortType = "2";
|
|
|
+ } else if (i == 2) {
|
|
|
+ sortType = "3";
|
|
|
+ }
|
|
|
+ getOrgList();
|
|
|
+ }
|
|
|
+ llFilterContent.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -220,7 +290,7 @@ public class OrgListFragment extends BaseFragment implements PullToRefreshBase.O
|
|
|
*/
|
|
|
private void getOrgList() {
|
|
|
|
|
|
- RequestGroup.getNearbyAgencyList(pageNumber + "", longitude+"", latitude+"", agencyTypeId, sortType, "", new Callback() {
|
|
|
+ RequestGroup.getNearbyAgencyList(pageNumber + "", longitude + "", latitude + "", agencyTypeId, sortType, "", new Callback() {
|
|
|
@Override
|
|
|
public Object parseNetworkResponse(Response response, int id) throws Exception {
|
|
|
return new Gson().fromJson(response.body().string(), OrgListBean.class);
|
|
@@ -288,11 +358,42 @@ public class OrgListFragment extends BaseFragment implements PullToRefreshBase.O
|
|
|
llHomeTitle.setVisibility(visibility);
|
|
|
}
|
|
|
|
|
|
- public void setOrgFilterType(String agencyTypeId){
|
|
|
+ public void setOrgFilterType(String agencyTypeId) {
|
|
|
this.agencyTypeId = agencyTypeId;
|
|
|
getOrgList();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取城市经纬度
|
|
|
+ *
|
|
|
+ * @param address
|
|
|
+ */
|
|
|
+ private void getAmapGeocode(String address) {
|
|
|
+ GeocodeSearch geocodeSearch = new GeocodeSearch(getActivity());
|
|
|
+ geocodeSearch.setOnGeocodeSearchListener(this);
|
|
|
+
|
|
|
+ GeocodeQuery geocodeQuery = new GeocodeQuery(address, "");
|
|
|
+ geocodeSearch.getFromLocationNameAsyn(geocodeQuery);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {
|
|
|
+ List<GeocodeAddress> listGeocodeAddress = geocodeResult.getGeocodeAddressList();
|
|
|
+ if (listGeocodeAddress != null && listGeocodeAddress.size() > 0) {
|
|
|
+ GeocodeAddress geocodeAddress = listGeocodeAddress.get(0);
|
|
|
+ LatLonPoint latLonPoint = geocodeAddress.getLatLonPoint();
|
|
|
+ latitude = latLonPoint.getLatitude();
|
|
|
+ longitude = latLonPoint.getLongitude();
|
|
|
+ pageNumber = 1;
|
|
|
+ getOrgList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
public void onMessageEvent(LocationChangedEvent event) {
|
|
|
if (event.getLocationDataBean() != null) {
|
|
@@ -310,9 +411,9 @@ public class OrgListFragment extends BaseFragment implements PullToRefreshBase.O
|
|
|
|
|
|
@Override
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
- switch (requestCode){
|
|
|
+ switch (requestCode) {
|
|
|
case 20:
|
|
|
- if(resultCode == Activity.RESULT_OK) {
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
LocationDataBean locationDataBean = new LocationDataBean();
|
|
|
locationDataBean.setCity(data.getStringExtra("city"));
|
|
|
locationDataBean.setLatitude(data.getDoubleExtra("latitude", 0));
|