AccountChildsAdapter.java
11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
package com.hjx.personalcenter.adapter;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.hjx.personalcenter.R;
import com.hjx.personalcenter.activity.RegisterInfoActivity;
import com.hjx.personalcenter.db.Content;
import com.hjx.personalcenter.db.SaveParam;
import com.hjx.personalcenter.http.HttpManager;
import com.hjx.personalcenter.model.ChildsInfo;
import com.hjx.personalcenter.util.GetDevicesUtil;
import com.mylhyl.circledialog.CircleDialog;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
import java.util.List;
/**
* Created by h on 2017/8/26.
*/
public class AccountChildsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements View.OnClickListener {
private List<ChildsInfo.DataBean> specailList;
private LayoutInflater mInflater;
private Context mContext;
private static final int BODY_TYPE = 00002;
private static final int FOOT_TYPE = 00003;
private int footCount = 1;//尾部个数,后续可以自己拓展
public AccountChildsAdapter(ArrayList<ChildsInfo.DataBean> specailList, Context context) {
this.mContext = context;
this.specailList = specailList;
mInflater = LayoutInflater.from(context);
}
public OnItemClickListener mOnItemClickListener;
@Override
public void onClick(View v) {
if (mOnItemClickListener == null) {
mOnItemClickListener.onItemClick(v, (int) v.getTag());
}
}
private int getBodySize() {
return specailList.size();
}
private boolean isFoot(int position) {
return footCount != 0 && (position >= (getBodySize()));
}
@Override
public int getItemViewType(int position) {
if (isFoot(position)) {
return FOOT_TYPE;
} else {
return BODY_TYPE;
}
}
public interface OnItemClickListener {
void onItemClick(View view, int position);
}
public void setOnItemClickListener(OnItemClickListener mOnItemClickLitener) {
this.mOnItemClickListener = mOnItemClickLitener;
}
public void setList(List<ChildsInfo.DataBean> list) {
this.specailList = list;
notifyDataSetChanged();
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
switch (viewType) {
case BODY_TYPE:
return new AccountChildsHolder(mInflater.inflate(R.layout.recycler_childaccunt_item_view, parent, false));
case FOOT_TYPE:
return new FootViewHolder(mInflater.inflate(R.layout.activity_account_management_add, parent, false));
default:
return null;
}
// View view = ;
// view.setOnClickListener(this);
// AccountChildsHolder holder = new AccountChildsHolder(view);
// return holder;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
String account = SaveParam.getInstance().getCustomizeParam(mContext, SaveParam.ACCOUNT);
if (holder instanceof AccountChildsHolder) {
final ChildsInfo.DataBean bean = specailList.get(position);
if (bean != null) {
if (bean.getImage()!=null&&!bean.getImage().isEmpty()) {
Picasso.with(mContext).load(bean.getImage()).into( ((AccountChildsHolder) holder).mSimpleDraweeView);
}
((AccountChildsHolder) holder).iv_child_name.setText(bean.getName());
((AccountChildsHolder) holder).iv_child_grade.setText(bean.getGrade());
((AccountChildsHolder) holder).iv_child_school.setText(bean.getSchool());
((AccountChildsHolder) holder).iv_child_adress.setText(bean.getRegion());
if (account.equals("1")) {
((AccountChildsHolder) holder).chang_account.setText("切换用户");
((AccountChildsHolder) holder).chang_account.setEnabled(true);
((AccountChildsHolder) holder).delete_account.setEnabled(true);
((AccountChildsHolder) holder).iv_using_pic.setVisibility(View.GONE);
((AccountChildsHolder) holder).ll_backgrangd.setBackgroundResource(R.drawable.corcle_black_bg);
} else {
if ("已使用".equals(bean.getStatus())) {
((AccountChildsHolder) holder).chang_account.setText("使用中");
((AccountChildsHolder) holder).chang_account.setEnabled(false);
((AccountChildsHolder) holder).delete_account.setEnabled(false);
((AccountChildsHolder) holder).iv_using_pic.setVisibility(View.VISIBLE);
((AccountChildsHolder) holder).ll_backgrangd.setBackgroundResource(R.drawable.corcle_blue_bg);
} else {
((AccountChildsHolder) holder).chang_account.setText("切换用户");
((AccountChildsHolder) holder).chang_account.setEnabled(true);
((AccountChildsHolder) holder).delete_account.setEnabled(true);
((AccountChildsHolder) holder).iv_using_pic.setVisibility(View.GONE);
((AccountChildsHolder) holder).ll_backgrangd.setBackgroundResource(R.drawable.corcle_black_bg);
}
}
((AccountChildsHolder) holder).delete_account.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new CircleDialog.Builder((FragmentActivity) mContext)
.setCanceledOnTouchOutside(false)
.setWidth(0.4f)
.setCancelable(false)
.setText("您确定删除该子账户?")
.setNegative("取消", null)
.setPositive("确定", new View.OnClickListener() {
@Override
public void onClick(View v) {
HttpManager.getInstance().deletechildAccountinfo(mContext, bean.getSubAccountId());
}
})
.show();
}
});
((AccountChildsHolder) holder).chang_account.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new CircleDialog.Builder((FragmentActivity) mContext)
.setCanceledOnTouchOutside(false)
.setWidth(0.4f)
.setCancelable(false)
.setText("您确定切换为该子账户?")
.setNegative("取消", null)
.setPositive("确定", new View.OnClickListener() {
@Override
public void onClick(View v) {
Content.changgeaccountflag = 2;
String ss = SaveParam.getInstance().getLoginParam(mContext, SaveParam.GRADENS);
try {
int zhugrade = Integer.parseInt(ss);
int zigrade =Integer.parseInt(bean.getGradeId());
// if ((zhugrade < 8)&&(zigrade>=8)||(zhugrade >= 8)&&(zigrade<8)) {
// Intent intentbroad = new Intent();
// intentbroad.putExtra("info", "小学");
// //4、定义广播发送的action
// intentbroad.setAction("com.ozing.launcher.SWITCH_GRADE");
// //5、发送广播
// mContext.sendBroadcast(intentbroad);
// Log.i("---", "发送完了");
// }
} catch (NumberFormatException e) {
e.printStackTrace();
}
SaveParam.getInstance().saveCustomizeParam(mContext, SaveParam.ACCOUNT, "2");
SaveParam.getInstance().saveCustomizeParam(mContext, SaveParam.CHILDSID, bean.getSubAccountId());
//保存子账号年级id
SaveParam.getInstance().saveCustomizeParam(mContext, SaveParam.CHILDSGRADENSss, bean.getGradeId());
String devicenumber = GetDevicesUtil.getDevicesInfo(mContext).getDeviceNumber();
HttpManager.getInstance().changechildAccountinfo(mContext, bean.getSubAccountId(), bean.getParentId(),
devicenumber, 2);
}
})
.show();
}
});
}
} else if (holder instanceof FootViewHolder) {
((FootViewHolder) holder).add_account.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Content.accountflag = 2;
Intent account = new Intent();
account.setClass(mContext, RegisterInfoActivity.class);
mContext.startActivity(account);
((Activity) mContext).overridePendingTransition(R.anim.rightin, R.anim.rightout);
}
});
}
}
@Override
public int getItemCount() {
return getBodySize() + footCount;
}
private static class AccountChildsHolder extends RecyclerView.ViewHolder {
ImageView iv_using_pic;
LinearLayout ll_backgrangd;
ImageView mSimpleDraweeView;
TextView iv_child_name, iv_child_grade, iv_child_school, iv_child_adress,
delete_account, chang_account;
public AccountChildsHolder(View itemView) {
super(itemView);
mSimpleDraweeView = (ImageView) itemView.findViewById(R.id.iv_child_head);
iv_child_name = (TextView) itemView.findViewById(R.id.iv_child_name);
iv_child_grade = (TextView) itemView.findViewById(R.id.iv_child_grade);
iv_child_school = (TextView) itemView.findViewById(R.id.iv_child_school);
iv_child_adress = (TextView) itemView.findViewById(R.id.iv_child_adress);
delete_account = (TextView) itemView.findViewById(R.id.delete_child_account);
chang_account = (TextView) itemView.findViewById(R.id.chang_account);
iv_using_pic = (ImageView) itemView.findViewById(R.id.iv_using_pic);
ll_backgrangd = (LinearLayout) itemView.findViewById(R.id.ll_backgrangd);
}
}
private static class FootViewHolder extends RecyclerView.ViewHolder {
LinearLayout add_account;
public FootViewHolder(View itemView) {
super(itemView);
add_account = (LinearLayout) itemView.findViewById(R.id.add_account);
}
}
}