Commit ab663b2d09ef50f3f8575dcd09e4f75519d42ec6
1 parent
d49f39e2
1 完成设置角色逻辑
Showing
5 changed files
with
37 additions
and
19 deletions
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/frame/view/SetFriendsRoleView.java
| ... | ... | @@ -44,7 +44,7 @@ public class SetFriendsRoleView implements MvpView { |
| 44 | 44 | bean.setAllowUse(roleNetBean.getRoleList().get(j).isAllowUse()); |
| 45 | 45 | bean.setId(roleNetBean.getRoleList().get(j).getId()); |
| 46 | 46 | bean.setRoleName(roleNetBean.getRoleList().get(j).getRoleName()); |
| 47 | - bean.setSelectList(new ArrayList<>()); | |
| 47 | + bean.setParentPosition(i); | |
| 48 | 48 | roleList.add(bean); |
| 49 | 49 | } |
| 50 | 50 | roleInfo.setRoleList(roleList); | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/model/RoleInfo.java
| ... | ... | @@ -12,6 +12,15 @@ public class RoleInfo { |
| 12 | 12 | private String userIcon; |
| 13 | 13 | private String userName; |
| 14 | 14 | private List<RoleNetBean.RoleListBean> roleList; |
| 15 | + private String selectId; | |
| 16 | + | |
| 17 | + public String getSelectId() { | |
| 18 | + return selectId; | |
| 19 | + } | |
| 20 | + | |
| 21 | + public void setSelectId(String selectId) { | |
| 22 | + this.selectId = selectId; | |
| 23 | + } | |
| 15 | 24 | |
| 16 | 25 | public List<RoleNetBean.RoleListBean> getRoleList() { |
| 17 | 26 | return roleList; | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/netWork/bean/RoleNetBean.java
| ... | ... | @@ -35,14 +35,14 @@ public class RoleNetBean { |
| 35 | 35 | private boolean allowUse; |
| 36 | 36 | private int id; |
| 37 | 37 | private String roleName; |
| 38 | - private List<String> selectList; | |
| 38 | + private int parentPosition; | |
| 39 | 39 | |
| 40 | - public List<String> getSelectList() { | |
| 41 | - return selectList; | |
| 40 | + public int getParentPosition() { | |
| 41 | + return parentPosition; | |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - public void setSelectList(List<String> selectList) { | |
| 45 | - this.selectList = selectList; | |
| 44 | + public void setParentPosition(int parentPosition) { | |
| 45 | + this.parentPosition = parentPosition; | |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | public boolean isAllowUse() { | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/adapter/AllRoleDetailAdapter.java
| ... | ... | @@ -12,6 +12,7 @@ import android.view.ViewGroup; |
| 12 | 12 | import com.cnlive.libs.base.util.AlertUtil; |
| 13 | 13 | import com.cnlive.strike.xiaojiaspeaker.R; |
| 14 | 14 | import com.cnlive.strike.xiaojiaspeaker.databinding.ItemListSetRoleCheckBoxBinding; |
| 15 | +import com.cnlive.strike.xiaojiaspeaker.model.RoleInfo; | |
| 15 | 16 | import com.cnlive.strike.xiaojiaspeaker.netWork.bean.RoleNetBean; |
| 16 | 17 | import com.cnlive.strike.xiaojiaspeaker.util.utilcode.util.GsonUtils; |
| 17 | 18 | |
| ... | ... | @@ -48,12 +49,13 @@ public class AllRoleDetailAdapter extends RecyclerView.Adapter { |
| 48 | 49 | //设置名称 |
| 49 | 50 | binding.checkBox.setText(allRoleList.get(position).getRoleName()); |
| 50 | 51 | //设置不可选中的 |
| 51 | - if (null != allRoleList.get(position).getSelectList()) { | |
| 52 | - if (allRoleList.get(position).getSelectList().contains(allRoleList.get(position).getId() + "")) { | |
| 53 | - binding.checkBox.setChecked(true); | |
| 54 | - } else { | |
| 55 | - binding.checkBox.setChecked(false); | |
| 56 | - } | |
| 52 | + List<RoleInfo> roleInfoList = setRoleAdapter.getRoleInfoList(); | |
| 53 | + String selectId = roleInfoList.get(allRoleList.get(position).getParentPosition()).getSelectId(); | |
| 54 | + if (null == selectId) { | |
| 55 | + selectId = ""; | |
| 56 | + } | |
| 57 | + if (selectId.contains(allRoleList.get(position).getId() + "")) { | |
| 58 | + binding.checkBox.setChecked(true); | |
| 57 | 59 | } else { |
| 58 | 60 | binding.checkBox.setChecked(false); |
| 59 | 61 | } |
| ... | ... | @@ -90,7 +92,10 @@ public class AllRoleDetailAdapter extends RecyclerView.Adapter { |
| 90 | 92 | public void onClick(View view) { |
| 91 | 93 | if (view.getId() == R.id.ll_root) { |
| 92 | 94 | int position = getAdapterPosition(); |
| 93 | - List<String> selectList = allRoleList.get(position).getSelectList(); | |
| 95 | + String selectId = setRoleAdapter.getRoleInfoList().get(allRoleList.get(position).getParentPosition()).getSelectId(); | |
| 96 | + if (null == selectId) { | |
| 97 | + selectId = ""; | |
| 98 | + } | |
| 94 | 99 | String currentRoleId = allRoleList.get(position).getId() + ""; |
| 95 | 100 | //先判断是否是后台初始传过来的 |
| 96 | 101 | if (setRoleAdapter.getInitNotAllowRoleId().contains(currentRoleId)) { |
| ... | ... | @@ -99,7 +104,7 @@ public class AllRoleDetailAdapter extends RecyclerView.Adapter { |
| 99 | 104 | } |
| 100 | 105 | //判断点击这个东西在不在已存储的集合中 |
| 101 | 106 | if (!allowSelectMap.get(currentRoleId)) { |
| 102 | - if (!selectList.contains(currentRoleId)) { | |
| 107 | + if (!selectId.equals(currentRoleId)) { | |
| 103 | 108 | AlertUtil.showDeftToast(context, "该角色已占用!"); |
| 104 | 109 | return; |
| 105 | 110 | } |
| ... | ... | @@ -108,13 +113,13 @@ public class AllRoleDetailAdapter extends RecyclerView.Adapter { |
| 108 | 113 | //开始设置全局状态 |
| 109 | 114 | if (binding.checkBox.isChecked()) { |
| 110 | 115 | //添加到选中的集合 |
| 111 | - if (!selectList.contains(currentRoleId)) { | |
| 112 | - selectList.add(currentRoleId); | |
| 116 | + if (!selectId.equals(currentRoleId)) { | |
| 117 | + //重置状态 | |
| 118 | + allowSelectMap.put(selectId, true); | |
| 119 | + setRoleAdapter.getRoleInfoList().get(allRoleList.get(position).getParentPosition()).setSelectId(currentRoleId); | |
| 113 | 120 | } |
| 114 | 121 | } else { |
| 115 | - if (selectList.contains(currentRoleId)) { | |
| 116 | - selectList.remove(currentRoleId); | |
| 117 | - } | |
| 122 | + setRoleAdapter.getRoleInfoList().get(allRoleList.get(position).getParentPosition()).setSelectId(""); | |
| 118 | 123 | } |
| 119 | 124 | //设置全局不允许选择 |
| 120 | 125 | allowSelectMap.put(currentRoleId, !binding.checkBox.isChecked()); | ... | ... |
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/adapter/SetRoleAdapter.java
| ... | ... | @@ -25,6 +25,10 @@ public class SetRoleAdapter extends RecyclerView.Adapter { |
| 25 | 25 | private AllRoleDetailAdapter adapter; |
| 26 | 26 | private List<Integer> initNotAllowRoleId;//服务器初始给的不允许点击的值 |
| 27 | 27 | |
| 28 | + public List<RoleInfo> getRoleInfoList() { | |
| 29 | + return roleInfoList; | |
| 30 | + } | |
| 31 | + | |
| 28 | 32 | public Map<String, Boolean> getAllowSelectMap() { |
| 29 | 33 | return allowSelectMap; |
| 30 | 34 | } | ... | ... |