594 lines
20 KiB
Java
594 lines
20 KiB
Java
package cn.shangyu.gdxzExpert.activity;
|
||
|
||
import android.content.Context;
|
||
import android.content.Intent;
|
||
import android.text.TextUtils;
|
||
import android.view.KeyEvent;
|
||
import android.view.View;
|
||
import android.view.View.OnClickListener;
|
||
import android.view.ViewGroup;
|
||
import android.view.inputmethod.EditorInfo;
|
||
import android.view.inputmethod.InputMethodManager;
|
||
import android.widget.AdapterView;
|
||
import android.widget.AdapterView.OnItemClickListener;
|
||
import android.widget.BaseAdapter;
|
||
import android.widget.CheckBox;
|
||
import android.widget.EditText;
|
||
import android.widget.FrameLayout.LayoutParams;
|
||
import android.widget.ImageView;
|
||
import android.widget.ListView;
|
||
import android.widget.TextView;
|
||
|
||
import com.gyf.immersionbar.ImmersionBar;
|
||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.LinkedHashSet;
|
||
import java.util.List;
|
||
import java.util.Set;
|
||
|
||
import cn.shangyu.gdxzExpert.R;
|
||
import cn.shangyu.gdxzExpert.activity.GroupChatSelectPatientActivity.PatientAdapter.ViewHolder;
|
||
import cn.shangyu.gdxzExpert.base.BaseActivity;
|
||
import cn.shangyu.gdxzExpert.ecdemo.storage.PatientSqlManager;
|
||
import cn.shangyu.gdxzExpert.ecdemo.ui.chatting.model.PatientModel;
|
||
import cn.shangyu.gdxzExpert.utils.CommonUtil;
|
||
import cn.shangyu.gdxzExpert.utils.Constant;
|
||
import cn.shangyu.gdxzExpert.utils.ImageOptions;
|
||
import cn.shangyu.gdxzExpert.utils.LogUtil;
|
||
import cn.shangyu.gdxzExpert.utils.StringUtil;
|
||
import cn.shangyu.gdxzExpert.utils.ToastUtil;
|
||
import cn.shangyu.gdxzExpert.utils.UIUtils;
|
||
import cn.shangyu.gdxzExpert.utils.Url;
|
||
import cn.shangyu.gdxzExpert.widget.LoadingPage.ResultState;
|
||
|
||
/**
|
||
*
|
||
* @author ssy Copyright (C) 2015 河南商宇科技有限公司
|
||
*
|
||
* 功能说明:我的患者-群发消息-群发消息患者选择患者
|
||
*
|
||
*/
|
||
public class GroupChatSelectPatientActivity extends BaseActivity implements
|
||
OnItemClickListener {
|
||
|
||
public static int RESULTCODE_OK = 1;
|
||
private ListView lv_patient;
|
||
private TextView load_empty;
|
||
private int checkNum = 0;// 记录选中的条目数量
|
||
private ArrayList<PatientModel> list;
|
||
private String mobile = "";
|
||
private String name = "";
|
||
private String Patientuuid = "";
|
||
private CheckBox bt_all_list;
|
||
private PatientAdapter patientAdapter;
|
||
private EditText mEdittext;
|
||
private ArrayList<PatientModel> list1 = new ArrayList<>();//搜索结果集合
|
||
private ArrayList<PatientModel> list2 = new ArrayList<>();//选中结果集合
|
||
private int sendgroup;
|
||
private int sureCount;//确定上显示的个数
|
||
|
||
// 用于保存勾选的联系人
|
||
@Override
|
||
public void setTitle() {
|
||
// TODO Auto-generated method stub
|
||
top_title.setText("我的患者");
|
||
top_right_text.setVisibility(View.VISIBLE);
|
||
// top_right_text.setBackgroundResource(R.drawable.btn_style_brown);
|
||
// String actionBtn = getString(R.string.radar_ok_count,
|
||
// getString(R.string.dialog_ok_button) , 0);
|
||
// top_right_text.setText(actionBtn);
|
||
// top_right_text.setTextColor(0xffffff);
|
||
top_right_text.setTextColor(GroupChatSelectPatientActivity.this
|
||
.getResources().getColor(R.color.white));
|
||
top_right_text.setTextSize(14);
|
||
top_right_text.setBackgroundResource(R.drawable.btn_style_brown);
|
||
LayoutParams paras = (LayoutParams) top_right_text
|
||
.getLayoutParams();
|
||
paras.setMargins(0, 0, dip2px(GroupChatSelectPatientActivity.this, 10),
|
||
0);
|
||
paras.height = dip2px(GroupChatSelectPatientActivity.this, 30);
|
||
top_right_text.setLayoutParams(paras);
|
||
|
||
onContactClick(checkNum);
|
||
if(CommonUtil.BigModule())
|
||
{
|
||
top_title.setTextSize(23);
|
||
top_right_text.setTextSize(18);
|
||
}
|
||
|
||
}
|
||
|
||
// dp到像素的转换
|
||
public static int dip2px(Context context, double d) {
|
||
final float scale = context.getResources().getDisplayMetrics().density;
|
||
return (int) (d * scale + 0.5f);
|
||
}
|
||
|
||
// 设置联系人选择情况,动态变化选择的个数
|
||
public void onContactClick(int count) {
|
||
sureCount = count;
|
||
top_right_text.setEnabled(count > 0 ? true : false);
|
||
top_right_text.setText(getString(R.string.radar_ok_count,
|
||
getString(R.string.dialog_ok_button), count));
|
||
}
|
||
|
||
@Override
|
||
public View onCreateSuccessedView() {
|
||
ImmersionBar.with(this).keyboardEnable(true).statusBarDarkFont(true).titleBar(mToolbar).init();
|
||
View view;
|
||
if(CommonUtil.BigModule())
|
||
{
|
||
view = UIUtils.inflate(R.layout.activity_patient_contact_big);
|
||
}
|
||
else
|
||
{
|
||
view = UIUtils.inflate(R.layout.activity_patient_contact);
|
||
}
|
||
|
||
lv_patient = (ListView) view.findViewById(R.id.lv_patient_list);
|
||
mEdittext = (EditText) view.findViewById(R.id.search);
|
||
lv_patient.setOnItemClickListener(this);
|
||
// //处理正在加载,空,错误的布局
|
||
load_empty = (TextView) view.findViewById(R.id.load_empty);
|
||
// 全选全不选
|
||
bt_all_list = (CheckBox) view.findViewById(R.id.bt_all_list);
|
||
TextView mEmptyView = (TextView) view
|
||
.findViewById(R.id.load_empty);
|
||
mEmptyView.setText("暂无搜索结果");
|
||
lv_patient.setEmptyView(mEmptyView);
|
||
ImageView iv_search = view.findViewById(R.id.iv_search);
|
||
iv_search.setOnClickListener(new OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
|
||
String input=mEdittext.getText().toString().trim();
|
||
if (!TextUtils.isEmpty(input)) {
|
||
list1.clear();
|
||
if(list!=null)
|
||
{
|
||
for (int i = 0; i < list.size(); i++) {
|
||
String realName = list.get(i).getRealName();
|
||
String nickname = list.get(i).getNickName();
|
||
String mobile = list.get(i).getMobile();
|
||
if (!StringUtil.isEmpty(realName)&&realName.contains(input)) {
|
||
list1.add(list.get(i));
|
||
}else if (!StringUtil.isEmpty(nickname)&&nickname.contains(input)){
|
||
list1.add(list.get(i));
|
||
}else if (!StringUtil.isEmpty(mobile)&&mobile.contains(input)){
|
||
list1.add(list.get(i));
|
||
}
|
||
}
|
||
}
|
||
|
||
} else {
|
||
list1.clear();
|
||
list1.addAll(list);
|
||
}
|
||
if (patientAdapter == null) {
|
||
new PatientAdapter(ct, list1);
|
||
lv_patient.setAdapter(patientAdapter);
|
||
} else {
|
||
patientAdapter.notifyDataSetChanged();
|
||
}
|
||
hideKeyboard(mEdittext);
|
||
}
|
||
});
|
||
bt_all_list.setOnClickListener(new OnClickListener() {
|
||
|
||
@Override
|
||
public void onClick(View v) {
|
||
// TODO Auto-generated method stub
|
||
if (bt_all_list.isChecked()) {
|
||
// 全选
|
||
bt_all_list.setText("全不选");
|
||
// bt_all_list.setTextColor(getResources().getColor(R.color.text_color));
|
||
bt_all_list.setBackgroundResource(R.drawable.btn);
|
||
if(CommonUtil.BigModule())
|
||
{
|
||
bt_all_list.setText("取消全选");
|
||
}
|
||
selectAllContacts();
|
||
} else {
|
||
// 全不选
|
||
bt_all_list.setText("全选");
|
||
// bt_all_list.setTextColor(getResources().getColor(R.color.white));
|
||
// bt_all_list.setBackgroundResource(R.color.top_title);
|
||
bt_all_list.setBackgroundResource(R.drawable.btn);
|
||
invertSelection();
|
||
}
|
||
}
|
||
});
|
||
|
||
mEdittext.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||
@Override
|
||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||
if (actionId == EditorInfo.IME_ACTION_SEARCH){
|
||
String input=mEdittext.getText().toString().trim();
|
||
if (!TextUtils.isEmpty(input)) {
|
||
list1.clear();
|
||
for (int i = 0; i < list.size(); i++) {
|
||
String realName = list.get(i).getRealName();
|
||
String nickname = list.get(i).getNickName();
|
||
String mobile = list.get(i).getMobile();
|
||
if (!StringUtil.isEmpty(realName)&&realName.contains(input)) {
|
||
list1.add(list.get(i));
|
||
}else if (!StringUtil.isEmpty(nickname)&&nickname.contains(input)){
|
||
list1.add(list.get(i));
|
||
}else if (!StringUtil.isEmpty(mobile)&&mobile.contains(input)){
|
||
list1.add(list.get(i));
|
||
}
|
||
}
|
||
} else {
|
||
list1.clear();
|
||
list1.addAll(list);
|
||
}
|
||
if (patientAdapter == null) {
|
||
new PatientAdapter(ct, list1);
|
||
lv_patient.setAdapter(patientAdapter);
|
||
} else {
|
||
patientAdapter.notifyDataSetChanged();
|
||
}
|
||
hideKeyboard(mEdittext);
|
||
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
});
|
||
|
||
initData();
|
||
initIntent();
|
||
return view;
|
||
}
|
||
|
||
private void initIntent() {
|
||
Intent intent = getIntent();
|
||
sendgroup = intent.getIntExtra("sendgroup",0);
|
||
}
|
||
|
||
/**
|
||
* 隐藏软键盘
|
||
*
|
||
* @param :上下文环境,一般为Activity实例
|
||
* @param view :一般为EditText
|
||
*/
|
||
public static void hideKeyboard(View view) {
|
||
InputMethodManager manager = (InputMethodManager) view.getContext()
|
||
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||
manager.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||
}
|
||
private void initData() {
|
||
// TODO Auto-generated method stub
|
||
showProgressDialog("正在加载");
|
||
// 从患者数据库里取出患者列表
|
||
list = PatientSqlManager.getPatientInfoList(Constant.typePatient);
|
||
if (list != null) {
|
||
// 数据为空
|
||
if (list.size() == 0) {
|
||
load_empty.setVisibility(View.VISIBLE);
|
||
} else {
|
||
/*
|
||
* for (int i = 0; i < list.size(); i++) {
|
||
* LogUtil.i("数据库取出uuid=="
|
||
* +list.get(i).getUuid()+"name=="+list.get
|
||
* (i).getRealName()+"photo=="+list.get(i).getPhoto()); }
|
||
*/
|
||
load_empty.setVisibility(View.GONE);
|
||
list1.addAll(list);
|
||
// 设置适配器
|
||
// ***********************注意,这个adapter要抽出全局变量*************************
|
||
patientAdapter = new PatientAdapter(ct, list1);
|
||
// 初始化isSelected的数据 ,让所有都设置为未选中
|
||
// for (int i = 0; i < list.size(); i++) {
|
||
// PatientAdapter.getIsSelected().put(i, false);
|
||
// }
|
||
lv_patient.setAdapter(patientAdapter);
|
||
}
|
||
} else {
|
||
load_empty.setVisibility(View.VISIBLE);
|
||
}
|
||
closeProgressDialog();
|
||
}
|
||
|
||
@Override
|
||
public ResultState onLoad() {
|
||
// TODO Auto-generated method stub
|
||
return ResultState.STATE_SUCCESSED;
|
||
}
|
||
|
||
@Override
|
||
protected void processClick(View v) {
|
||
// TODO Auto-generated method stub
|
||
switch (v.getId()) {
|
||
case R.id.top_right_text:// 提交
|
||
submitOK();
|
||
break;
|
||
// case R.id.bt_all_list:
|
||
// break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 提交选中的患者 submitOK
|
||
*
|
||
* void
|
||
*/
|
||
private void submitOK() {
|
||
// TODO Auto-generated method stub
|
||
// if (list == null && list.size() == 0) {
|
||
// return;
|
||
// }
|
||
// for (int i = 0; i < list.size(); i++) {
|
||
// // 选中情况
|
||
// if (PatientAdapter.getIsSelected().get(i)) {
|
||
// String uuid = list.get(i).getUuid();
|
||
// // 要过滤出真正的uuid
|
||
// if (uuid.contains("#")) {
|
||
// uuid = uuid.split("#")[1];
|
||
// }
|
||
// Patientuuid += uuid + ",";
|
||
// mobile += list.get(i).getMobile() + ",";
|
||
// name += list.get(i).getRealName() + ",";
|
||
// }
|
||
//
|
||
// }
|
||
|
||
if (list2 == null && list2.size() == 0) {
|
||
return;
|
||
}
|
||
if (sureCount>200){
|
||
ToastUtil.showMessage("群发人数不能超过200人");
|
||
return;
|
||
}
|
||
// if (sureCount>100){
|
||
// ToastUtil.showMessage("群发人数不能超过100人");
|
||
// return;
|
||
// }
|
||
for (int i = 0; i < list2.size(); i++) {
|
||
// 选中情况
|
||
String uuid = list2.get(i).getUuid();
|
||
// 要过滤出真正的uuid
|
||
if (uuid.contains("#")) {
|
||
uuid = uuid.split("#")[1];
|
||
}
|
||
Patientuuid += uuid + ",";
|
||
mobile += list2.get(i).getMobile() + ",";
|
||
String nickName = list2.get(i).getNickName();
|
||
if(!StringUtil.isEmpty(nickName)){
|
||
name += nickName+ ",";
|
||
}else {
|
||
name += list2.get(i).getRealName() + ",";
|
||
}
|
||
|
||
|
||
}
|
||
// 传递数据
|
||
Intent intent = getIntent();
|
||
intent.putExtra("uuid", Patientuuid);
|
||
intent.putExtra("mobile", mobile);
|
||
intent.putExtra("name", name);
|
||
LogUtil.i("群发uuid=" + Patientuuid + "=mobile=" + mobile);
|
||
setResult(RESULTCODE_OK, intent);
|
||
finish();
|
||
}
|
||
|
||
/**
|
||
* 患者列表适配器
|
||
*/
|
||
public class PatientAdapter extends BaseAdapter {
|
||
private Context context;
|
||
private List<PatientModel> PatientList;
|
||
// 用来控制CheckBox的选中状况
|
||
// private static HashMap<Integer, Boolean> isSelected;
|
||
|
||
public PatientAdapter(Context context, ArrayList<PatientModel> list) {
|
||
this.context = context;
|
||
this.PatientList = list;
|
||
// isSelected = new HashMap<Integer, Boolean>();
|
||
// 初始化数据
|
||
// initDate();
|
||
}
|
||
|
||
// 初始化isSelected的数据 ,让所有都设置为未选中
|
||
// private void initDate() {
|
||
// for (int i = 0; i < PatientList.size(); i++) {
|
||
// getIsSelected().put(i, false);
|
||
// }
|
||
// }
|
||
|
||
@Override
|
||
public int getCount() {
|
||
return PatientList.size();
|
||
}
|
||
|
||
@Override
|
||
public View getView(int position, View convertView, ViewGroup parent) {
|
||
ViewHolder mHolder = null;
|
||
if (convertView == null) {
|
||
if(CommonUtil.BigModule())
|
||
{
|
||
convertView = View.inflate(context, R.layout.item_patient_list_big1,
|
||
null);
|
||
}
|
||
else
|
||
{
|
||
convertView = View.inflate(context, R.layout.item_patient_list,
|
||
null);
|
||
}
|
||
|
||
mHolder = new ViewHolder();
|
||
mHolder.ivImage = (ImageView) convertView
|
||
.findViewById(R.id.iv_patient_touxiang);// 头像
|
||
mHolder.tvTitle = (TextView) convertView
|
||
.findViewById(R.id.tv_patient_name);// 姓名
|
||
mHolder.cbSelect = (CheckBox) convertView
|
||
.findViewById(R.id.cb_select);// 选择框
|
||
mHolder.cbSelect.setVisibility(View.VISIBLE);
|
||
|
||
convertView.setTag(mHolder);
|
||
} else {
|
||
mHolder = (ViewHolder) convertView.getTag();
|
||
}
|
||
|
||
// 给控件赋值.
|
||
PatientModel p = PatientList.get(position);
|
||
// 姓名
|
||
mHolder.tvTitle.setText(p.getRealName());
|
||
if(CommonUtil.BigModule())
|
||
{
|
||
// 头像
|
||
if (!TextUtils.isEmpty(p.getPhoto()) && !"null".equals(p.getPhoto())) {
|
||
ImageLoader
|
||
.getInstance()
|
||
.displayImage(
|
||
Url.urlHtml + p.getPhoto(),
|
||
mHolder.ivImage,
|
||
ImageOptions
|
||
.getImageOptions(R.drawable.icon_touxiang_persion_gray_big));
|
||
} else {
|
||
mHolder.ivImage
|
||
.setImageResource(R.drawable.icon_touxiang_persion_gray_big);
|
||
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// 头像
|
||
if (!TextUtils.isEmpty(p.getPhoto()) && !"null".equals(p.getPhoto())) {
|
||
ImageLoader
|
||
.getInstance()
|
||
.displayImage(
|
||
Url.urlHtml + p.getPhoto(),
|
||
mHolder.ivImage,
|
||
ImageOptions
|
||
.getImageOptions(R.drawable.icon_touxiang_persion_gray_big));
|
||
} else {
|
||
mHolder.ivImage
|
||
.setImageResource(R.drawable.icon_touxiang_persion_gray_big);
|
||
|
||
}
|
||
}
|
||
|
||
// 根据isSelected来设置checkbox的选中状况
|
||
// mHolder.cbSelect.setChecked(getIsSelected().get(position));
|
||
mHolder.cbSelect.setChecked(p.isSelect());
|
||
return convertView;
|
||
}
|
||
|
||
@Override
|
||
public Object getItem(int position) {
|
||
// TODO Auto-generated method stub
|
||
return PatientList.get(position);
|
||
}
|
||
|
||
@Override
|
||
public long getItemId(int position) {
|
||
// TODO Auto-generated method stub
|
||
return position;
|
||
}
|
||
|
||
|
||
|
||
// public static HashMap<Integer, Boolean> getIsSelected() {
|
||
// return isSelected;
|
||
// }
|
||
|
||
// public void setIsSelected(HashMap<Integer, Boolean> isSelected) {
|
||
// PatientAdapter.isSelected = isSelected;
|
||
// }
|
||
|
||
public class ViewHolder {
|
||
|
||
public CheckBox cbSelect;
|
||
public ImageView ivImage;
|
||
public TextView tvTitle;
|
||
}
|
||
|
||
}
|
||
|
||
// ***********************全选*************************
|
||
public void selectAllContacts() {
|
||
if (list1 != null) {
|
||
for (int i = 0; i < list1.size(); i++) {
|
||
list2.addAll(list1);
|
||
list1.get(i).setSelect(true);
|
||
Set<PatientModel> middleLinkedHashSet = new LinkedHashSet<PatientModel>(list2);
|
||
list2 = new ArrayList<PatientModel>(middleLinkedHashSet);
|
||
// PatientAdapter.getIsSelected().put(i, true);
|
||
}
|
||
patientAdapter.notifyDataSetChanged();
|
||
checkNum = list2.size();
|
||
onContactClick(checkNum);
|
||
}
|
||
|
||
}
|
||
|
||
// ***********************非全选*************************
|
||
public void invertSelection() {
|
||
if (list1 != null) {
|
||
for (int i = 0; i < list1.size(); i++) {
|
||
// PatientAdapter.getIsSelected().put(i, false);
|
||
list1.get(i).setSelect(false);
|
||
for (int j= 0;j<list2.size();j++){
|
||
if (list1.get(i).getUuid().equals(list2.get(j).getUuid())){
|
||
list2.remove(j);
|
||
}
|
||
}
|
||
|
||
}
|
||
patientAdapter.notifyDataSetChanged();
|
||
onContactClick(list2.size());
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
|
||
// TODO Auto-generated method stub
|
||
// 取得ViewHolder对象,这样就省去了通过层层的findViewById去实例化我们需要的cb实例的步骤
|
||
ViewHolder holder = (ViewHolder) arg1
|
||
.getTag();
|
||
// ViewHolder holder = (ViewHolder) arg1.getTag();
|
||
// 改变CheckBox的状态
|
||
holder.cbSelect.toggle();
|
||
// 将CheckBox的选中状况记录下来
|
||
// PatientAdapter.getIsSelected().put(arg2, holder.cbSelect.isChecked());
|
||
// 调整选定条目
|
||
// if (holder.cbSelect.isChecked() == true) {
|
||
// checkNum++;
|
||
// } else {
|
||
// checkNum--;
|
||
// }
|
||
// onContactClick(checkNum);
|
||
PatientModel patientModel = list1.get(arg2);
|
||
if (holder.cbSelect.isChecked() == true) {
|
||
list2.add(list1.get(arg2));
|
||
for (int j= 0;j<list.size();j++){
|
||
if (patientModel.getUuid().equals(list.get(j).getUuid())){
|
||
list.get(j).setSelect(true);
|
||
}
|
||
}
|
||
} else {
|
||
if (list2.size()>0){
|
||
for (int i = 0;i<list2.size();i++){
|
||
if (patientModel.getUuid().equals(list2.get(i).getUuid())){
|
||
list2.remove(i);
|
||
}
|
||
}
|
||
for (int j= 0;j<list.size();j++){
|
||
if (patientModel.getUuid().equals(list.get(j).getUuid())){
|
||
list.get(j).setSelect(false);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
onContactClick(list2.size());
|
||
}
|
||
|
||
}
|