|
|
@@ -1,5 +1,7 @@
|
|
|
package com.android.chmo.ui.fragment;
|
|
|
|
|
|
+import android.app.AlertDialog;
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.support.v4.app.Fragment;
|
|
|
import android.support.v4.app.FragmentManager;
|
|
|
import android.support.v4.app.FragmentPagerAdapter;
|
|
|
@@ -10,6 +12,8 @@ import android.widget.TextView;
|
|
|
|
|
|
import com.android.chmo.R;
|
|
|
import com.android.chmo.base.BaseFragment;
|
|
|
+import com.android.chmo.http.RequestCallback;
|
|
|
+import com.android.chmo.http.service.ModelService;
|
|
|
import com.android.chmo.ui.activity.model.SearchModelActivity;
|
|
|
import com.android.chmo.ui.dialog.SelectDialog;
|
|
|
import com.android.chmo.ui.fragment.home.ActivitiesFragment;
|
|
|
@@ -20,6 +24,12 @@ import com.android.chmo.utils.CommonUtils;
|
|
|
import com.android.chmo.utils.PixelUtils;
|
|
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
+import org.json.JSONArray;
|
|
|
+import org.json.JSONException;
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
import butterknife.OnClick;
|
|
|
@@ -127,13 +137,42 @@ public class HomeFragment extends BaseFragment {
|
|
|
|
|
|
@OnClick(R.id.tv_city)
|
|
|
void clickCity() {
|
|
|
- String[] strs = new String[]{"全国", "烟台"};
|
|
|
- new SelectDialog(getContext())
|
|
|
- .setItems(strs)
|
|
|
- .setItemListener(pos -> {
|
|
|
- tvCity.setText(strs[pos]);
|
|
|
- EventBus.getDefault().post("chooseCity" + strs[pos]);
|
|
|
- }).show();
|
|
|
+ ModelService.getArea(new RequestCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(String result) {
|
|
|
+ try {
|
|
|
+ JSONObject jsonObject = new JSONObject(result);
|
|
|
+ if (jsonObject.getString("msg").equals("success")) {
|
|
|
+ JSONArray array = jsonObject.getJSONArray("data");
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ list.add("全国");
|
|
|
+ for (int i = 0; i < array.length(); i++) {
|
|
|
+ list.add(array.getJSONObject(i).getString("name"));
|
|
|
+ }
|
|
|
+
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(getContext(), 0);
|
|
|
+ builder.setTitle("选择城市");
|
|
|
+ builder.setIcon(R.mipmap.ic_launcher);
|
|
|
+ builder.setSingleChoiceItems(list.toArray(new String[0]), 0,
|
|
|
+ (dialog, which) -> {
|
|
|
+ tvCity.setText(list.get(which));
|
|
|
+ EventBus.getDefault().post("chooseCity" + list.get(which));
|
|
|
+ dialog.dismiss();
|
|
|
+ });
|
|
|
+ builder.create().show();
|
|
|
+ }
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailure(String error) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void changeTab() {
|