package com.basic.security.fragment;
|
|
import android.text.TextUtils;
|
import android.view.View;
|
import android.widget.Button;
|
import android.widget.CheckBox;
|
import android.widget.CompoundButton;
|
import android.widget.RadioButton;
|
|
import com.basic.security.R;
|
import com.basic.security.base.BaseApplication;
|
import com.basic.security.base.BaseFragment;
|
import com.basic.security.manager.BaseSettingManager;
|
import com.basic.security.manager.IdentityManager;
|
import com.basic.security.manager.PersonIdentityManager;
|
import com.basic.security.manager.PersonManager;
|
import com.basic.security.model.ModelAdapter;
|
import com.basic.security.utils.ToastUtil;
|
import com.basic.security.utils.abslistview.CommonAdapter;
|
import com.basic.security.utils.abslistview.ViewHolder;
|
import com.basic.security.widget.hlistview.HListView;
|
|
import org.androidannotations.annotations.AfterViews;
|
import org.androidannotations.annotations.Click;
|
import org.androidannotations.annotations.EFragment;
|
import org.androidannotations.annotations.UiThread;
|
import org.androidannotations.annotations.ViewById;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
|
@EFragment(R.layout.fragment_person_identity)
|
public class PersonIdentityFragment extends BaseFragment {
|
|
@ViewById
|
public Button save, tempSave, deletePerson, giveUpSave;
|
public Map<String, ModelAdapter> checkedIdentityMapByPerson = new HashMap<>();
|
public ModelAdapter checkedPerson = null;
|
@ViewById
|
HListView identity_list;
|
@ViewById
|
RadioButton allDevice, thisDevice;
|
@ViewById
|
View next;
|
List<ModelAdapter> allIdentityList = new ArrayList<>();
|
private CommonAdapter adapter;
|
|
@Override
|
public void show() {
|
allIdentityList.clear();
|
allIdentityList.addAll(IdentityManager.findIdentityList());
|
if (mainActivity().currentFragment == mainActivity().fragment_su_logged_ic_wait_face) {
|
deletePerson.setVisibility(View.VISIBLE);
|
}
|
if (mainActivity().currentFragment == mainActivity().fragment_su_logged_ic_compare_success) {
|
deletePerson.setVisibility(View.VISIBLE);
|
}
|
if (mainActivity().currentFragment == mainActivity().fragment_su_logged_ic_wait_idcard) {
|
deletePerson.setVisibility(View.VISIBLE);
|
}
|
// setIdentityWithPerson(null);
|
// adapter.notifyDataSetChanged();
|
}
|
|
@UiThread
|
public void setIsTempSave(boolean isTempSave) {
|
if (save != null && tempSave != null) {
|
boolean alwaysShowSave = mainActivity().currentFragment == mainActivity().fragment_person_manage &&
|
"已注册".equals(mainActivity().fragment_face_list.isRegister);
|
if (isTempSave && !alwaysShowSave) {
|
save.setVisibility(View.GONE);
|
tempSave.setVisibility(View.VISIBLE);
|
} else {
|
tempSave.setVisibility(View.GONE);
|
save.setVisibility(View.VISIBLE);
|
}
|
}
|
}
|
|
@AfterViews
|
public void afterViews() {
|
setIsTempSave(true);
|
thisDevice.setChecked(true);
|
adapter = new CommonAdapter<ModelAdapter>(mainActivity(), R.layout.identity_checkbox_item, allIdentityList) {
|
protected void convert(ViewHolder vh, ModelAdapter singleIdentityInAllIdentity, int position) {
|
CheckBox identityCB = vh.getView(R.id.identity_checkbox);
|
identityCB.setText(singleIdentityInAllIdentity.getString("name"));
|
identityCB.setChecked(checkedIdentityMapByPerson.containsKey(singleIdentityInAllIdentity.getId()));
|
identityCB.setClickable(true);
|
if (checkedPerson != null && "1".equals(checkedPerson.getString("auto_init"))) {
|
identityCB.setClickable(false);
|
} else {
|
identityCB.setClickable(true);
|
identityCB.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
@Override
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
if (isChecked) {
|
if (!checkedIdentityMapByPerson.containsKey(singleIdentityInAllIdentity.getId())) {
|
checkedIdentityMapByPerson.put(singleIdentityInAllIdentity.getId(), singleIdentityInAllIdentity);
|
}
|
} else {
|
if (checkedIdentityMapByPerson.containsKey(singleIdentityInAllIdentity.getId())) {
|
checkedIdentityMapByPerson.remove(singleIdentityInAllIdentity.getId());
|
}
|
}
|
adapter.notifyDataSetChanged();
|
}
|
});
|
|
}
|
}
|
};
|
identity_list.setAdapter(adapter);
|
}
|
|
@Click
|
public void save() {
|
mainActivity().fragment_person_manage.savePerson();
|
}
|
|
@Click
|
public void tempSave() {
|
mainActivity().fragment_person_manage.savePerson();
|
}
|
|
@Click
|
public void deletePerson() {
|
mainActivity().fragment_person_manage.deletePerson();
|
}
|
|
@Click
|
public void giveUpSave() {
|
mainActivity().fragment_person_manage.giveUpSave();
|
}
|
|
// @Click
|
// public void allDevice() {
|
// if (allDevice.isChecked()) {
|
// ((FaceDetailTimeFragment) mainActivity().fragment_face_detail_time).checkDevice();
|
// }
|
// }
|
|
public void setIdentityWithPerson(String personId) {
|
checkedPerson = PersonManager.findPersonById(personId);
|
thisDevice.setChecked(true);
|
if (personId == null) {
|
checkedIdentityMapByPerson = new HashMap<>();
|
}
|
setIdentityWithPersonInThread(personId);
|
}
|
|
public void setIdentityWithPersonInThread(String personId) {
|
BaseApplication.getApplication().executorService.execute(() -> {
|
if (personId != null) {
|
checkedIdentityMapByPerson = PersonIdentityManager.findIdentityMapByPersonId(personId);
|
}
|
notifyDataSetChanged();
|
});
|
|
}
|
|
@UiThread
|
public void notifyDataSetChanged() {
|
adapter.notifyDataSetChanged();
|
}
|
|
public void setDevice(String all_device) {// 1 所有设备 0 当前设备
|
if (false && "1".equals(all_device)) {
|
allDevice.setChecked(true);
|
} else {
|
thisDevice.setChecked(true);
|
}
|
|
}
|
|
/**
|
* 保存人员信息时,如果checkedIdentityMapByPerson为null时返回FALSE会影响其他逻辑
|
* 所以写了一个checkedIdentityMapByPerson.keySet().size()方法
|
*/
|
public boolean savePersonIdentity(String personId) {
|
List<String> nameList = new ArrayList<>();
|
for (ModelAdapter identityModelAdapter : checkedIdentityMapByPerson.values()) {
|
if (identityModelAdapter != null && !TextUtils.isEmpty(identityModelAdapter.getString("name"))) {
|
nameList.add(identityModelAdapter.getString("name"));
|
}
|
}
|
if (nameList.contains("黑名单") && nameList.contains("管理员")) {
|
ToastUtil.show("管理员和黑名单不能同时选中");
|
return false;
|
}
|
|
if (mainActivity().currentFragment == mainActivity().fragment_su_auto_ic_compare_success
|
|| mainActivity().currentFragment == mainActivity().fragment_su_auto_nic_wait_detail
|
|| mainActivity().currentFragment == mainActivity().fragment_sign_up_success
|
|| mainActivity().currentFragment == mainActivity().fragment_su_auto_ic_wait_idcard
|
|| mainActivity().currentFragment == mainActivity().fragment_su_auto_wait_face
|
) {
|
checkedIdentityMapByPerson.clear();
|
String id = BaseSettingManager.getDefaultIdentityId();
|
if (id != null) {
|
if (IdentityManager.findIdentityById(id) == null) {
|
ToastUtil.show("自助注册默认身份出错,请联系管理员");
|
} else {
|
checkedIdentityMapByPerson.put(id, IdentityManager.findIdentityById(id));
|
}
|
}
|
}
|
|
Map<String, ModelAdapter> dbCheckedIdentityMapByPerson = PersonIdentityManager.findIdentityMapByPersonId(personId);
|
for (String identityId : checkedIdentityMapByPerson.keySet()) {
|
if (!dbCheckedIdentityMapByPerson.containsKey(identityId)) {
|
PersonIdentityManager.save(personId, identityId);
|
|
if (IdentityManager.findIdentityById(identityId) != null &&
|
"管理员".equals(IdentityManager.findIdentityById(identityId).getString("name"))) {
|
PersonIdentityManager.saveAdminIdentity(personId);
|
}
|
}
|
}
|
for (String identityId : dbCheckedIdentityMapByPerson.keySet()) {
|
if (!checkedIdentityMapByPerson.containsKey(identityId)) {
|
PersonIdentityManager.delete(personId, identityId);
|
|
if (IdentityManager.findIdentityById(identityId) != null &&
|
"管理员".equals(IdentityManager.findIdentityById(identityId).getString("name"))) {
|
PersonIdentityManager.delAdminIdentity(personId);
|
}
|
}
|
}
|
return true;
|
}
|
|
public String aboutDevice() {
|
if (allDevice.isChecked()) {
|
// List<String> list =((FaceDetailTimeFragment) mainActivity().fragment_face_detail_time).checkedDeviceList;
|
// return StringUtils.join(list,",");
|
return "1";
|
}
|
if (thisDevice.isChecked()) {
|
// return SlDeviceSettingManager.getDeviceName();
|
return "0";
|
}
|
return null;
|
}
|
|
public int getIdentitySize() {
|
return checkedIdentityMapByPerson.values().size();
|
}
|
|
@Click
|
void next() {
|
|
int position = identity_list.getFirstVisiblePosition();
|
|
if (position + 2 > allIdentityList.size()) {
|
position = allIdentityList.size();
|
} else {
|
position += 2;
|
}
|
identity_list.setSelection(position);
|
}
|
|
}
|