FindNestedSubscriptionFragment.java
14.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
package com.cnlive.goldenline.ui.fragment;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.cnlive.goldenline.R;
import com.cnlive.goldenline.api.CmsAPI;
import com.cnlive.goldenline.model.FindSubscribeBean;
import com.cnlive.goldenline.model.request.AllSubscribeRequest;
import com.cnlive.goldenline.model.request.FindSubscribeRequest;
import com.cnlive.goldenline.model.response.DianBoListResponse;
import com.cnlive.goldenline.model.response.bean.VideoDemandBean;
import com.cnlive.goldenline.ui.activity.AllSubscriptionActivity;
import com.cnlive.goldenline.ui.activity.TheatreInfoActivity;
import com.cnlive.goldenline.ui.adapter.FindAdapter;
import com.cnlive.goldenline.ui.adapter.ViewType;
import com.cnlive.goldenline.ui.model.RecyclerViewNormalBean;
import com.cnlive.goldenline.ui.widget.PlayerListRecyclerView;
import com.cnlive.goldenline.ui.widget.pull2refresh.PullToRefreshLayout;
import com.cnlive.goldenline.util.LogUtils;
import com.cnlive.goldenline.util.RestAdapterUtils;
import com.cnlive.goldenline.util.ShareSdkUtil;
import com.cnlive.goldenline.util.StringUtils;
import com.cnlive.goldenline.util.UserService;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;
/**
* 我的订阅
* FileName:com.cnlive.goldenline.ui.fragment.FindNestedSubscriptionFragment.java
* Created on 2017/2/21
* Version V1.0
*/
public class FindNestedSubscriptionFragment extends BaseVideoTypeListFragment implements PullToRefreshLayout.OnPullListener {
private static final String TAG = "FindNestedSubscriptionFragment";
/**
* 用于存储订阅号list
*/
private List<RecyclerViewNormalBean> dataList = new ArrayList<>();
private List<VideoDemandBean> playList = new ArrayList<>();
private RecyclerViewNormalBean header;
@Nullable
@BindView(R.id.list)
PlayerListRecyclerView mReyclerView;
@Nullable
@BindView(R.id.pull_to_refresh)
PullToRefreshLayout pullToRefreshLayout;
private FindAdapter adapter;
private LinearLayout linear_addview;
private TextView tv_alls_num;
private View rootView;
private UserService mUserService;
/**
* 用于存储订阅号 url
*/
//private ArrayList<AnchorItem> urlList = new ArrayList<>();
private int page = 1;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = super.onCreateView(inflater, container, savedInstanceState);
if (mEmptyView == null)
mEmptyView = (RelativeLayout) rootView.findViewById(R.id.empty);
return rootView;
}
@Override
protected void setupView() {
super.setupView();
mPullToRefreshLayout.setOnPullListener(this);
View headView = LayoutInflater.from(getActivity()).inflate(R.layout.layout_subscription_headview, null);
findHeadView(headView);
adapter = new FindAdapter(getActivity());
mReyclerView.setHasFixedSize(true);
adapter.setItemClickListener(this);
mReyclerView.setLayoutManager(new GridLayoutManager(getAttchActivity(), 4));
adapter.updateItems(dataList);
adapter.setHeadView(headView);
mReyclerView.setAdapter(adapter);
}
//是否在下拉刷新
private boolean isRefresh = false;
@Override
protected PlayerListRecyclerView getFragmentRecyclerView() {
return mReyclerView;
}
@Override
protected PullToRefreshLayout getFragmentRefreshLayout() {
return mPullToRefreshLayout;
}
/**
* 初始化 头布局
*
* @param headView
*/
private void findHeadView(View headView) {
mUserService = new UserService(getActivity());
if (headView == null) return;
tv_alls_num = (TextView) headView.findViewById(R.id.tv_alls_num);
linear_addview = (LinearLayout) headView.findViewById(R.id.linear_addview);
addLinearData();
tv_alls_num.setOnClickListener(this);
header = new RecyclerViewNormalBean(null, ViewType.TYPE_LIST_HEADER);
dataList.add(header);
}
//Fragment切换时刷新数据,两个方法都要重写,同时加一个标记,判断数据是否已经被刷新,没有被刷新则刷新,否则不刷新
private boolean isGetData = false;
@Override
public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
// 进入当前Fragment
if (enter && !isGetData) {
isGetData = true;
// 这里可以做网络请求或者需要的数据刷新操作
adapter.notifyDataSetChanged();
} else {
isGetData = false;
}
return super.onCreateAnimation(transit, enter, nextAnim);
}
@Override
public void onResume() {
super.onResume();
if (!isGetData) {
// 这里可以做网络请求或者需要的数据刷新操作
addLinearData();
adapter.notifyDataSetChanged();
isGetData = true;
}
}
@Override
public void onPause() {
super.onPause();
isGetData = false;
}
/**
* 添加订阅号布局
*/
//private int theatreId;
private List<FindSubscribeBean.DataBean> subscribeList;
private void addLinearData() {
String uid = mUserService.getUserInfo().getCn_uid();
RestAdapterUtils.getRestAPI(CmsAPI.class).getFindSubscribe(new FindSubscribeRequest(5, StringUtils.isEmpty(uid) ? " " : uid), new Callback<FindSubscribeBean>() {
@Override
public void success(FindSubscribeBean findSubscribeBean, Response response) {
subscribeList = findSubscribeBean.getData();
if (subscribeList != null) {
//theatreId = subscribeList.get(postiton).getTheatreId();
//在我的订阅页面最多只展示5个
int size = subscribeList.size() < 5 ? subscribeList.size() : 5;
if (linear_addview != null)
linear_addview.removeAllViews();
for (int i = size - 1; i >= 0; i--) {
linear_addview.addView(formatView(i));
tv_alls_num.setText("全部(" + subscribeList.size() + ")");
}
}
}
@Override
public void failure(RetrofitError error) {
}
});
/* for (int i = 0; i < 6; i++) {
AnchorItem it = new AnchorItem();
it.setAddress("name" + i);
it.setAvatar("http://shtml.asia-cloud.com/ZZSY/touxiang1.png");
urlList.add(it);
}
for (int i = 0; i < 6; i++) {
linear_addview.addView(formatView(i));
// linear_addview.addView(formatView(dataList.get(i)));
}*/
}
/**
* 赋值
* <p>
* // * @param str
*
* @param i
* @return
*/
private View formatView(final int i) {
View v = LayoutInflater.from(getActivity()).inflate(R.layout.layout_singletextima, null);
ImageView ima = (ImageView) v.findViewById(R.id.image_head);
final TextView text = (TextView) v.findViewById(R.id.text_name);
// if (i == 0) {
// Glide.with(getActivity()).load("http://shtml.asia-cloud.com/ZZSY/touxiang1.png").bitmapTransform(new CropCircleTransformation(getActivity())).into(ima);
// } else if (i == 1) {
// Glide.with(getActivity()).load("http://shtml.asia-cloud.com/ZZSY/touxiang2.png").bitmapTransform(new CropCircleTransformation(getActivity())).into(ima);
// } else if (i == 3) {
// Glide.with(getActivity()).load("http://shtml.asia-cloud.com/ZZSY/touxiang3.png").bitmapTransform(new CropCircleTransformation(getActivity())).into(ima);
// } else if (i == 2) {
// Glide.with(getActivity()).load("http://shtml.asia-cloud.com/ZZSY/touxiang4.png").bitmapTransform(new CropCircleTransformation(getActivity())).into(ima);
// } else {
// Glide.with(getActivity()).load("http://shtml.asia-cloud.com/ZZSY/touxiang2.png").bitmapTransform(new CropCircleTransformation(getActivity())).into(ima);
// }
text.setText(subscribeList.get(i).getTheatreName());
//text.setText("name" + i);
// Glide.with(getActivity()).load(str).error(R.mipmap.ic_launcher).into(ima);
ima.setImageURI(Uri.parse(subscribeList.get(i).getTheatreCover()));
//Glide.with(getActivity()).load(subscribeList.get(i).getTheatreCover()).placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher).transform(new GlideRoundTransform(getActivity(), 2)).into(ima);
ima.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TheatreInfoActivity.startActivity(getActivity(), subscribeList.get(i).getTheatreId());
}
});
return v;
}
@Override
public void onItemClick(View view, Object o, int position, int eventType) {
super.onItemClick(view, o, position, eventType);
}
@Override
protected void theatrePortraitClick(VideoDemandBean playBean) {
if (playBean.getVdTheatreId()!=0)
TheatreInfoActivity.startActivity(getActivity(), playBean.getVdTheatreId());
}
@Override
public void onClick(View v) {
super.onClick(v);
switch (v.getId()) {
case R.id.tv_alls_num://全部订阅号
/*if (urlList != null && !urlList.isEmpty()) {
AllSubscriptionActivity.startActivity(getActivity(), urlList, 1);
}*/
if (subscribeList != null && !subscribeList.isEmpty()) {
AllSubscriptionActivity.startActivity(getActivity());
}
break;
default:
break;
}
}
@Override
protected int getLayoutRes() {
return R.layout.fragment_mysubcription;
}
@Override
protected void listShareClick(VideoDemandBean playBean) {
super.listShareClick(playBean);
ShareSdkUtil.selectSharePlatform(getActivity(), R.id.ll_sub, ShareSdkUtil.SHARE_VIDEO,
playBean.getVdShowTitle(),
"正在上演", //说明
playBean.getVdCover(),
playBean.getVdShareUrl());
}
private void fetchVideoDemandList() {
LogUtils.LOGE(TAG + " fetchVideoDemandList page = " + page);
RestAdapterUtils.getRestAPI(CmsAPI.class).getAllSubscribe(new AllSubscribeRequest(3, page, "", "", mUserService.getUserInfo().getCn_uid()), new Callback<DianBoListResponse>() {
@Override
public void success(DianBoListResponse t, Response response) {
isRefresh = false;
LogUtils.LOGE(TAG + " success t.getCode() = " + t.getCode() + " t.getList.size = " + (t.getRecordList() == null ? " 0 " : t.getRecordList().size()));
if(page == 1)
mPullToRefreshLayout.refreshFinish(PullToRefreshLayout.SUCCEED);
else
mPullToRefreshLayout.loadmoreFinish(PullToRefreshLayout.SUCCEED);
if (t.getCode() == 0) {
List<VideoDemandBean> list = t.getRecordList();
// LogUtils.LOGE(TAG + " success list = " + list);
if (page == 1) {
if (dataList == null)
dataList = new ArrayList<>();
if (playList == null)
playList = new ArrayList<>();
playList.clear();
dataList.clear();
header = new RecyclerViewNormalBean(null, ViewType.TYPE_LIST_HEADER);
dataList.add(header);
enableLoadMore = true;
}
if (list != null && list.size() > 0) {
playList.addAll(list);
List<RecyclerViewNormalBean> tmpList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
VideoDemandBean bean = list.get(i);
RecyclerViewNormalBean data = new RecyclerViewNormalBean();
data.setT(bean);
data.setDataType(ViewType.TYPE_LIST_PLAYER);
tmpList.add(data);
}
dataList.addAll(tmpList);
if (page == 1) {
adapter.updateItems(dataList);
} else
adapter.addItems(tmpList);
page++;
} else {
mPullToRefreshLayout.setPullUpEnable(false);
enableLoadMore = false;
}
adapter.notifyDataSetChanged();
onRefreshCallback(true);
} else {
onRefreshCallback(false);
showConnectionRetry();
//ToastUtil.showToast(t.getErrMsg());
}
}
@Override
public void failure(RetrofitError error) {
onRefreshCallback(false);
error.printStackTrace();
if(page==1&&isRefresh){
pullToRefreshLayout.refreshFinish(PullToRefreshLayout.FAIL);
//showConnectionRetry();
}else if(page==1&&!isRefresh){
//pullToRefreshLayout.refreshFinish(PullToRefreshLayout.FAIL);
showConnectionRetry();
}else {
pullToRefreshLayout.loadmoreFinish(PullToRefreshLayout.FAIL);
}
}
});
}
@Override
protected void onLoadData() {
super.onLoadData();
LogUtils.LOGE(TAG + " onLoadData ");
addLinearData();
fetchVideoDemandList();
}
@Override
protected void onInitLoadData(Object pageData) {
}
@Override
public void onRefresh(PullToRefreshLayout pullToRefreshLayout) {
isRefresh = true;
LogUtils.LOGE(TAG + " onRefresh ");
page = 1;
mPullToRefreshLayout.setPullUpEnable(true);
onLoadData();
}
@Override
public void onLoadMore(PullToRefreshLayout pullToRefreshLayout) {
LogUtils.LOGE(TAG + " onLoadMore enableLoadMore = " + enableLoadMore);
onLoadData();
}
}