admin
2021-10-16 988a99f8f8f8e1e123efd29e108dcd0240ad8a33
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
396
package com.weikou.beibeivideo.ui.media;
 
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow.OnDismissListener;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
 
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.lcjian.library.RetainViewFragment;
import com.umeng.analytics.MobclickAgent;
import com.weikou.beibeivideo.BasicTextHttpResponseHandler;
import com.weikou.beibeivideo.BeibeiVideoAPI;
import com.weikou.beibeivideo.R;
import com.weikou.beibeivideo.entity.Comment;
import com.weikou.beibeivideo.entity.VideoDetailInfo;
import com.weikou.beibeivideo.entity.VideoInfo;
import com.weikou.beibeivideo.util.VideoUtil;
import com.weikou.beibeivideo.widget.MySwipeRefreshLayout;
 
import org.apache.http.Header;
import org.greenrobot.eventbus.Subscribe;
import org.json.JSONObject;
 
import java.util.ArrayList;
import java.util.List;
 
import org.greenrobot.eventbus.EventBus;
 
/**
 * 小屏播放-评论
 *
 * @author weikou2015
 */
public class VideoReviewFragment extends RetainViewFragment implements
        OnClickListener {
 
    private TextView tv_no_review;
 
    private VideoInfo mVideoInfo;
 
    private int mCurrentPage = 1;
 
    private VideoReviewAdapter adapter;
 
    private MySwipeRefreshLayout rl_review;
 
    private ListView lv_review;
 
    private List<Comment> mList;
 
    private LinearLayout tv_review_layout;
 
    VideoReviewPopupWindow popupwindow;
 
    public static VideoReviewFragment newInstance(VideoInfo videoInfo,
                                                  int playingPostion) {
        VideoReviewFragment videoReviewFragment = new VideoReviewFragment();
        Bundle args = new Bundle();
        args.putSerializable("video_info", videoInfo);
        args.putInt("playing_position", playingPostion);
        videoReviewFragment.setArguments(args);
        return videoReviewFragment;
    }
 
    @Override
    public int getContentResource() {
        return R.layout.video_review_fragment;
    }
 
    @Override
    public void onCreateView(View contentView, Bundle savedInstanceState) {
        mVideoInfo = (VideoInfo) getArguments().getSerializable("video_info");
        tv_no_review = (TextView) contentView.findViewById(R.id.tv_no_review);
        rl_review = contentView.findViewById(R.id.rl_review);
        lv_review = (ListView) contentView.findViewById(R.id.lv_review);
        tv_review_layout = (LinearLayout) contentView.findViewById(R.id.tv_review_layout);
        mList = new ArrayList<Comment>();
        adapter = new VideoReviewAdapter(getActivity(), getActivity().getApplicationContext(), mList, tv_review_layout);
        lv_review.setAdapter(adapter);
        tv_review_layout.setOnClickListener(this);
        View view = new View(lv_review.getContext());
        lv_review.addHeaderView(view);
        ProgressBar pb = new ProgressBar(lv_review.getContext());
        rl_review.setFooter(pb);
        rl_review.setRefreshing(true);
        rl_review.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mCurrentPage = 1;
                getReviewList();
            }
        });
        rl_review.setOnLoadListener(new MySwipeRefreshLayout.OnLoadListener() {
            @Override
            public void onLoad() {
                mCurrentPage++;
                getReviewList();
            }
        });
        lv_review.postDelayed(new Runnable() {
 
            @Override
            public void run() {
                mCurrentPage = 1;
                getReviewList();
            }
        }, 200);
 
        SharedPreferences preferences1 = tv_no_review.getContext().getSharedPreferences(
                "user", Context.MODE_PRIVATE);
        Editor edit = preferences1.edit();
        edit.putString("review_id", mVideoInfo.getId());
        edit.putString("review_type", mVideoInfo.getThirdType());
        edit.commit();
 
    }
 
    @Override
    public void onResume() {
        super.onResume();
        EventBus.getDefault().register(this);
    }
 
    @Override
    public void onPause() {
        super.onPause();
        EventBus.getDefault().unregister(this);
    }
 
    @Subscribe
    public void onEventMainThread(VideoDetailInfo videoDetailInfo) {
        for (int i = 0; i < VideoUtil.videoEpisodeList.size(); i++) {
            if (videoDetailInfo.getId().equals(
                    VideoUtil.videoEpisodeList.get(i).getId())) {
                break;
            }
        }
    }
 
    /**
     * 获取影片评论列表
     */
    private void getReviewList() {
        SharedPreferences preferences = tv_no_review.getContext().getSharedPreferences(
                "user", Context.MODE_PRIVATE);
        String uid = preferences.getString("uid", "");
 
        BeibeiVideoAPI.getVideoCommentList(tv_no_review.getContext(), uid,
                mVideoInfo.getId(), mVideoInfo.getThirdType(),
                String.valueOf(mCurrentPage),
 
                new BasicTextHttpResponseHandler() {
 
                    @Override
                    public void onSuccessPerfect(int statusCode,
                                                 Header[] headers, JSONObject jsonObject)
                            throws Exception {
 
                        if (jsonObject.optBoolean("IsPost")) {
                            Log.d("TAG", "Review========================="
                                    + jsonObject.optJSONObject("Data")
                                    .toString());
 
                            Gson gson = new GsonBuilder().setFieldNamingPolicy(
                                    FieldNamingPolicy.UPPER_CAMEL_CASE)
                                    .create();
                            // if (mList == null) {
                            // mList = new ArrayList<Comment>();
                            // }
 
                            List<Comment> list = gson.fromJson(jsonObject
                                            .optJSONObject("Data").optJSONArray("data")
                                            .toString(),
                                    new TypeToken<List<Comment>>() {
                                    }.getType());
 
                            if (mCurrentPage == 1) {
                                mList.clear();
                            }
 
                            mList.addAll(list);
                            adapter.notifyDataSetChanged();
 
                            if ((list == null || list.size() == 0)
                                    && mCurrentPage > 1) {
                                Toast.makeText(tv_no_review.getContext(), "没有更多了",
                                        Toast.LENGTH_SHORT).show();
                                mCurrentPage--;
                            }
 
                            if (mList == null || mList.size() == 0) {
                                tv_no_review.setVisibility(View.VISIBLE);
                            } else {
                                tv_no_review.setVisibility(View.GONE);
                            }
                        }
                    }
 
                    @Override
                    public void onFinish() {
                        super.onFinish();
                        rl_review.setRefreshing(false);
                        rl_review.setLoading(false);
                    }
                });
 
    }
 
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_review_layout:
                popupwindow = new VideoReviewPopupWindow(getActivity(),
                        mVideoInfo.getId(), mVideoInfo.getThirdType(), true,
                        "我也来说两句...");
 
                popupwindow.showPopupWindow(getActivity().findViewById(
                        R.id.tv_review_layout));
                tv_review_layout.setVisibility(View.GONE);
                popupwindow.setOnDismissListener(new OnDismissListener() {
 
                    @Override
                    public void onDismiss() {
                        tv_review_layout.setVisibility(View.VISIBLE);
                    }
                });
                break;
 
            default:
                break;
        }
    }
 
    // EventBus事件响应
    @Subscribe
    public void onEventMainThread(Boolean e) {
        if (e) {
            getReviewList();
        }
    }
    /**
     * 自定义popupWindow
     *
     * @author weikou2015
     *
     */
    // public class VideoReviewPopupWindow extends PopupWindow {
    // private LayoutInflater mInflater;
    // private View conentView;
    // private EditText tv_review_edit;
    // private Button tv_review_deliver;
    // private VideoReviewPopupWindow vWindow;
    // private FragmentActivity mContext;
    // private String videoId;// 影片ID
    // private String thirdType;// 影片类型分辨
    //
    // public VideoReviewPopupWindow(final FragmentActivity context,
    // String videoId, String thirdType) {
    // mContext = context;
    // this.videoId = videoId;
    // this.thirdType = thirdType;
    // mInflater = (LayoutInflater) context
    // .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // SharedPreferences preferences = context.getSharedPreferences(
    // "user", Context.MODE_PRIVATE);
    // isLogin = preferences.getBoolean("isLogin", false);
    // conentView = mInflater.inflate(R.layout.video_review_popupwindow,
    // null);
    // this.setContentView(conentView);
    //
    // this.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
    // // 软键盘不会挡着popupwindow
    // this.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    // this.setWidth(LayoutParams.MATCH_PARENT);
    // this.setHeight(LayoutParams.WRAP_CONTENT);
    //
    // this.setFocusable(true);
    // this.setOutsideTouchable(false);
    // ColorDrawable dw = new ColorDrawable(0000000000);
    // this.setBackgroundDrawable(dw);
    // this.update();
    //
    // tv_review_edit = (EditText) conentView
    // .findViewById(R.id.tv_review_edit);
    // tv_review_deliver = (Button) conentView
    // .findViewById(R.id.tv_review_deliver);
    //
    // tv_review_deliver.setOnClickListener(new OnClickListener() {
    //
    // @Override
    // public void onClick(View v) {
    // dismiss();
    // if (isLogin) {
    // setDeliver();
    // } else {
    // setLogin();
    // }
    // }
    // });
    //
    // tv_review_edit
    // .setOnFocusChangeListener(new OnFocusChangeListener() {
    //
    // @Override
    // public void onFocusChange(View v, boolean hasFocus) {
    // if (hasFocus) {
    // setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    // }
    // }
    // });
    //
    // }
    //
    // /**
    // * 显示popupWindow
    // *
    // * @param parent
    // */
    // public void showPopupWindow(View parent) {
    // if (!this.isShowing()) {
    // // this.showAsDropDown(parent, 0, 0, Gravity.BOTTOM);
    // this.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
    // openKeyboard(new Handler(), 200);
    // } else {
    // this.dismiss();
    // }
    // }
    //
    // /**
    // * 打开软键盘
    // */
    // private void openKeyboard(Handler mHandler, int s) {
    // mHandler.postDelayed(new Runnable() {
    // @Override
    // public void run() {
    // InputMethodManager imm = (InputMethodManager) mContext
    // .getSystemService(Context.INPUT_METHOD_SERVICE);
    // imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    // }
    // }, s);
    // }
    //
    // /**
    // * 发布评论还是登录
    // */
    // private boolean isLogin = false;// false为需要登录,true为已经为登录状态
    //
    // /**
    // * 登录
    // */
    // private void setLogin() {
    // mContext.startActivity(new Intent(mContext, LoginActivity.class));
    // }
    //
    // /**
    // * 发布评论内容
    // */
    // private void setDeliver() {
    // SharedPreferences preferences = mContext.getSharedPreferences(
    // "user", Context.MODE_PRIVATE);
    // String uid = preferences.getString("uid", "");
    // BeibeiVideoAPI.Comment(mContext, uid, videoId, thirdType,
    // tv_review_edit.getEditableText().toString(),
    // new BasicTextHttpResponseHandler() {
    //
    // @Override
    // public void onSuccessPerfect(int statusCode,
    // Header[] headers, JSONObject jsonObject)
    // throws Exception {
    // }
    //
    // @Override
    // public void onFinish() {
    // super.onFinish();
    // Toast.makeText(getActivity(), "评论发布成功!!!",
    // Toast.LENGTH_SHORT).show();
    // }
    // });
    //
    // }
    //
    // }
}