ChoiseTextBookActivity.java
8.77 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
package com.hjx.personalcenter.activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.facebook.drawee.view.SimpleDraweeView;
import com.hjx.personalcenter.R;
import com.hjx.personalcenter.adapter.GridAdapter;
import com.hjx.personalcenter.customdialog.ElectronicCardDialog;
import com.hjx.personalcenter.customdialog.VerSionDialog;
import com.hjx.personalcenter.db.SaveParam;
import com.hjx.personalcenter.http.HttpCode;
import com.hjx.personalcenter.http.HttpManager;
import com.hjx.personalcenter.model.DefautPublishInfo;
import com.hjx.personalcenter.util.AlertUtils;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
* 选择教材
* Created by h on 2017/8/10.
*/
public class ChoiseTextBookActivity extends AppCompatActivity implements View.OnClickListener, AdapterView.OnItemClickListener{
private GridView gridView;
private Button btn_ok;
private ImageView cancel;
private ArrayList<DefautPublishInfo.DataBean> defautPublishInfos = new ArrayList<>();
private GridAdapter sim_adapter;
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
JSONObject jsonObject;
String status;
switch (msg.what) {
case HttpCode.CHECKCARD:
try {
jsonObject = new JSONObject((String) msg.obj);
status = jsonObject.optString("status");
if (status.equals("1")) {
AlertUtils.showToast(ChoiseTextBookActivity.this, "您已经填写了保卡信息,请到主界面确认您的保卡信息是否正确!");
Intent intent = new Intent();
intent.setClass(ChoiseTextBookActivity.this, TheStartPageActivity.class);
ChoiseTextBookActivity.this.startActivity(intent);
overridePendingTransition(R.anim.rightin, R.anim.rightout);
} else if (status.equals("2001")) {
ElectronicCardDialog.getInstance().show(getSupportFragmentManager(), "ElectronicCardDialog");
}
} catch (JSONException e) {
e.printStackTrace();
}
break;
case HttpCode.PUBLISH_SUCESS:
defautPublishInfos.clear();
defautPublishInfos.addAll( (List<DefautPublishInfo.DataBean>)msg.obj);
sim_adapter.notifyDataSetChanged();
break;
case HttpCode.REGISTERINFO_SUCESS:
try {
jsonObject = new JSONObject((String) msg.obj);
String statusregister = jsonObject.optString("status");
if (statusregister.equals("1")) {
Toast.makeText(ChoiseTextBookActivity.this, "注册信息上传成功", Toast.LENGTH_LONG).show();
String userID = SaveParam.getInstance().getLoginParam(ChoiseTextBookActivity.this, "userId");
try {
if (userID == null) {
AlertUtils.showToast(ChoiseTextBookActivity.this, "连接超时请重新登录!");
} else {
long auserID = Long.parseLong(userID);
//验证保卡信息
HttpManager.getInstance().cardinfocheck(ChoiseTextBookActivity.this, auserID, handler);
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
} else {
AlertUtils.showToast(ChoiseTextBookActivity.this, "您好,服务器异常,请稍后重试");
}
} catch (JSONException e) {
e.printStackTrace();
}
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String userID = SaveParam.getInstance().getLoginParam(this,"userId");
String graderid = SaveParam.getInstance().getCustomizeParam(this,SaveParam.GRADENS);
try {
long auserID = Long.parseLong(userID);
int graderID = Integer.parseInt(graderid);
//获取版本信息
HttpManager.getInstance().getpublishinfo(this,auserID,graderID,handler);
} catch (NumberFormatException e) {
e.printStackTrace();
}
setContentView(R.layout.activity_choisetextbook);
initView();
initData();
initLister();
}
private void initView() {
gridView = (GridView) findViewById(R.id.grideview);
cancel = (ImageView) findViewById(R.id.cancel);
btn_ok = (Button) findViewById(R.id.btn_ok);
}
private void initData() {
sim_adapter = new GridAdapter(defautPublishInfos,this);
//配置适配器
gridView.setAdapter(sim_adapter);
}
private void initLister() {
btn_ok.setOnClickListener(this);
cancel.setOnClickListener(this);
gridView.setOnItemClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_ok:
String userID = SaveParam.getInstance().getLoginParam(this, "userId");
String regionId = SaveParam.getInstance().getLoginParam(ChoiseTextBookActivity.this, SaveParam.COUNTRY);
String regionId1 = SaveParam.getInstance().getLoginParam(ChoiseTextBookActivity.this, SaveParam.CITYS);
if (regionId == null) {
regionId = regionId1;
}
String grade = SaveParam.getInstance().getCustomizeParam(ChoiseTextBookActivity.this, SaveParam.GRADENS);
String schoolid = SaveParam.getInstance().getLoginParam(ChoiseTextBookActivity.this, SaveParam.SCHOOOlID);
String name = SaveParam.getInstance().getLoginParam(ChoiseTextBookActivity.this, SaveParam.USERNAME);
String regeionname = SaveParam.getInstance().getLoginParam(ChoiseTextBookActivity.this, SaveParam.ADRESS);
String togoth ="人民教育出版社";
try {
if (userID == null) {
AlertUtils.showToast(ChoiseTextBookActivity.this, "连接超时请重新登录!");
} else {
Object schoolID;
long auserID = Long.parseLong(userID);
int gradeID = Integer.parseInt(grade);
long regionID = Long.parseLong(regionId);
if (schoolid==null){
schoolID =null;
}else {
schoolID = Long.parseLong(schoolid);
}
//提交注册信息
HttpManager.getInstance().subregisterinfo(ChoiseTextBookActivity.this, auserID,
name ,gradeID,regionID,regeionname,schoolID,togoth,togoth,togoth,togoth
,togoth,togoth,togoth,togoth,togoth,togoth,handler);
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
break;
case R.id.cancel:
finish();
break;
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
SaveParam.getInstance().saveLoginParam(this,SaveParam.SUBJECT,defautPublishInfos.get(position).getSubject());
VerSionDialog.getInstance().show(getSupportFragmentManager(), "VerSionDialog");
String imgurl = SaveParam.getInstance().getLoginParam(this, SaveParam.IMGURL);
String version = SaveParam.getInstance().getLoginParam(this, SaveParam.VERSION);
SimpleDraweeView simpleDraweeView = (SimpleDraweeView) parent.findViewById(R.id.image_publish);
TextView publish = (TextView) parent.findViewById(R.id.tv_publish);
simpleDraweeView.setImageURI(imgurl);
publish.setText(version);
}
}