|
@@ -12,9 +12,13 @@ import android.widget.ListView;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import com.common.library.cache.Cache;
|
|
|
+import com.common.library.okhttp.callback.Callback;
|
|
|
+import com.google.gson.Gson;
|
|
|
import com.ynstkz.shitu.android.R;
|
|
|
import com.ynstkz.shitu.android.adapter.HistoryCityGridAdapter;
|
|
|
import com.ynstkz.shitu.android.base.TitleBarActivity;
|
|
|
+import com.ynstkz.shitu.android.bean.LocalCityBean;
|
|
|
+import com.ynstkz.shitu.android.data.RequestGroup;
|
|
|
import com.ynstkz.shitu.android.data.SharedPreferencesUtils;
|
|
|
import com.ynstkz.shitu.android.view.sortlist.CharacterParser;
|
|
|
import com.ynstkz.shitu.android.view.sortlist.PinyinComparator;
|
|
@@ -27,6 +31,8 @@ import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
|
|
|
import butterknife.Bind;
|
|
|
+import okhttp3.Call;
|
|
|
+import okhttp3.Response;
|
|
|
|
|
|
/**
|
|
|
* 作者:fuchangle on 2018/2/9 11:26
|
|
@@ -78,7 +84,7 @@ public class LocationSelectActivity extends TitleBarActivity {
|
|
|
}
|
|
|
|
|
|
private void initData() {
|
|
|
-
|
|
|
+ //历史选择
|
|
|
Cache<List<String>> cacheHistoryCity = new Cache<>();
|
|
|
listCacheHistoryCity = cacheHistoryCity.get(KRY_LISTCACHEHISTORYCITY);
|
|
|
if(listCacheHistoryCity != null && listCacheHistoryCity.size() > 0){
|
|
@@ -88,11 +94,9 @@ public class LocationSelectActivity extends TitleBarActivity {
|
|
|
} else {
|
|
|
gvHistoryCity.setVisibility(View.GONE);
|
|
|
}
|
|
|
- sourceDateList = filledData(getResources().getStringArray(R.array.citys));
|
|
|
- // 根据a-z进行排序源数据
|
|
|
- Collections.sort(sourceDateList, pinyinComparator);
|
|
|
- sortAdapter = new SortAdapter(this, sourceDateList);
|
|
|
- lvCountry.setAdapter(sortAdapter);
|
|
|
+
|
|
|
+ //城市排序
|
|
|
+ getLocalCityList();
|
|
|
}
|
|
|
|
|
|
private void setListener() {
|
|
@@ -146,20 +150,65 @@ public class LocationSelectActivity extends TitleBarActivity {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取定位列表
|
|
|
+ */
|
|
|
+ private void getLocalCityList(){
|
|
|
+
|
|
|
+ RequestGroup.getLocalCity(new Callback() {
|
|
|
+ @Override
|
|
|
+ public Object parseNetworkResponse(Response response, int id) throws Exception {
|
|
|
+ return new Gson().fromJson(response.body().string(), LocalCityBean.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(Call call, Exception e, int id) {
|
|
|
+ showToast(getString(R.string.error_msg));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(Object response, int id) {
|
|
|
+ LocalCityBean localCityBean = (LocalCityBean)response;
|
|
|
+ if(localCityBean != null){
|
|
|
+ if("200".equals(localCityBean.getCode())){
|
|
|
+ if(localCityBean.getData() != null){
|
|
|
+ List<LocalCityBean.DataBean> dataBean = localCityBean.getData();
|
|
|
+ if(dataBean != null && dataBean.size() > 0){
|
|
|
+ List<String> cityNames = new ArrayList<>();
|
|
|
+ for(int i=0; i<dataBean.size(); i++){
|
|
|
+ String regionName = dataBean.get(i).getRegionName();
|
|
|
+ cityNames.add(regionName);
|
|
|
+ }
|
|
|
+ sourceDateList = filledData(cityNames);
|
|
|
+ // 根据a-z进行排序源数据
|
|
|
+ Collections.sort(sourceDateList, pinyinComparator);
|
|
|
+ sortAdapter = new SortAdapter(LocationSelectActivity.this, sourceDateList);
|
|
|
+ lvCountry.setAdapter(sortAdapter);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ showToast(localCityBean.getMsg());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 为ListView填充数据
|
|
|
*
|
|
|
* @param date
|
|
|
* @return
|
|
|
*/
|
|
|
- private List<SortModel> filledData(String[] date) {
|
|
|
+ private List<SortModel> filledData(List<String> date) {
|
|
|
List<SortModel> mSortList = new ArrayList<SortModel>();
|
|
|
|
|
|
- for (int i = 0; i < date.length; i++) {
|
|
|
+ for (int i = 0; i < date.size(); i++) {
|
|
|
SortModel sortModel = new SortModel();
|
|
|
- sortModel.setName(date[i]);
|
|
|
+ sortModel.setName(date.get(i));
|
|
|
//汉字转换成拼音
|
|
|
- String pinyin = characterParser.getSelling(date[i]);
|
|
|
+ String pinyin = characterParser.getSelling(date.get(i));
|
|
|
String sortString = pinyin.substring(0, 1).toUpperCase();
|
|
|
|
|
|
// 正则表达式,判断首字母是否是英文字母
|
|
@@ -182,7 +231,9 @@ public class LocationSelectActivity extends TitleBarActivity {
|
|
|
if(listCacheHistoryCity == null){
|
|
|
listCacheHistoryCity = new ArrayList<>();
|
|
|
}
|
|
|
- listCacheHistoryCity.add(0, city);
|
|
|
+ if(!listCacheHistoryCity.contains(city)){
|
|
|
+ listCacheHistoryCity.add(0, city);
|
|
|
+ }
|
|
|
if(listCacheHistoryCity.size() > 4){
|
|
|
listCacheHistoryCity.remove(4);
|
|
|
}
|