1
This commit is contained in:
361
app/src/main/java/com/sl/house_property/BindHouseDialog.java
Normal file
361
app/src/main/java/com/sl/house_property/BindHouseDialog.java
Normal file
@@ -0,0 +1,361 @@
|
||||
package com.sl.house_property;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.internal.LinkedTreeMap;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.lxj.xpopup.core.CenterPopupView;
|
||||
import com.selectpicker.OptionsPopupWindow;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import entity.MyHomequEntity;
|
||||
import http.ApiConfig;
|
||||
import my_loader.Loader;
|
||||
import my_loader.Resultcode;
|
||||
import rx.functions.Action1;
|
||||
import utils.Md5;
|
||||
|
||||
public class BindHouseDialog extends CenterPopupView {
|
||||
|
||||
private TextView tvQu;
|
||||
private TextView tvLou;
|
||||
private TextView tvDan;
|
||||
private TextView tvFang;
|
||||
private EditText etName;
|
||||
private EditText etCardNumber;
|
||||
private String userId = "";
|
||||
Loader mGankLoader = new Loader();
|
||||
public ProgressDialog progressDialog;
|
||||
private MyHomequEntity mQu = null;
|
||||
private MyHomequEntity mLou = null;
|
||||
private MyHomequEntity mDan = null;
|
||||
private MyHomequEntity mFang = null;
|
||||
private OnBindHouseListener listener;
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public BindHouseDialog(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getImplLayoutId() {
|
||||
return R.layout.dialog_bind_house;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate() {
|
||||
super.onCreate();
|
||||
progressDialog = new ProgressDialog(getContext());
|
||||
tvQu = findViewById(R.id.tv_qu);
|
||||
tvLou = findViewById(R.id.lou);
|
||||
tvDan = findViewById(R.id.dan);
|
||||
tvFang = findViewById(R.id.fang);
|
||||
etName = findViewById(R.id.et_name);
|
||||
etCardNumber = findViewById(R.id.et_cardNumber);
|
||||
findViewById(R.id.ll_qu).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("userid", userId);
|
||||
map.put("app", "Trend");
|
||||
map.put("class", "GetHomeByPid");
|
||||
//map.put("home_id", "GetHomeByPid");
|
||||
map.put("sign", Md5.md5("Trend" + "GetHomeByPid" + Md5.secret));
|
||||
getGankList(ApiConfig.BASE_URL, map, 1);
|
||||
}
|
||||
});
|
||||
findViewById(R.id.ll_lou).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mQu == null) {
|
||||
Toast.makeText(getContext(), "请选择小区", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("userid", userId);
|
||||
map.put("app", "Trend");
|
||||
map.put("class", "GetHomeByPid");
|
||||
map.put("home_id", mQu.getHome_id());
|
||||
//map.put("home_id", "GetHomeByPid");
|
||||
map.put("sign", Md5.md5("Trend" + "GetHomeByPid" + Md5.secret));
|
||||
getGankList(ApiConfig.BASE_URL, map, 2);
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
findViewById(R.id.ll_dan).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mQu == null) {
|
||||
Toast.makeText(getContext(), "请选择小区", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (mLou == null) {
|
||||
Toast.makeText(getContext(), "请选择楼号", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("userid", userId);
|
||||
map.put("app", "Trend");
|
||||
map.put("class", "GetHomeByPid");
|
||||
map.put("home_id", mLou.getHome_id());
|
||||
//map.put("home_id", "GetHomeByPid");
|
||||
map.put("sign", Md5.md5("Trend" + "GetHomeByPid" + Md5.secret));
|
||||
getGankList(ApiConfig.BASE_URL, map, 3);
|
||||
}
|
||||
});
|
||||
findViewById(R.id.ll_fang).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mQu == null) {
|
||||
Toast.makeText(getContext(), "请选择小区", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (mLou == null) {
|
||||
Toast.makeText(getContext(), "请选择楼号", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (mDan == null) {
|
||||
Toast.makeText(getContext(), "请选择单元", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("userid", userId);
|
||||
map.put("app", "Trend");
|
||||
map.put("class", "GetHomeByPid");
|
||||
map.put("home_id", mDan.getHome_id());
|
||||
//map.put("home_id", "GetHomeByPid");
|
||||
map.put("sign", Md5.md5("Trend" + "GetHomeByPid" + Md5.secret));
|
||||
getGankList(ApiConfig.BASE_URL, map, 4);
|
||||
}
|
||||
});
|
||||
findViewById(R.id.tv_submit).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mQu == null) {
|
||||
Toast.makeText(getContext(), "请选择小区", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (mLou == null) {
|
||||
Toast.makeText(getContext(), "请选择楼号", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (mDan == null) {
|
||||
Toast.makeText(getContext(), "请选择单元", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (mFang == null) {
|
||||
Toast.makeText(getContext(), "请选择单元", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
String name = etName.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(name)) {
|
||||
Toast.makeText(getContext(), "请输入户主姓名", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
String cardNumber = etCardNumber.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(cardNumber)) {
|
||||
Toast.makeText(getContext(), "请输入身份证号", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("userid", userId);
|
||||
map.put("app", "Cas");
|
||||
map.put("class", "AddMyHouse");
|
||||
map.put("home_id", mFang.getHome_id());
|
||||
map.put("relname", name);
|
||||
map.put("idcard", cardNumber);
|
||||
//map.put("home_id", "GetHomeByPid");
|
||||
map.put("sign", Md5.md5("Cas" + "AddMyHouse" + Md5.secret));
|
||||
getGankList(ApiConfig.BASE_URL, map, 5);
|
||||
}
|
||||
});
|
||||
findViewById(R.id.tv_cancel).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void getGankList(String myurl, Map<String, String> map, final int requstecode) {
|
||||
mGankLoader.getMovie(myurl, map).subscribe(new Action1<Resultcode>() {
|
||||
@Override
|
||||
public void call(Resultcode resultcode) {
|
||||
progressDialog.dismiss();
|
||||
|
||||
if (!(resultcode.status == 0)) {
|
||||
Toast.makeText(getContext(), resultcode.msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
if (resultcode.status == 0) {
|
||||
if (requstecode == 1) {
|
||||
//选择区
|
||||
Gson gs = new Gson();
|
||||
ArrayList<LinkedTreeMap> adta = (ArrayList<LinkedTreeMap>) resultcode.data;
|
||||
String s = gs.toJson(adta);
|
||||
//final ArrayList<MyHomequEntity> list = null;
|
||||
Type type = new TypeToken<ArrayList<MyHomequEntity>>() {
|
||||
}.getType();
|
||||
final ArrayList<MyHomequEntity> list = new Gson().fromJson(s, type);
|
||||
final ArrayList<String> strings = new ArrayList<>();
|
||||
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
strings.add(list.get(i).getHome_name());
|
||||
}
|
||||
OptionsPopupWindow alarmOptionPop = new OptionsPopupWindow(getContext());
|
||||
alarmOptionPop.setPicker(strings);
|
||||
|
||||
alarmOptionPop.setOnoptionsSelectListener(new OptionsPopupWindow.OnOptionsSelectListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(int position, int option2, int options3) {
|
||||
mQu = list.get(position);
|
||||
tvQu.setText(mQu.getHome_name());
|
||||
mLou = null;
|
||||
tvLou.setText("请选择楼号");
|
||||
mDan = null;
|
||||
tvDan.setText("请选择单元");
|
||||
mFang = null;
|
||||
tvFang.setText("请选择房号");
|
||||
}
|
||||
});
|
||||
|
||||
alarmOptionPop.showAtLocation(getRootView(), Gravity.BOTTOM, 0, 0);
|
||||
|
||||
} else if (requstecode == 2) {
|
||||
//选择楼
|
||||
Gson gs = new Gson();
|
||||
ArrayList<LinkedTreeMap> adta = (ArrayList<LinkedTreeMap>) resultcode.data;
|
||||
String s = gs.toJson(adta);
|
||||
//final ArrayList<MyHomequEntity> list = null;
|
||||
Type type = new TypeToken<ArrayList<MyHomequEntity>>() {
|
||||
}.getType();
|
||||
final ArrayList<MyHomequEntity> list = new Gson().fromJson(s, type);
|
||||
final ArrayList<String> strings = new ArrayList<>();
|
||||
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
strings.add(list.get(i).getHome_name());
|
||||
}
|
||||
OptionsPopupWindow alarmOptionPop = new OptionsPopupWindow(getContext());
|
||||
alarmOptionPop.setPicker(strings);
|
||||
|
||||
alarmOptionPop.setOnoptionsSelectListener(new OptionsPopupWindow.OnOptionsSelectListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(int position, int option2, int options3) {
|
||||
mLou = list.get(position);
|
||||
tvLou.setText(mLou.getHome_name());
|
||||
|
||||
mDan = null;
|
||||
tvDan.setText("请选择单元");
|
||||
mFang = null;
|
||||
tvFang.setText("请选择房号");
|
||||
}
|
||||
});
|
||||
|
||||
alarmOptionPop.showAtLocation(getRootView(), Gravity.BOTTOM, 0, 0);
|
||||
} else if (requstecode == 3) {
|
||||
//选择单元
|
||||
Gson gs = new Gson();
|
||||
ArrayList<LinkedTreeMap> adta = (ArrayList<LinkedTreeMap>) resultcode.data;
|
||||
String s = gs.toJson(adta);
|
||||
//final ArrayList<MyHomequEntity> list = null;
|
||||
Type type = new TypeToken<ArrayList<MyHomequEntity>>() {
|
||||
}.getType();
|
||||
final ArrayList<MyHomequEntity> list = new Gson().fromJson(s, type);
|
||||
final ArrayList<String> strings = new ArrayList<>();
|
||||
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
strings.add(list.get(i).getHome_name());
|
||||
}
|
||||
OptionsPopupWindow alarmOptionPop = new OptionsPopupWindow(getContext());
|
||||
alarmOptionPop.setPicker(strings);
|
||||
|
||||
alarmOptionPop.setOnoptionsSelectListener(new OptionsPopupWindow.OnOptionsSelectListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(int position, int option2, int options3) {
|
||||
mDan = list.get(position);
|
||||
tvDan.setText(mDan.getHome_name());
|
||||
|
||||
mFang = null;
|
||||
tvFang.setText("请选择房号");
|
||||
}
|
||||
});
|
||||
|
||||
alarmOptionPop.showAtLocation(getRootView(), Gravity.BOTTOM, 0, 0);
|
||||
} else if (requstecode == 4) {
|
||||
//选择房号
|
||||
Gson gs = new Gson();
|
||||
ArrayList<LinkedTreeMap> adta = (ArrayList<LinkedTreeMap>) resultcode.data;
|
||||
String s = gs.toJson(adta);
|
||||
//final ArrayList<MyHomequEntity> list = null;
|
||||
Type type = new TypeToken<ArrayList<MyHomequEntity>>() {
|
||||
}.getType();
|
||||
final ArrayList<MyHomequEntity> list = new Gson().fromJson(s, type);
|
||||
final ArrayList<String> strings = new ArrayList<>();
|
||||
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
strings.add(list.get(i).getHome_name());
|
||||
}
|
||||
OptionsPopupWindow alarmOptionPop = new OptionsPopupWindow(getContext());
|
||||
alarmOptionPop.setPicker(strings);
|
||||
|
||||
alarmOptionPop.setOnoptionsSelectListener(new OptionsPopupWindow.OnOptionsSelectListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(int position, int option2, int options3) {
|
||||
mFang = list.get(position);
|
||||
tvFang.setText(mFang.getHome_name());
|
||||
}
|
||||
});
|
||||
|
||||
alarmOptionPop.showAtLocation(getRootView(), Gravity.BOTTOM, 0, 0);
|
||||
} else if (requstecode == 5) {
|
||||
if (listener != null) {
|
||||
listener.onSubmit();
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}, new Action1<Throwable>() {
|
||||
@Override
|
||||
public void call(Throwable throwable) {
|
||||
progressDialog.dismiss();
|
||||
Toast.makeText(getContext(), getContext().getString(R.string.getdatafailure), Toast.LENGTH_SHORT).show();
|
||||
// setToast(getString(R.string.getdatafailure));
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setOnBindHouseListener(OnBindHouseListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
interface OnBindHouseListener {
|
||||
void onSubmit();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user