CertificationCourseDetailAdapter.java
6.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
package com.hh.xuetubao.adapter;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.hh.xuetubao.MyServer;
import com.hh.xuetubao.R;
import com.hh.xuetubao.Utils.BaseObsever;
import com.hh.xuetubao.Utils.HttpUtils;
import com.hh.xuetubao.Utils.ListviewUtils;
import com.hh.xuetubao.Utils.NetConfig;
import com.hh.xuetubao.Utils.SharedPrefrenceUtils;
import com.hh.xuetubao.activity.pratice.PriacticeDistActivity;
import com.hh.xuetubao.bean.AnswerBean;
import com.hh.xuetubao.bean.DoExerciseBean;
import com.hh.xuetubao.bean.FreeCourseBean;
import com.hh.xuetubao.fragment.CurriculumScheduleFragment;
import java.util.ArrayList;
import java.util.List;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
public class CertificationCourseDetailAdapter extends BaseAdapter {
private List<DoExerciseBean.bean> list;
private Context context;
private FragmentTransaction transaction;
private CertificationCourseContentAdapter adapter;
private int thisPosition;
private int viewId;
private int type;
private List<String> cataloglst = new ArrayList<>();
public CertificationCourseDetailAdapter(List<DoExerciseBean.bean> list, Context context, FragmentTransaction transaction, int viewId, int type) {
this.list = list;
this.context = context;
this.transaction = transaction;
this.viewId = viewId;
this.type = type;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
thisPosition = position;
View view = LayoutInflater.from(context).inflate(R.layout.lv_course_title, null);
ImageView img = (ImageView) view.findViewById(R.id.img);
TextView title = (TextView) view.findViewById(R.id.title);
ListView lv = (ListView) view.findViewById(R.id.lv_content);
List<DoExerciseBean.bean> catalogLst = list.get(position).getSubCatalogLst().get(position).getSubCatalogLst();
adapter = new CertificationCourseContentAdapter(catalogLst, context);
lv.setAdapter(adapter);
ListviewUtils.setListViewHeightBasedOnChildren(lv);
for (DoExerciseBean.bean a : catalogLst) {
cataloglst.add(a.getCatalogOid());
}
SharedPrefrenceUtils.putStringList(context, "CataLogLst", cataloglst);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
private Intent intent;
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String oid = list.get(thisPosition).getSubCatalogLst().get(thisPosition).getSubCatalogLst().get(position).getCatalogOid();
String accountOid = SharedPrefrenceUtils.getString(context, "AccountOid");
if (type == 1) {
//认证课程
doRequestOne(accountOid, oid);
} else if (type == 2) {
//练习
String title = list.get(thisPosition).getSubCatalogLst().get(thisPosition).getSubCatalogLst().get(position).getCatalogName();
doRequestTwo(oid, accountOid, title);
}
}
});
if (list.get(position).getSubCatalogLst().get(position).getCatalogName() != null)
title.setText(list.get(position).getSubCatalogLst().get(position).getCatalogName());
if (list.get(position).getCatalogPicUrl() != null && list.get(position).getCatalogPicUrl() != "")
Glide.with(context).load(list.get(position).getCatalogPicUrl()).into(img);
return view;
}
private void doRequestOne(String accountOid, final String oid) {
MyServer mServers = HttpUtils.getInstance().getServer(NetConfig.learnUrl);
mServers.getLessonLstByCatalogOid(accountOid, oid)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new BaseObsever() {
@Override
public void onNext(Object value) {
super.onNext(value);
FreeCourseBean courseBean = (FreeCourseBean) value;
if (courseBean.getSuccess()) {
CurriculumScheduleFragment curriculumScheduleFragment = new CurriculumScheduleFragment();
transaction.replace(R.id.frame, curriculumScheduleFragment, oid);
transaction.commit();
} else {
Toast.makeText(context, "当前账号无权限,请拨打电话xxxxxxxxxx", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onError(Throwable e) {
super.onError(e);
}
@Override
public void onComplete() {
super.onComplete();
}
});
}
private void doRequestTwo(final String catalogOid, String accountOid, final String title) {
MyServer mServers = HttpUtils.getInstance().getServer(NetConfig.shuaTiUrl);
mServers.GetRandomQuestions(catalogOid, Integer.valueOf(10), accountOid)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new BaseObsever() {
@Override
public void onNext(Object value) {
super.onNext(value);
AnswerBean bean = (AnswerBean) value;
if (bean.isIsSuccess()) {
Intent intent = new Intent(context, PriacticeDistActivity.class);
intent.putExtra("CatalogOid", catalogOid);
SharedPrefrenceUtils.saveString(context, "PraticeTitle", title);
context.startActivity(intent);
} else {
Toast.makeText(context, "当前账号无权限,请拨打电话xxxxxxxxxx", Toast.LENGTH_SHORT).show();
}
}
});
}
}