StudyFragment.java
9.0 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
260
261
package com.hh.xuetubao.fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.hh.xuetubao.MainActivity;
import com.hh.xuetubao.R;
import com.hh.xuetubao.Utils.CustomScrollView;
import com.hh.xuetubao.Utils.RecyclerViewSpacesItemDecoration;
import com.hh.xuetubao.Utils.SharedPrefrenceUtils;
import com.hh.xuetubao.activity.study.CourseDetailActivity_Video;
import com.hh.xuetubao.adapter.StudyTimeXrcAdapter;
import com.hh.xuetubao.adapter.StudyXrecAdapter;
import com.hh.xuetubao.bean.LearningRecordDataBean;
import com.hh.xuetubao.bean.MyLearningInfoBean;
import com.hh.xuetubao.bean.UserBean;
import com.hh.xuetubao.model.LearnModel;
import com.hh.xuetubao.mvp.BaseMvpFragment;
import com.hh.xuetubao.mvp.CommonPresenter;
import com.hh.xuetubao.mvp.ICommonView;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class StudyFragment extends BaseMvpFragment<CommonPresenter, LearnModel> implements ICommonView, CustomScrollView.OnScrollChangeListener, XRecyclerView.LoadingListener, View.OnClickListener, StudyXrecAdapter.TurnTo {
@BindView(R.id.xrecyclerview)
XRecyclerView xrecyclerview;
@BindView(R.id.rv_readTime)
RecyclerView rvReadTime;
@BindView(R.id.img_user)
ImageView imgUser;
@BindView(R.id.tv_user)
TextView tvUser;
@BindView(R.id.today_study)
TextView todayStudy;
@BindView(R.id.duration_study)
TextView durationStudy;
@BindView(R.id.total_study)
TextView totalStudy;
@BindView(R.id.scroll)
CustomScrollView scroll;
@BindView(R.id.lin_back)
LinearLayout linBack;
@BindView(R.id.rl_user)
RelativeLayout rlUser;
@BindView(R.id.rl_body)
RelativeLayout rlBody;
private StudyXrecAdapter adapter;
private StudyTimeXrcAdapter xrcAdapter;
private int pageIndex = 1;
private int pageSize = 10;
private List<LearningRecordDataBean.learnBean> mlist = new ArrayList<>();
private boolean isRefresh = false;
private List<String> day = new ArrayList<>();
private List<String> time = new ArrayList<>();
private String resumeOid;
List<Integer> arr = new ArrayList<>();
int max;
@Override
public int getLayoutId() {
return R.layout.activity_study;
}
@Override
public void initView(@Nullable Bundle savedInstanceState) {
ButterKnife.bind(getActivity());
resumeOid = SharedPrefrenceUtils.getString(getActivity(), "AccountOid");
xrecyclerview.setLayoutManager(new LinearLayoutManager(getActivity()));
adapter = new StudyXrecAdapter(getActivity(), mlist);
xrecyclerview.setAdapter(adapter);
xrecyclerview.setLoadingListener(this);
adapter.setTurnTo(this);
// scroll.setNestedScrollingEnabled(false);
xrecyclerview.setNestedScrollingEnabled(false);
scroll.setNestedScrollingEnabled(true);
// int max = Collections.max(arr);
LinearLayoutManager manager = new LinearLayoutManager(getActivity());
manager.setOrientation(LinearLayoutManager.HORIZONTAL);
rvReadTime.setLayoutManager(manager);
xrcAdapter = new StudyTimeXrcAdapter(getActivity(), day, time, max);
rvReadTime.setAdapter(xrcAdapter);
HashMap<String, Integer> stringIntegerHashMap = new HashMap<>();
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.RIGHT_DECORATION, 25);//右间距
rvReadTime.addItemDecoration(new RecyclerViewSpacesItemDecoration(stringIntegerHashMap));
scroll.setOnScrollChangeListener(this);
linBack.setOnClickListener(this);
rlUser.setOnClickListener(this);
imgUser.setOnClickListener(this);
rlBody.setOnClickListener(this);
}
@Override
public void initData() {
mPresenter.getPresenter(4, 1, resumeOid);
mPresenter.getPresenter(4, 2, resumeOid, String.valueOf(pageIndex), String.valueOf(pageSize));
mPresenter.getPresenter(4, 3, resumeOid);
}
@Override
public CommonPresenter getPresenter() {
return new CommonPresenter();
}
@Override
public LearnModel getModel() {
return new LearnModel();
}
@Override
public void getData(Object o, int api, int intent) {
if (api == 4 && intent == 1) {
MyLearningInfoBean bean = (MyLearningInfoBean) o;
if (bean.getUserName() != null)
tvUser.setText(bean.getUserName());
if (bean.getHeadPic() != null && bean.getHeadPic() != "") {
Glide.with(getActivity()).load(bean.getHeadPic()).into(imgUser);
} else {
String headPic = SharedPrefrenceUtils.getString(getActivity(), "HeadPic");
Glide.with(getActivity()).load(headPic).into(imgUser);
}
if (bean.getTodayDuration() != null)
todayStudy.setText(bean.getTodayDuration());
if (bean.getMaxDuration() != null)
durationStudy.setText(bean.getMaxDuration());
if (bean.getTotalDuration() != null)
totalStudy.setText(bean.getTotalDuration());
}
if (api == 4 && intent == 2) {
LearningRecordDataBean bean = (LearningRecordDataBean) o;
List<LearningRecordDataBean.learnBean> recordLst = bean.getRecordLst();
if (isRefresh) {
mlist.clear();
isRefresh = false;
}
mlist.addAll(recordLst);
adapter.notifyDataSetChanged();
xrecyclerview.loadMoreComplete();
xrecyclerview.refreshComplete();
}
if (api == 4 && intent == 3) {
UserBean bean = (UserBean) o;
List<String> categories = bean.getCategories();
List<String> datas = bean.getDatas();
day.addAll(datas);
time.addAll(categories);
for (int i = 0; i < day.size(); i++) {
arr.add(Integer.valueOf(day.get(i).substring(0, day.get(i).length() - 2)));
}
max = Collections.max(arr);
Log.e("maxValue", max + "");
xrcAdapter = new StudyTimeXrcAdapter(getActivity(), day, time, max);
rvReadTime.setAdapter(xrcAdapter);
// xrcAdapter.notifyDataSetChanged();
}
}
@Override
public void onComplete(int api) {
}
@Override
public void onError(Throwable e, int api) {
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.lin_back:
getActivity().finish();
break;
case R.id.img_user:
case R.id.rl_user:
case R.id.rl_body:
// startActivity(new Intent(getActivity(), InfromationActivity.class));
// MineFragment mineFragment = new MineFragment();
// FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
// transaction.replace(R.id.frame, mineFragment);
// transaction.commit();
// Intent intent = new Intent(getActivity(), MainActivity.class);
// intent.putExtra("Intenttag","4");
// startActivity(intent);
break;
}
}
@Override
public void onScrollToStart() {
// scroll.setNestedScrollingEnabled(false);
scroll.setNestedScrollingEnabled(false);
xrecyclerview.setNestedScrollingEnabled(true);
Log.e("zhangtao", "到顶部了");
}
@Override
public void onScrollToEnd() {
// scroll.setNestedScrollingEnabled(false);
pageIndex++;
mPresenter.getPresenter(4, 2, resumeOid, String.valueOf(pageIndex), String.valueOf(pageSize));
Log.e("zhangtao", "到底部了");
}
@Override
public void turn(String LessonOid) {
Intent intent = new Intent(getActivity(), CourseDetailActivity_Video.class);
intent.putExtra("lessonOid", LessonOid);
startActivity(intent);
}
@Override
public void onRefresh() {
pageIndex = 1;
isRefresh = true;
mPresenter.getPresenter(4, 2, resumeOid, String.valueOf(pageIndex), String.valueOf(pageSize));
// scroll.setNestedScrollingEnabled(false);
xrecyclerview.setNestedScrollingEnabled(false);
scroll.setNestedScrollingEnabled(true);
}
@Override
public void onLoadMore() {
pageIndex++;
mPresenter.getPresenter(4, 2, resumeOid, String.valueOf(pageIndex), String.valueOf(pageSize));
scroll.setNestedScrollingEnabled(true);
}
}