|
|
@@ -0,0 +1,237 @@
|
|
|
+package com.sheep.gamegroup.view.fragment;
|
|
|
+
|
|
|
+import android.support.annotation.NonNull;
|
|
|
+import android.support.v7.widget.AppCompatRatingBar;
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.EditText;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.RelativeLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.scwang.smartrefresh.layout.SmartRefreshLayout;
|
|
|
+import com.scwang.smartrefresh.layout.api.RefreshLayout;
|
|
|
+import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
|
|
|
+import com.sheep.gamegroup.absBase.BaseListActivity2;
|
|
|
+import com.sheep.gamegroup.dateview.DateUtil;
|
|
|
+import com.sheep.gamegroup.model.api.ApiService;
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
+import com.sheep.gamegroup.model.entity.UserComment;
|
|
|
+import com.sheep.gamegroup.model.entity.UserCommentDetail;
|
|
|
+import com.sheep.gamegroup.model.entity.UserCommentReply;
|
|
|
+import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
+import com.sheep.gamegroup.util.ApiJSONUtil;
|
|
|
+import com.sheep.gamegroup.util.DataUtil;
|
|
|
+import com.sheep.gamegroup.util.Jump2View;
|
|
|
+import com.sheep.gamegroup.util.ListUtil;
|
|
|
+import com.sheep.gamegroup.util.RefreshUtil;
|
|
|
+import com.sheep.gamegroup.util.TestUtil;
|
|
|
+import com.sheep.gamegroup.util.TextViewUtil;
|
|
|
+import com.sheep.gamegroup.util.ViewUtil;
|
|
|
+import com.sheep.gamegroup.view.adapter.AdpUserCommentReply;
|
|
|
+import com.sheep.jiuyan.samllsheep.R;
|
|
|
+import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
+
|
|
|
+import butterknife.BindView;
|
|
|
+import rx.Observable;
|
|
|
+import rx.android.schedulers.AndroidSchedulers;
|
|
|
+import rx.schedulers.Schedulers;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by realicing on 2018/11/2.
|
|
|
+ * realicing@sina.com
|
|
|
+ * 用户评论详情界面
|
|
|
+ */
|
|
|
+public class FgtUserCommentDetail extends BaseListFragment3<UserCommentReply> {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getLayoutId() {
|
|
|
+ return R.layout.net_empty_smart_refresh_rv;
|
|
|
+ }
|
|
|
+
|
|
|
+ @BindView(R.id.refresh)
|
|
|
+ SmartRefreshLayout refresh;
|
|
|
+ @BindView(R.id.bottom)
|
|
|
+ RelativeLayout bottom;
|
|
|
+ @Override
|
|
|
+ public void initView() {
|
|
|
+ TitleBarUtils.getInstance().setTitle(mView, "回复详情")
|
|
|
+ .setTitleFinish(mView, activity);
|
|
|
+ smartRefreshLayout = refresh;
|
|
|
+ refresh.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
|
|
|
+ @Override
|
|
|
+ public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
|
|
|
+ loadMoreData();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onRefresh(@NonNull RefreshLayout refreshLayout) {
|
|
|
+ refreshData();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ RefreshUtil.newInstance().publicParameterLoadMore(refresh, activity);
|
|
|
+
|
|
|
+ //头部view
|
|
|
+ initHeaderView();
|
|
|
+
|
|
|
+ //尾部,在无数据时显示
|
|
|
+ footerView = LayoutInflater.from(SheepApp.getInstance()).inflate(R.layout.footer_user_comment_detail, null);
|
|
|
+ //底部可发表评论
|
|
|
+ LayoutInflater.from(SheepApp.getInstance()).inflate(R.layout.bottom_user_comment_detail, bottom);
|
|
|
+ bottom_user_comment_detail_input = bottom.findViewById(R.id.bottom_user_comment_detail_input);
|
|
|
+ bottom.findViewById(R.id.bottom_user_comment_detail_commit).setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ String content = bottom_user_comment_detail_input.getText().toString();
|
|
|
+ commitContent(content);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+// ------------------------------start header------------------------------------
|
|
|
+ private LinearLayout user_comment_detail_game_ll;
|
|
|
+ private TextView user_comment_detail_game_name;
|
|
|
+ private ImageView user_comment_detail_game_icon;
|
|
|
+ private ImageView user_comment_detail_user_avatar;
|
|
|
+ private TextView user_comment_detail_user_name;
|
|
|
+ private TextView user_comment_detail_user_publish_time;
|
|
|
+ private AppCompatRatingBar user_comment_detail_user_publish_score;
|
|
|
+ private TextView user_comment_detail_num1;
|
|
|
+ private TextView user_comment_detail_num2;
|
|
|
+ private TextView user_comment_detail_num3;
|
|
|
+ //初始化headerView
|
|
|
+ private void initHeaderView() {
|
|
|
+ headerView = LayoutInflater.from(SheepApp.getInstance()).inflate(R.layout.header_user_comment_detail, null);
|
|
|
+
|
|
|
+ user_comment_detail_game_ll = headerView.findViewById(R.id.user_comment_detail_game_ll);
|
|
|
+ user_comment_detail_game_name = headerView.findViewById(R.id.user_comment_detail_game_name);
|
|
|
+ user_comment_detail_game_icon = headerView.findViewById(R.id.user_comment_detail_game_icon);
|
|
|
+ user_comment_detail_user_avatar = headerView.findViewById(R.id.user_comment_detail_user_avatar);
|
|
|
+ user_comment_detail_user_name = headerView.findViewById(R.id.user_comment_detail_user_name);
|
|
|
+ user_comment_detail_user_publish_time = headerView.findViewById(R.id.user_comment_detail_user_publish_time);
|
|
|
+ user_comment_detail_user_publish_score = headerView.findViewById(R.id.user_comment_detail_user_publish_score);
|
|
|
+ user_comment_detail_num1 = headerView.findViewById(R.id.user_comment_detail_num1);
|
|
|
+ user_comment_detail_num2 = headerView.findViewById(R.id.user_comment_detail_num2);
|
|
|
+ user_comment_detail_num3 = headerView.findViewById(R.id.user_comment_detail_num3);
|
|
|
+ }
|
|
|
+ //加载数据
|
|
|
+ private void loadHeaderViewData(final UserComment user_comment){
|
|
|
+ user_comment_detail_game_ll.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ //点击游戏
|
|
|
+ if(user_comment != null)
|
|
|
+ Jump2View.getInstance().goPlayGameDetail(activity, user_comment.getApp_id());
|
|
|
+ else
|
|
|
+ G.showToast(R.string.loading_data);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ user_comment_detail_user_publish_score.setMax(10);
|
|
|
+ user_comment_detail_user_publish_score.setProgress(user_comment.getScore());
|
|
|
+ ViewUtil.setText(user_comment_detail_num1, user_comment.getComment());
|
|
|
+ ViewUtil.setText(user_comment_detail_num2, user_comment.getLike());
|
|
|
+ ViewUtil.setText(user_comment_detail_num3, user_comment.getExpression());
|
|
|
+ ViewUtil.setText(user_comment_detail_game_name, user_comment.getApp_name());
|
|
|
+ ViewUtil.setText(user_comment_detail_user_name, user_comment.getNickname());
|
|
|
+ user_comment_detail_user_publish_time.setText(DateUtil.getTimeText(user_comment.getCreate_time()));
|
|
|
+ ViewUtil.setGameImage(user_comment_detail_game_icon, user_comment.getApp_icon());
|
|
|
+ ViewUtil.setAvatar(user_comment_detail_user_avatar, user_comment.getAvatar());
|
|
|
+ TextViewUtil.initIntroView(headerView, user_comment.getShowAll(), "全文");
|
|
|
+ }
|
|
|
+
|
|
|
+// ------------------------------end header------------------------------------
|
|
|
+ //用户评论一个用户对游戏的评论
|
|
|
+ private void commitContent(String content) {
|
|
|
+ if(TestUtil.isDev()) G.showToast("评论内容:" + content);
|
|
|
+ if(content.isEmpty()){
|
|
|
+ G.showToast("评论内容不能为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 发表评论
|
|
|
+ ApiJSONUtil.postGameUserUserComment(user_comment_id, false, content)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ G.showToast(baseMessage);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ G.showToast(baseMessage);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //输入框
|
|
|
+ private EditText bottom_user_comment_detail_input;
|
|
|
+
|
|
|
+ private View headerView;
|
|
|
+ private View footerView;
|
|
|
+
|
|
|
+ private int user_comment_id;
|
|
|
+ public void setUser_comment_id(int user_comment_id) {
|
|
|
+ this.user_comment_id = user_comment_id;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean useSelfEmpty() {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private AdpUserCommentReply adapter;
|
|
|
+ @Override
|
|
|
+ protected RecyclerView.Adapter getAdapter() {
|
|
|
+ //用户评论的回复列表
|
|
|
+ adapter = new AdpUserCommentReply(list);
|
|
|
+ adapter.addHeaderView(headerView);
|
|
|
+ return adapter;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected String getKey(int page, int per_page) {
|
|
|
+ return String.format(Locale.CHINA, "app/game_user/user_comment_detail?page_no=%d&page_size=%d&user_comment_id=%d", page, per_page, user_comment_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected Observable<BaseMessage> getApi(ApiService apiService) {
|
|
|
+ return apiService.getGameUserUserCommentDetail(page, per_page, user_comment_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected List<UserCommentReply> resolveData(BaseMessage baseMessage, int page) {
|
|
|
+ UserCommentDetail userCommentDetail = baseMessage.getData(UserCommentDetail.class);
|
|
|
+ if(page == 0){
|
|
|
+ adapter.setUserComment(userCommentDetail.getUser_comment());
|
|
|
+ loadHeaderViewData(userCommentDetail.getUser_comment());
|
|
|
+ }
|
|
|
+ if(userCommentDetail != null && userCommentDetail.getUser_comment_reply() != null && userCommentDetail.getUser_comment_reply().getReply_list() != null)
|
|
|
+ return userCommentDetail.getUser_comment_reply().getReply_list();
|
|
|
+ return ListUtil.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected Class<UserCommentReply> getTClass() {
|
|
|
+ return UserCommentReply.class;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void updateEmptyView() {
|
|
|
+ if(adapter != null){
|
|
|
+ if(list.isEmpty()) {
|
|
|
+ if(footerView.getParent() == null)//未添加尾部view
|
|
|
+ adapter.addFooterView(footerView);
|
|
|
+ } else {
|
|
|
+ if(footerView.getParent() != null)//已经添加尾部view
|
|
|
+ adapter.removeFooterView(footerView);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|