package com.hanju.video.app.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.lcjian.library.util.RefreshLayout;
|
import com.umeng.analytics.MobclickAgent;
|
import com.hanju.video.app.BasicTextHttpResponseHandler;
|
import com.hanju.video.app.HttpApiUtil;
|
import com.hanju.video.app.R;
|
import com.hanju.video.app.entity.Comment;
|
import com.hanju.video.app.entity.VideoDetailInfo;
|
import com.hanju.video.app.entity.VideoInfo;
|
|
import org.apache.http.Header;
|
import org.json.JSONObject;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import de.greenrobot.event.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 RefreshLayout 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 = contentView.findViewById(R.id.tv_no_review);
|
rl_review = contentView.findViewById(R.id.rl_review);
|
lv_review = contentView.findViewById(R.id.lv_review);
|
tv_review_layout = 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 RefreshLayout.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();
|
MobclickAgent.onPageStart("播放详情-评论");
|
EventBus.getDefault().register(this);
|
}
|
|
@Override
|
public void onPause() {
|
super.onPause();
|
MobclickAgent.onPageEnd("播放详情-评论");
|
EventBus.getDefault().unregister(this);
|
}
|
|
public void onEventMainThread(VideoDetailInfo videoDetailInfo) {
|
for (int i = 0; i < mVideoInfo.getVideoDetailList().size(); i++) {
|
if (videoDetailInfo.getId().equals(
|
mVideoInfo.getVideoDetailList().get(i).getId())) {
|
break;
|
}
|
}
|
}
|
|
/**
|
* 获取影片评论列表
|
*/
|
private void getReviewList() {
|
SharedPreferences preferences = tv_no_review.getContext().getSharedPreferences(
|
"user", Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
|
HttpApiUtil.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事件响应
|
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();
|
// }
|
// });
|
//
|
// }
|
//
|
// }
|
}
|