diff --git a/app/src/main/java/com/gh/common/util/CommentUtils.java b/app/src/main/java/com/gh/common/util/CommentUtils.java index 7d9bb57dfd..6d10475050 100644 --- a/app/src/main/java/com/gh/common/util/CommentUtils.java +++ b/app/src/main/java/com/gh/common/util/CommentUtils.java @@ -3,11 +3,15 @@ package com.gh.common.util; import android.annotation.SuppressLint; import android.app.Dialog; import android.content.Context; +import android.graphics.drawable.ColorDrawable; import android.text.TextUtils; +import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.view.Window; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.PopupWindow; import android.widget.TextView; import androidx.annotation.Nullable; @@ -19,6 +23,7 @@ import com.gh.gamecenter.adapter.viewholder.CommentViewHolder; import com.gh.gamecenter.common.callback.SimpleCallback; import com.gh.gamecenter.common.retrofit.BiResponse; import com.gh.gamecenter.common.retrofit.Response; +import com.gh.gamecenter.common.utils.DialogHelper; import com.gh.gamecenter.common.utils.ExtensionsKt; import com.gh.gamecenter.common.utils.ImageUtils; import com.gh.gamecenter.core.utils.DisplayUtils; @@ -45,6 +50,7 @@ import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Locale; +import java.util.Objects; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; @@ -105,7 +111,8 @@ public class CommentUtils { public static void showReportDialog(final CommentEntity commentEntity, final Context context, final boolean showConversation, - final String patch) { + final String patch, + final OnCommentDeleteListener onCommentDeleteListener) { final Dialog dialog = new Dialog(context); LinearLayout container = new LinearLayout(context); @@ -121,6 +128,15 @@ public class CommentUtils { dialogType.add("查看对话"); } + String commentUserId = commentEntity.getUser().getId(); + String userId = UserManager.getInstance().getUserId(); + MeEntity me = commentEntity.getMe(); + boolean isCommentedByUser = Objects.equals(commentUserId, userId); + boolean isContentAuthorOrModerator = me != null && (me.isModerator() || me.isContentAuthor()); + if (isCommentedByUser || isContentAuthorOrModerator) { + dialogType.add("删除"); + } + for (String s : dialogType) { final TextView reportTv = new TextView(context); reportTv.setText(s); @@ -143,11 +159,23 @@ public class CommentUtils { case "投诉": CheckLoginUtils.checkLogin(context, patch + "-投诉", () -> showReportTypeDialog(commentEntity, context)); - break; case "查看对话": context.startActivity(CommentDetailActivity.getIntent(context, commentEntity.getId(), null)); break; + case "删除": + DialogHelper.INSTANCE.showDialog( + context, + "提示", + "删除评论后,评论下所有的回复都将被删除", + "删除", + "取消", + () -> { + deleteComment(context, commentEntity, onCommentDeleteListener); + return null; + } + ); + break; } }); } @@ -158,6 +186,83 @@ public class CommentUtils { } + public static void showMorePopupWindow( + final View anchor, + final CommentEntity commentEntity, + final boolean showConversation, + final String patch, + final OnCommentDeleteListener onCommentDeleteListener + ) { + Context context = anchor.getContext(); + LayoutInflater inflater = LayoutInflater.from(context); + View contentView = inflater.inflate(R.layout.layout_popup_container, null); + PopupWindow popupWindow = new PopupWindow( + contentView, + ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ); + popupWindow.setBackgroundDrawable(new ColorDrawable(0)); + popupWindow.setTouchable(true); + popupWindow.setFocusable(true); + popupWindow.setOutsideTouchable(true); + + LinearLayout container = contentView.findViewById(R.id.container); + List dialogType = new ArrayList<>(); + dialogType.add("复制"); + dialogType.add("投诉"); + + if (commentEntity.getParent() != null && showConversation) { + dialogType.add("查看对话"); + } + + String commentUserId = commentEntity.getUser().getId(); + String userId = UserManager.getInstance().getUserId(); + MeEntity me = commentEntity.getMe(); + boolean isCommentedByUser = Objects.equals(commentUserId, userId); + boolean isContentAuthorOrModerator = me != null && (me.isModerator() || me.isContentAuthor()); + if (isCommentedByUser || isContentAuthorOrModerator) { + dialogType.add("删除"); + } + + for (String s : dialogType) { + View itemView = inflater.inflate(R.layout.layout_popup_option_item, container, false); + TextView reportTv = itemView.findViewById(R.id.hint_text); + reportTv.setText(s); + container.addView(itemView); + + reportTv.setOnClickListener(v -> { + popupWindow.dismiss(); + switch (reportTv.getText().toString()) { + case "复制": + copyText(commentEntity.getContent(), context); + break; + case "投诉": + CheckLoginUtils.checkLogin(context, patch + "-投诉", + () -> showReportTypeDialog(commentEntity, context)); + break; + case "查看对话": + context.startActivity(CommentDetailActivity.getIntent(context, commentEntity.getId(), null)); + break; + case "删除": + DialogHelper.INSTANCE.showDialog( + context, + "提示", + "删除评论后,评论下所有的回复都将被删除", + "删除", + "取消", + () -> { + deleteComment(context, commentEntity, onCommentDeleteListener); + return null; + } + ); + break; + } + }); + } + + ExtensionsKt.showAutoOrientation(popupWindow, anchor, 0, 0); + } + private static void showReportTypeDialog(final CommentEntity commentEntity, final Context context) { final String[] arrReportType = new String[]{"垃圾广告营销", "恶意攻击谩骂", "淫秽色情信息", "违法有害信息", "其它"}; @@ -430,6 +535,28 @@ public class CommentUtils { }); } + public static void deleteComment( + final Context context, + final CommentEntity commentEntity, + final OnCommentDeleteListener listener + ) { + Dialog dialog = DialogUtils.showWaitDialog( + context, + context.getString(R.string.post_dialog_hint) + ); + RetrofitManager.getInstance().getApi() + .deleteComment(commentEntity.getId()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .doFinally(dialog::cancel) + .subscribe(new Response() { + @Override + public void onResponse(@Nullable ResponseBody response) { + listener.onCommentDelete(); + } + }); + } + // 设置评论item 用户相关的view(点赞/头像/用户名) public static void setCommentUserView(Context mContext, CommentViewHolder holder, CommentEntity entity) { @@ -540,4 +667,8 @@ public class CommentUtils { public interface OnVoteListener { void onVote(); } + + public interface OnCommentDeleteListener { + void onCommentDelete(); + } } diff --git a/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java b/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java index 50c90e634e..89efbabe14 100644 --- a/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/NewsDetailActivity.java @@ -30,7 +30,6 @@ import com.ethanhua.skeleton.ViewSkeletonScreen; import com.gh.base.DownloadToolbarActivity; import com.gh.common.filter.RegionSettingHelper; import com.gh.common.history.HistoryHelper; -import com.gh.gamecenter.feature.utils.ApkActiveUtils; import com.gh.common.util.CheckLoginUtils; import com.gh.common.util.CollectionUtils; import com.gh.common.util.DataCollectionUtils; @@ -41,6 +40,8 @@ import com.gh.gamecenter.adapter.viewholder.DetailViewHolder; import com.gh.gamecenter.common.callback.OnRequestCallBackListener; import com.gh.gamecenter.common.constant.Constants; import com.gh.gamecenter.common.constant.EntranceConsts; +import com.gh.gamecenter.common.eventbus.EBNetworkState; +import com.gh.gamecenter.common.eventbus.EBReuse; import com.gh.gamecenter.common.retrofit.Response; import com.gh.gamecenter.common.utils.ExtensionsKt; import com.gh.gamecenter.common.utils.ShareUtils; @@ -49,15 +50,16 @@ import com.gh.gamecenter.common.view.VerticalItemDecoration; import com.gh.gamecenter.core.utils.ClickUtils; import com.gh.gamecenter.core.utils.DisplayUtils; import com.gh.gamecenter.core.utils.MtaHelper; +import com.gh.gamecenter.entity.NewsDetailEntity; +import com.gh.gamecenter.eventbus.EBConcernChanged; +import com.gh.gamecenter.eventbus.EBAddComment; +import com.gh.gamecenter.eventbus.EBDeleteComment; +import com.gh.gamecenter.eventbus.EBDownloadStatus; +import com.gh.gamecenter.eventbus.EBPackage; import com.gh.gamecenter.feature.entity.GameEntity; import com.gh.gamecenter.feature.entity.MeEntity; -import com.gh.gamecenter.entity.NewsDetailEntity; import com.gh.gamecenter.feature.entity.NewsEntity; -import com.gh.gamecenter.eventbus.EBConcernChanged; -import com.gh.gamecenter.eventbus.EBDownloadStatus; -import com.gh.gamecenter.common.eventbus.EBNetworkState; -import com.gh.gamecenter.eventbus.EBPackage; -import com.gh.gamecenter.common.eventbus.EBReuse; +import com.gh.gamecenter.feature.utils.ApkActiveUtils; import com.gh.gamecenter.newsdetail.NewsDetailAdapter; import com.gh.gamecenter.retrofit.RetrofitManager; import com.lightgame.download.DataWatcher; @@ -557,6 +559,17 @@ public class NewsDetailActivity extends DownloadToolbarActivity implements OnCli }); } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onDeleteComment(EBDeleteComment event) { + adapter.getNewsCommentNum(); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onAddComment(EBAddComment event) { + adapter.getNewsCommentNum(); + } + + @Override public boolean dispatchTouchEvent(MotionEvent ev) { switch (ev.getAction() & MotionEventCompat.ACTION_MASK) { diff --git a/app/src/main/java/com/gh/gamecenter/adapter/CommentDetailAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/CommentDetailAdapter.java index f12e0ff95d..e3b4cef1c3 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/CommentDetailAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/CommentDetailAdapter.java @@ -8,27 +8,31 @@ import android.view.ViewGroup; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView.ViewHolder; -import com.gh.gamecenter.common.constant.ItemViewType; import com.gh.common.util.CheckLoginUtils; import com.gh.common.util.CommentUtils; import com.gh.common.util.DialogUtils; import com.gh.common.util.DirectUtils; -import com.gh.gamecenter.common.utils.ImageUtils; -import com.gh.gamecenter.core.utils.MtaHelper; -import com.gh.gamecenter.common.utils.TextHelper; import com.gh.gamecenter.R; import com.gh.gamecenter.adapter.viewholder.CommentViewHolder; +import com.gh.gamecenter.common.constant.ItemViewType; +import com.gh.gamecenter.common.retrofit.Response; +import com.gh.gamecenter.common.utils.ImageUtils; +import com.gh.gamecenter.common.utils.TextHelper; import com.gh.gamecenter.common.viewholder.FooterViewHolder; +import com.gh.gamecenter.core.utils.MtaHelper; import com.gh.gamecenter.entity.ArticleCommentParent; import com.gh.gamecenter.entity.CommentEntity; -import com.gh.gamecenter.common.retrofit.Response; +import com.gh.gamecenter.eventbus.EBDeleteComment; import com.gh.gamecenter.retrofit.RetrofitManager; import com.lightgame.adapter.BaseRecyclerAdapter; import com.lightgame.utils.Utils; +import org.greenrobot.eventbus.EventBus; + import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; @@ -68,22 +72,34 @@ public class CommentDetailAdapter extends BaseRecyclerAdapter { mDataExceptionView = dataExceptionView; mRecyclerView = recyclerView; - loadData(); + mOnCommentCallBackListener.onCommentCallback(null); + + refresh(); } - public void loadData() { + public void refresh() { + loadData(1); + } + + public void loadMore() { + loadData(mPage + 1); + } + + public void loadData(int page) { if (mIsLoading) return; mIsLoading = true; RetrofitManager.getInstance().getApi() - .getCommentTrace(mCommentId, mPage) + .getCommentTrace(mCommentId, page) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Response>() { @Override public void onResponse(List response) { super.onResponse(response); + if (page == 1) { + mCommentList.clear(); + } mCommentList.addAll(response); - if (response.size() < 20) { mIsOver = true; } @@ -91,7 +107,7 @@ public class CommentDetailAdapter extends BaseRecyclerAdapter { mDataExceptionView.setVisibility(View.GONE); mRecyclerView.setVisibility(View.VISIBLE); notifyItemRangeChanged(0, getItemCount() - 1); - mPage++; + mPage = page; mIsLoading = false; } @@ -201,8 +217,14 @@ public class CommentDetailAdapter extends BaseRecyclerAdapter { }); holder.commentMore.setOnClickListener(v -> - CommentUtils.showReportDialog(commentEntity, - mContext, false, "资讯文章-评论")); + CommentUtils.showMorePopupWindow( + holder.commentMore, + commentEntity, + false, + "资讯文章-评论", + () -> EventBus.getDefault().post(new EBDeleteComment(commentEntity)) + ) + ); holder.commentUserIconDv.setOnClickListener(v -> DirectUtils.directToHomeActivity(mContext, commentEntity.getUser().getId(), "", "文章-评论详情")); holder.commentUserNameTv.setOnClickListener(v -> DirectUtils.directToHomeActivity(mContext, commentEntity.getUser().getId(), "", "文章-评论详情")); @@ -254,4 +276,24 @@ public class CommentDetailAdapter extends BaseRecyclerAdapter { public boolean isLoading() { return mIsLoading; } + + public void notifyCommentRemoved(final CommentEntity entity) { + int positionInComments = getCommentIndexByEntity(mCommentList, entity); + if (positionInComments != -1) { + mCommentList.remove(positionInComments); + notifyItemRemoved(positionInComments); + } + } + + private static int getCommentIndexByEntity( + final List commentList, + final CommentEntity comment + ) { + for (int i = 0; i < commentList.size();i++) { + if (Objects.equals(comment.getId(), commentList.get(i).getId())) { + return i; + } + } + return -1; + } } diff --git a/app/src/main/java/com/gh/gamecenter/adapter/MessageDetailAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/MessageDetailAdapter.java index 78365bb06b..7c5e3659ff 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/MessageDetailAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/MessageDetailAdapter.java @@ -42,6 +42,7 @@ import com.gh.gamecenter.databinding.NewsDigestItemBinding; import com.gh.gamecenter.entity.ArticleCommentParent; import com.gh.gamecenter.entity.CommentEntity; import com.gh.gamecenter.entity.ConcernEntity; +import com.gh.gamecenter.eventbus.EBDeleteComment; import com.gh.gamecenter.manager.VisitManager; import com.gh.gamecenter.common.retrofit.JSONObjectResponse; import com.gh.gamecenter.common.retrofit.OkHttpCache; @@ -50,12 +51,14 @@ import com.gh.gamecenter.retrofit.RetrofitManager; import com.lightgame.adapter.BaseRecyclerAdapter; import com.lightgame.utils.Utils; +import org.greenrobot.eventbus.EventBus; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.atomic.AtomicBoolean; @@ -151,6 +154,7 @@ public class MessageDetailAdapter extends BaseRecyclerAdapter { return; } if (isRefresh) { + isOver = false; mNormalCommentList.clear(); mPage = 1; } @@ -467,8 +471,14 @@ public class MessageDetailAdapter extends BaseRecyclerAdapter { }); holder.commentMore.setOnClickListener(v -> - CommentUtils.showReportDialog(finalCommentEntity, - mContext, true, "资讯文章详情-评论详情")); + CommentUtils.showMorePopupWindow( + holder.commentMore, + finalCommentEntity, + true, + "资讯文章详情-评论详情", + () -> EventBus.getDefault().post(new EBDeleteComment(finalCommentEntity)) + ) + ); holder.commentUserNameTv.setOnClickListener(v -> DirectUtils.directToHomeActivity(mContext, finalCommentEntity.getUser().getId(), mEntrance, "文章-评论详情")); holder.commentUserIconDv.setOnClickListener(v -> DirectUtils.directToHomeActivity(mContext, finalCommentEntity.getUser().getId(), mEntrance, "文章-评论详情")); @@ -524,6 +534,42 @@ public class MessageDetailAdapter extends BaseRecyclerAdapter { }); } + public void notifyCommentRemoved(final CommentEntity entity) { + + if (mHotCommentList.size() > 0) { + int positionInHotComments = getCommentIndexByEntity(mHotCommentList, entity); + if (positionInHotComments != -1) {// 如果在热门评论中存在要被删除的评论,则将此评论移除 + mHotCommentList.remove(positionInHotComments); + } + } + + if (mNormalCommentList.size() > 0) { + int positionInNormalComments = getCommentIndexByEntity(mNormalCommentList, entity); + if (positionInNormalComments != -1) {// 如果在热门评论中存在要被删除的评论,则将此评论移除 + mNormalCommentList.remove(positionInNormalComments); + } + } + + if (mConcernEntity != null) { + int commentNum = mConcernEntity.getCommentnum(); + mConcernEntity.setCommentnum(commentNum - 1); + } + + notifyDataSetChanged(); + } + + private static int getCommentIndexByEntity( + final List commentList, + final CommentEntity comment + ) { + for (int i = 0; i < commentList.size();i++) { + if (Objects.equals(comment.getId(), commentList.get(i).getId())) { + return i; + } + } + return -1; + } + private void statNewsViews(final String news_id) { RetrofitManager.getInstance().getApi().postArticleVisit(news_id) .subscribeOn(Schedulers.io()) @@ -587,7 +633,7 @@ public class MessageDetailAdapter extends BaseRecyclerAdapter { } public void addCommentCount() { - mConcernEntity.setCommentnum(mConcernEntity.getCommentnum()); + mConcernEntity.setCommentnum(mConcernEntity.getCommentnum() + 1); notifyDataSetChanged(); } diff --git a/app/src/main/java/com/gh/gamecenter/eventbus/EBAddComment.java b/app/src/main/java/com/gh/gamecenter/eventbus/EBAddComment.java new file mode 100644 index 0000000000..01ad4ecda3 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/eventbus/EBAddComment.java @@ -0,0 +1,3 @@ +package com.gh.gamecenter.eventbus; + +public class EBAddComment {} diff --git a/app/src/main/java/com/gh/gamecenter/info/ConcernAdapter.java b/app/src/main/java/com/gh/gamecenter/info/ConcernAdapter.java index 6b4f17c5a2..6abdcd1e6a 100644 --- a/app/src/main/java/com/gh/gamecenter/info/ConcernAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/info/ConcernAdapter.java @@ -263,7 +263,7 @@ class ConcernAdapter extends BaseRecyclerAdapter { } // 获取新闻评论数 - private void getNewsCommentnum(final List list) { + public void getNewsCommentnum(final List list) { if (list == null || list.isEmpty()) { return; } @@ -508,6 +508,10 @@ class ConcernAdapter extends BaseRecyclerAdapter { return null; } + public List getConcernList() { + return concernList; + } + public List getLibaoStatusList() { return libaoStatusList; } diff --git a/app/src/main/java/com/gh/gamecenter/info/ConcernFragment.java b/app/src/main/java/com/gh/gamecenter/info/ConcernFragment.java index 31082b8bd8..391323fedd 100644 --- a/app/src/main/java/com/gh/gamecenter/info/ConcernFragment.java +++ b/app/src/main/java/com/gh/gamecenter/info/ConcernFragment.java @@ -20,6 +20,8 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.gh.gamecenter.common.callback.OnRequestCallBackListener; import com.gh.gamecenter.common.base.activity.ToolBarActivity; import com.gh.common.filter.RegionSettingHelper; +import com.gh.gamecenter.eventbus.EBAddComment; +import com.gh.gamecenter.eventbus.EBDeleteComment; import com.gh.gamecenter.feature.utils.ApkActiveUtils; import com.gh.common.util.CheckLoginUtils; import com.gh.common.util.DataCollectionUtils; @@ -386,6 +388,16 @@ public class ConcernFragment extends ToolbarFragment implements SwipeRefreshLayo } } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onAddComment(EBAddComment event) { + mAdapter.getNewsCommentnum(mAdapter.getConcernList()); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onDeleteComment(EBDeleteComment event) { + mAdapter.getNewsCommentnum(mAdapter.getConcernList()); + } + @Override public void onRefresh() { postDelayedRunnable(mRunnable, 1000); diff --git a/app/src/main/java/com/gh/gamecenter/message/MessageDetailFragment.java b/app/src/main/java/com/gh/gamecenter/message/MessageDetailFragment.java index c6f281bf6c..568a7b9488 100644 --- a/app/src/main/java/com/gh/gamecenter/message/MessageDetailFragment.java +++ b/app/src/main/java/com/gh/gamecenter/message/MessageDetailFragment.java @@ -44,24 +44,32 @@ import com.gh.gamecenter.entity.CommentEntity; import com.gh.gamecenter.entity.CommentnumEntity; import com.gh.gamecenter.entity.ConcernEntity; import com.gh.gamecenter.entity.ViewsEntity; +import com.gh.gamecenter.eventbus.EBAddComment; +import com.gh.gamecenter.eventbus.EBDeleteComment; import com.gh.gamecenter.login.entity.UserInfoEntity; import com.gh.gamecenter.login.user.UserManager; import com.gh.gamecenter.manager.CommentManager; import com.gh.gamecenter.retrofit.RetrofitManager; +import com.gh.gamecenter.retrofit.service.ApiService; import com.halo.assistant.HaloApp; import com.lightgame.listeners.OnBackPressedListener; import com.lightgame.utils.Util_System_Keyboard; import com.lightgame.utils.Utils; +import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import java.util.Arrays; import java.util.List; +import java.util.function.BiFunction; +import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.functions.Function3; import io.reactivex.schedulers.Schedulers; import retrofit2.HttpException; @@ -199,46 +207,34 @@ public class MessageDetailFragment extends ToolbarFragment implements OnCommentC mBinding.shadowView.setOnClickListener(this); } - public void getCommentNum() { - RetrofitManager.getInstance().getApi() - .getNewsCommentnum(newsId, Utils.getTime(getContext())) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response>() { - - @Override - public void onResponse(List response) { - super.onResponse(response); - if (response.size() > 0) { - if (!TextUtils.isEmpty(mConcernEntity.getId())) { - commentNum = response.get(0).getNum(); - mConcernEntity.setCommentnum(commentNum); - adapter.notifyItemChanged(0); - } + private void getConcernDigest() { + ApiService apiService = RetrofitManager.getInstance().getApi(); + Observable.zip( + apiService.getNewsRichDigest(newsId), + apiService.getArticlesVisits(UrlFilterUtils.getFilterQuery("article_ids", newsId)), + apiService.getNewsCommentnum(newsId, Utils.getTime(getContext())), + (concernEntity, viewsEntities, commentNumEntities) -> { + if (commentNumEntities.size() > 0) { + if (!TextUtils.isEmpty(concernEntity.getId())) { + concernEntity.setCommentnum(commentNumEntities.get(0).getNum()); } } - }); - } - private void getConcernDigest() { - RetrofitManager.getInstance().getApi().getNewsRichDigest(newsId) + if (viewsEntities.size() > 0) { + concernEntity.setViews(viewsEntities.get(0).getViews()); + } + + return concernEntity; + }) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Response() { @Override public void onResponse(ConcernEntity response) { mConcernEntity = response; - if (commentNum == -1) { - getCommentNum(); - } else { - mConcernEntity.setCommentnum(commentNum); - } - + commentNum = mConcernEntity.getCommentnum(); adapter.addConcernEntity(mConcernEntity); - adapter.notifyDataSetChanged(); adapter.addHotComment(); - getNewsViews(); - if (commentNum == 0) { setSoftInput(true); } @@ -251,22 +247,6 @@ public class MessageDetailFragment extends ToolbarFragment implements OnCommentC }); } - private void getNewsViews() { - RetrofitManager.getInstance().getApi() - .getArticlesVisits(UrlFilterUtils.getFilterQuery("article_ids", newsId)) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Response>() { - @Override - public void onResponse(List viewsEntities) { - if (viewsEntities.size() > 0) { - mConcernEntity.setViews(viewsEntities.get(0).getViews()); - adapter.notifyItemChanged(0); - } - } - }); - } - //软键盘控制 private void setSoftInput(boolean isShow) { if (isShow) { @@ -297,6 +277,17 @@ public class MessageDetailFragment extends ToolbarFragment implements OnCommentC } } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onDeleteComment(EBDeleteComment event) { + adapter.notifyCommentRemoved(event.commentEntity); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onAddComment(EBAddComment event) { + commentNum = -1; + getConcernDigest(); + } + @Override public void onClick(View view) { switch (view.getId()) { @@ -375,6 +366,8 @@ public class MessageDetailFragment extends ToolbarFragment implements OnCommentC //修改评论缓存 CommentManager.updateOkhttpCacheForId(getContext(), newsId); CommentManager.updateOkhttpCache(getContext(), newsId); + // 发送评论更新通知 + EventBus.getDefault().post(new EBAddComment()); adapter.notifyItemInserted(adapter.getHotCommentListSize() + 2); adapter.notifyItemChanged(adapter.getItemCount() - 1); //刷新脚布局高度 } else { diff --git a/app/src/main/java/com/gh/gamecenter/newsdetail/NewsDetailAdapter.java b/app/src/main/java/com/gh/gamecenter/newsdetail/NewsDetailAdapter.java index 287205539e..2510b599f9 100644 --- a/app/src/main/java/com/gh/gamecenter/newsdetail/NewsDetailAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/newsdetail/NewsDetailAdapter.java @@ -64,6 +64,7 @@ import com.gh.gamecenter.databinding.GamedetailItemNewsBinding; import com.gh.gamecenter.databinding.NewsDetailCommentBinding; import com.gh.gamecenter.databinding.NewsdetailItemContentBinding; import com.gh.gamecenter.databinding.NewsdetailItemGameBinding; +import com.gh.gamecenter.eventbus.EBDeleteComment; import com.gh.gamecenter.feature.entity.ApkEntity; import com.gh.gamecenter.entity.ArticleCommentParent; import com.gh.gamecenter.feature.entity.ColorEntity; @@ -77,9 +78,12 @@ import com.gh.gamecenter.retrofit.RetrofitManager; import com.lightgame.adapter.BaseRecyclerAdapter; import com.lightgame.utils.Utils; +import org.greenrobot.eventbus.EventBus; + import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -579,8 +583,16 @@ public class NewsDetailAdapter extends BaseRecyclerAdapter { return true; }); viewHolder.commentMore.setOnClickListener(v -> - CommentUtils.showReportDialog(commentEntity, - mContext, true, "资讯文章详情-评论")); + CommentUtils.showMorePopupWindow( + viewHolder.commentMore, + commentEntity, + true, + "资讯文章详情-评论", + () -> { + EventBus.getDefault().post(new EBDeleteComment(commentEntity)); + } + ) + ); viewHolder.commentUserNameTv.setOnClickListener(v -> DirectUtils.directToHomeActivity(mContext, commentEntity.getUser().getId(), mEntrance, "文章-评论列表")); viewHolder.commentUserIconDv.setOnClickListener(v -> DirectUtils.directToHomeActivity(mContext, commentEntity.getUser().getId(), mEntrance, "文章-评论列表")); @@ -679,10 +691,8 @@ public class NewsDetailAdapter extends BaseRecyclerAdapter { @Override public void onResponse(List response) { - if (response.size() > 0 && response.get(0).getNum() > 0) { - mCommentNum = response.get(0).getNum(); - getNewsHotComment(); - } + mCommentNum = response.get(0).getNum(); + getNewsHotComment(); } @Override @@ -726,9 +736,9 @@ public class NewsDetailAdapter extends BaseRecyclerAdapter { public void onResponse(List response) { if (response.size() >= 1) { mIsHotComment = false; - mCommentEntityList = response; - notifyDataSetChanged(); } + mCommentEntityList = response; + notifyDataSetChanged(); } }); } diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java index 4d1f9150c4..96bbf831f8 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java @@ -497,6 +497,12 @@ public interface ApiService { @POST("articles/comments/{comment_id}:vote") Observable postCommentVote(@Path("comment_id") String comment_id); + /** + * 评论点赞 + */ + @POST("articles/comments/{comment_id}:hide") + Observable deleteComment(@Path("comment_id") String comment_id); + /** * 获取新闻评论 */ diff --git a/app/src/main/java/com/halo/assistant/fragment/comment/CommentDetailFragment.java b/app/src/main/java/com/halo/assistant/fragment/comment/CommentDetailFragment.java index 8fcfbf00f9..b6aaeecaf4 100644 --- a/app/src/main/java/com/halo/assistant/fragment/comment/CommentDetailFragment.java +++ b/app/src/main/java/com/halo/assistant/fragment/comment/CommentDetailFragment.java @@ -35,8 +35,13 @@ import com.gh.gamecenter.adapter.OnCommentCallBackListener; import com.gh.gamecenter.entity.CommentEntity; import com.gh.gamecenter.entity.MessageEntity; import com.gh.gamecenter.common.base.fragment.ToolbarFragment; +import com.gh.gamecenter.eventbus.EBAddComment; +import com.gh.gamecenter.eventbus.EBDeleteComment; import com.lightgame.utils.Util_System_Keyboard; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; import org.json.JSONException; import org.json.JSONObject; @@ -122,7 +127,7 @@ public class CommentDetailFragment extends ToolbarFragment implements OnCommentC public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); if (newState == RecyclerView.SCROLL_STATE_IDLE && !mAdapter.isOver() && !mAdapter.isLoading()) { - mAdapter.loadData(); + mAdapter.loadMore(); } } }); @@ -140,6 +145,11 @@ public class CommentDetailFragment extends ToolbarFragment implements OnCommentC requireView().post(() -> mKeyboardHeightProvider.start()); } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onDeleteComment(EBDeleteComment event) { + mAdapter.notifyCommentRemoved(event.commentEntity); + } + @Override public void onResume() { super.onResume(); @@ -180,7 +190,7 @@ public class CommentDetailFragment extends ToolbarFragment implements OnCommentC @Override public void onCommentCallback(CommentEntity entity) { mCommentEntity = entity; - setSoftInput(true); + setSoftInput(mCommentEntity != null); } @Override @@ -215,6 +225,8 @@ public class CommentDetailFragment extends ToolbarFragment implements OnCommentC mCommentDetailCommentEt.setText(""); setSoftInput(false); + mAdapter.refresh(); + EventBus.getDefault().post(new EBAddComment()); } diff --git a/module_common/src/main/java/com/gh/gamecenter/common/utils/DialogHelper.kt b/module_common/src/main/java/com/gh/gamecenter/common/utils/DialogHelper.kt index ebbcbc1ccf..780df67394 100644 --- a/module_common/src/main/java/com/gh/gamecenter/common/utils/DialogHelper.kt +++ b/module_common/src/main/java/com/gh/gamecenter/common/utils/DialogHelper.kt @@ -34,6 +34,7 @@ object DialogHelper { * * uiModificationCallback,可用来手动微调样式的回调,可使用 binding 来修改颜色、文字大小等 */ + @JvmOverloads fun showDialog( context: Context, title: String,