diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index be8edacbf4..bf4da9f4e2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -369,7 +369,7 @@ android:screenOrientation = "portrait" /> diff --git a/app/src/main/java/com/gh/common/util/CommentHelper.kt b/app/src/main/java/com/gh/common/util/CommentHelper.kt new file mode 100644 index 0000000000..83c7141a19 --- /dev/null +++ b/app/src/main/java/com/gh/common/util/CommentHelper.kt @@ -0,0 +1,203 @@ +package com.gh.common.util + +import android.app.Dialog +import android.content.Context +import android.graphics.Color +import android.support.v4.content.ContextCompat +import android.text.TextUtils +import android.view.Window +import android.widget.LinearLayout +import android.widget.TextView +import com.gh.common.util.CommentUtils.copyText +import com.gh.gamecenter.CommentDetailActivity +import com.gh.gamecenter.MessageDetailActivity +import com.gh.gamecenter.R +import com.gh.gamecenter.adapter.OnCommentCallBackListener +import com.gh.gamecenter.entity.CommentEntity +import com.lightgame.utils.Utils +import org.json.JSONException +import org.json.JSONObject + +object CommentHelper { + + // TODO 合并这两个方法的共同部分 + @JvmStatic + fun showCommunityArticleCommentOptions( + context: Context, + commentEntity: CommentEntity, + showConversation: Boolean, + articleId: String, + communityId: String, + listener: OnCommentCallBackListener?) { + val dialogOptions = ArrayList() + + if (commentEntity.me == null || !commentEntity.me?.isAnswerCommented!!) { + dialogOptions.add("回复") + } + + dialogOptions.add("复制") + dialogOptions.add("举报") + + if (commentEntity.parentUser != null && showConversation) { + dialogOptions.add("查看对话") + } + + val dialog: Dialog + + dialog = createOptionsSelectDialog(context, dialogOptions) { + when (it) { + "回复" -> { + CheckLoginUtils.checkLogin(context) { + if (listener != null) { + listener.onCommentCallback(commentEntity) + } else if (!TextUtils.isEmpty(commentEntity.id)) { + context.startActivity(MessageDetailActivity.getMessageDetailIntent(context, commentEntity, commentEntity.id)) + } else { + Utils.toast(context, "缺少关键属性") + } + } + } + + "复制" -> copyText(commentEntity.content, context) + + "举报" -> CheckLoginUtils.checkLogin(context) { + showReportTypeDialog(context) { reportType -> + PostCommentUtils.reportCommunityArticleComment(context, communityId, articleId, commentEntity.id, reportType, + object : PostCommentUtils.PostCommentListener { + override fun postSuccess(response: JSONObject?) { + Utils.toast(context, "感谢您的举报") + } + + override fun postFailed(error: Throwable?) { + if (error == null) { + Utils.toast(context, "举报失败,请稍后重试") + } else { + Utils.toast(context, "举报失败,${error.message}") + } + } + }) + } + } + + "查看对话" -> context.startActivity(CommentDetailActivity.getCommunityArticleCommentIntent(context, articleId, commentEntity.id, communityId)); + } + } + + dialog.show(); + } + + @JvmStatic + fun showAnswerCommentOptions( + context: Context, + commentEntity: CommentEntity, + showConversation: Boolean, + answerId: String, + listener: OnCommentCallBackListener?) { + val dialogOptions = ArrayList() + + if (commentEntity.me == null || !commentEntity.me?.isAnswerCommented!!) { + dialogOptions.add("回复") + } + + dialogOptions.add("复制") + dialogOptions.add("举报") + + if (commentEntity.parentUser != null && showConversation) { + dialogOptions.add("查看对话") + } + + val dialog: Dialog + + dialog = createOptionsSelectDialog(context, dialogOptions) { + when (it) { + "回复" -> { + CheckLoginUtils.checkLogin(context) { + if (listener != null) { + listener.onCommentCallback(commentEntity) + } else if (!TextUtils.isEmpty(commentEntity.id)) { + context.startActivity(MessageDetailActivity.getMessageDetailIntent(context, commentEntity, commentEntity.id)) + } else { + Utils.toast(context, "缺少关键属性") + } + } + } + + "复制" -> copyText(commentEntity.content, context) + + "举报" -> CheckLoginUtils.checkLogin(context) { + showReportTypeDialog(context) { reportType -> + PostCommentUtils.postAnswerReportData(context, commentEntity.id, answerId, reportType, + object : PostCommentUtils.PostCommentListener { + override fun postSuccess(response: JSONObject?) { + Utils.toast(context, "感谢您的举报") + } + + override fun postFailed(error: Throwable?) { + if (error == null) { + Utils.toast(context, "举报失败,请稍后重试") + } else { + Utils.toast(context, "举报失败,${error.message}") + } + } + }) + } + } + + "查看对话" -> context.startActivity(CommentDetailActivity.getAnswerCommentIntent(context, commentEntity.id, answerId)) + } + } + + dialog.show(); + } + + private fun showReportTypeDialog(context: Context, reportCallback: (reportType: String) -> Unit) { + val reportTypes = arrayListOf("垃圾广告营销", "恶意攻击谩骂", "淫秽色情信息", "违法有害信息", "其它") + + val dialog = createOptionsSelectDialog(context, reportTypes) { + val jsonObject = JSONObject() + try { + jsonObject.put("reason", it) + reportCallback.invoke(jsonObject.toString()) + } catch (e: JSONException) { + e.printStackTrace() + } + } + dialog.show() + } + + private fun createOptionsSelectDialog( + context: Context, + dialogOptions: ArrayList, + clickCallback: (text: String) -> Unit): Dialog { + val dialog = Dialog(context) + + val container = LinearLayout(context) + container.orientation = LinearLayout.VERTICAL + container.setBackgroundColor(Color.WHITE) + container.setPadding(0, DisplayUtils.dip2px(context, 12f), 0, DisplayUtils.dip2px(context, 12f)) + + for (s in dialogOptions) { + val reportTv = TextView(context) + reportTv.text = s + reportTv.textSize = 17f + reportTv.setTextColor(ContextCompat.getColor(context, R.color.title)) + reportTv.setBackgroundResource(R.drawable.textview_white_style) + val widthPixels = context.resources.displayMetrics.widthPixels + reportTv.layoutParams = LinearLayout.LayoutParams(widthPixels * 9 / 10, + LinearLayout.LayoutParams.WRAP_CONTENT) + reportTv.setPadding(DisplayUtils.dip2px(context, 20f), DisplayUtils.dip2px(context, 12f), + 0, DisplayUtils.dip2px(context, 12f)) + container.addView(reportTv) + + reportTv.setOnClickListener { + dialog.cancel() + clickCallback.invoke(reportTv.text.toString()) + } + } + + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) + dialog.setContentView(container) + + return dialog + } +} \ No newline at end of file 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 7a8b3b0c22..6a4619ddac 100644 --- a/app/src/main/java/com/gh/common/util/CommentUtils.java +++ b/app/src/main/java/com/gh/common/util/CommentUtils.java @@ -314,7 +314,6 @@ public class CommentUtils { CheckLoginUtils.checkLogin(context, () -> showAnswerReportDialog(answerId, commentEntity, context)); break; case "查看对话": - if (TextUtils.isEmpty(articleId)) { context.startActivity(CommentDetailActivity.getAnswerCommentIntent(context, commentEntity.getId(), answerId)); } else { @@ -370,7 +369,11 @@ public class CommentUtils { @Override public void postFailed(Throwable error) { - Utils.toast(context, error.toString()); + if (error != null) { + Utils.toast(context, "举报失败" + error.getMessage()); + } else { + Utils.toast(context, "举报失败,请稍候重试"); + } } }); reportTypeDialog.cancel(); diff --git a/app/src/main/java/com/gh/common/util/PostCommentUtils.java b/app/src/main/java/com/gh/common/util/PostCommentUtils.java index 312f344263..0d77b5ce1f 100644 --- a/app/src/main/java/com/gh/common/util/PostCommentUtils.java +++ b/app/src/main/java/com/gh/common/util/PostCommentUtils.java @@ -191,6 +191,30 @@ public class PostCommentUtils { }); } + public static void reportCommunityArticleComment(final Context context, + final String communityId, + final String articleId, + final String commentId, + final String reportData, + final PostCommentListener listener) { + RequestBody body = RequestBody.create(MediaType.parse("application/json"), reportData); + RetrofitManager.getInstance(context).getApi() + .postCommunityArticleCommentReport(communityId, articleId, commentId, body) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onResponse(ResponseBody response) { + listener.postSuccess(null); + } + + @Override + public void onFailure(HttpException e) { + listener.postFailed(e); + } + }); + } + public interface PostCommentListener { void postSuccess(JSONObject response); diff --git a/app/src/main/java/com/gh/gamecenter/CommentDetailActivity.java b/app/src/main/java/com/gh/gamecenter/CommentDetailActivity.java index a73d30a5eb..efea8f4fb6 100644 --- a/app/src/main/java/com/gh/gamecenter/CommentDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/CommentDetailActivity.java @@ -6,8 +6,8 @@ import android.os.Bundle; import com.gh.common.util.EntranceUtils; import com.gh.gamecenter.entity.MessageEntity; -import com.gh.gamecenter.qa.answer.detail.comment.AnswerCommentActivity; -import com.gh.gamecenter.qa.answer.detail.comment.AnswerCommentConversationFragment; +import com.gh.gamecenter.qa.comment.CommentActivity; +import com.gh.gamecenter.qa.comment.CommentConversationFragment; import com.halo.assistant.fragment.comment.CommentDetailFragment; /** @@ -27,16 +27,16 @@ public class CommentDetailActivity extends NormalActivity { Bundle args = new Bundle(); args.putString(EntranceUtils.KEY_COMMENTID, commentId); args.putString(EntranceUtils.KEY_ANSWER_ID, answerId); - return getTargetIntent(context, CommentDetailActivity.class, AnswerCommentConversationFragment.class, args); + return getTargetIntent(context, CommentDetailActivity.class, CommentConversationFragment.class, args); } public static Intent getCommunityArticleCommentIntent(Context context, String articleId, String articleCommentId, String articleCommunityId) { Bundle args = new Bundle(); - args.putString(AnswerCommentActivity.ARTICLE_ID, articleId); + args.putString(CommentActivity.ARTICLE_ID, articleId); args.putString(EntranceUtils.KEY_ARTICLE_COMMENT_ID, articleCommentId); - args.putString(AnswerCommentActivity.ARTICLE_COMMUNITY_ID, articleCommunityId); - return getTargetIntent(context, CommentDetailActivity.class, AnswerCommentConversationFragment.class, args); + args.putString(CommentActivity.ARTICLE_COMMUNITY_ID, articleCommunityId); + return getTargetIntent(context, CommentDetailActivity.class, CommentConversationFragment.class, args); } } diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/desc/GameDetailPluginAdapter.java b/app/src/main/java/com/gh/gamecenter/gamedetail/desc/GameDetailPluginAdapter.java index 1d317e548c..3c3fde9127 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/desc/GameDetailPluginAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/desc/GameDetailPluginAdapter.java @@ -77,7 +77,9 @@ public class GameDetailPluginAdapter extends BaseRecyclerAdapter) data.getExtras().get(ViewImageActivity.VIEWED_IMAGE); - } else if (requestCode == AnswerCommentActivity.REQUEST_CODE && resultCode == Activity.RESULT_OK) { + } else if (requestCode == CommentActivity.REQUEST_CODE && resultCode == Activity.RESULT_OK) { - String draft = data.getStringExtra(AnswerCommentActivity.COMMENT_DRAFT); + String draft = data.getStringExtra(CommentActivity.COMMENT_DRAFT); if (draft != null) { mCacheCommentDraft = draft; } - int count = data.getIntExtra(AnswerCommentActivity.COMMENT_COUNT, 0); + int count = data.getIntExtra(CommentActivity.COMMENT_COUNT, 0); if (count != 0) { mDetailEntity.setCommentCount(count); mAnswerCommentCountTv.setText(String.format("%s 评论", NumberUtils.transSimpleCount(mDetailEntity.getCommentCount()))); @@ -573,8 +573,8 @@ public class AnswerDetailFragment extends NormalFragment { commentCount = mDetailEntity.getCommentCount(); } - Intent intent = AnswerCommentActivity.getIntent(getContext(), mAnswerId, commentCount, mCacheCommentDraft, showKeyBoard); - startActivityForResult(intent, AnswerCommentActivity.REQUEST_CODE); + Intent intent = CommentActivity.getIntent(getContext(), mAnswerId, commentCount, mCacheCommentDraft, showKeyBoard); + startActivityForResult(intent, CommentActivity.REQUEST_CODE); } private void editContent() { diff --git a/app/src/main/java/com/gh/gamecenter/qa/article/detail/ArticleDetailActivity.kt b/app/src/main/java/com/gh/gamecenter/qa/article/detail/ArticleDetailActivity.kt index 590cbf3203..2fe71e9627 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/article/detail/ArticleDetailActivity.kt +++ b/app/src/main/java/com/gh/gamecenter/qa/article/detail/ArticleDetailActivity.kt @@ -29,8 +29,9 @@ import com.gh.gamecenter.databinding.ActivityArticleDetailBinding import com.gh.gamecenter.entity.CommunityEntity import com.gh.gamecenter.manager.UserManager import com.gh.gamecenter.mvvm.Status -import com.gh.gamecenter.qa.answer.detail.comment.AnswerCommentActivity import com.gh.gamecenter.qa.article.edit.ArticleEditActivity +import com.gh.gamecenter.qa.comment.CommentActivity +import com.gh.gamecenter.qa.entity.ArticleDetailEntity import com.gh.gamecenter.suggest.SuggestType import com.google.android.flexbox.FlexboxLayout import kotterknife.bindView @@ -74,6 +75,12 @@ class ArticleDetailActivity : BaseActivity() { } } } + } else if (requestCode == CommentActivity.REQUEST_CODE && resultCode == Activity.RESULT_OK) { + val commentCount = data?.getIntExtra(CommentActivity.COMMENT_COUNT, 0) + if (commentCount != 0) { + mViewModel.detailEntity?.count?.comment = commentCount!! + mBinding.articleDetailCommentCountTv.text = String.format("%s 评论", NumberUtils.transSimpleCount(mViewModel.detailEntity?.count?.comment!!)) + } } } @@ -157,9 +164,9 @@ class ArticleDetailActivity : BaseActivity() { fun onClick(v: View) { when (v.id) { R.id.article_detail_comment_count_container -> { - val intent = AnswerCommentActivity.getArticleCommentIntent(this, mViewModel?.articleId!! - , 0, "", false, mViewModel.community?.id!!) - startActivityForResult(intent, AnswerCommentActivity.REQUEST_CODE) + val intent = CommentActivity.getArticleCommentIntent(this, mViewModel.articleId!! + , mViewModel.detailEntity?.count?.comment, "", false, mViewModel.community?.id!!) + startActivityForResult(intent, CommentActivity.REQUEST_CODE) } R.id.article_detail_like_container -> { CheckLoginUtils.checkLogin(this) { diff --git a/app/src/main/java/com/gh/gamecenter/qa/answer/detail/comment/AnswerCommentActivity.kt b/app/src/main/java/com/gh/gamecenter/qa/comment/CommentActivity.kt similarity index 90% rename from app/src/main/java/com/gh/gamecenter/qa/answer/detail/comment/AnswerCommentActivity.kt rename to app/src/main/java/com/gh/gamecenter/qa/comment/CommentActivity.kt index 7d683744dd..8d8e03f8bd 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/answer/detail/comment/AnswerCommentActivity.kt +++ b/app/src/main/java/com/gh/gamecenter/qa/comment/CommentActivity.kt @@ -1,4 +1,4 @@ -package com.gh.gamecenter.qa.answer.detail.comment +package com.gh.gamecenter.qa.comment import android.app.Activity import android.content.Context @@ -8,7 +8,7 @@ import android.support.v7.app.AppCompatActivity import com.gh.gamecenter.R import com.gh.gamecenter.qa.answer.detail.AnswerDetailFragment -class AnswerCommentActivity : AppCompatActivity() { +class CommentActivity : AppCompatActivity() { val resultIntent = Intent() @@ -25,7 +25,7 @@ class AnswerCommentActivity : AppCompatActivity() { @JvmStatic fun getIntent(context: Context, answerId: String, commentCount: Int? = 0, commentDraft: String? = null, showKeyboard: Boolean): Intent { - val intent = Intent(context, AnswerCommentActivity::class.java) + val intent = Intent(context, CommentActivity::class.java) intent.putExtra(ANSWER_ID, answerId) intent.putExtra(COMMENT_COUNT, commentCount) intent.putExtra(COMMENT_DRAFT, commentDraft) @@ -37,7 +37,7 @@ class AnswerCommentActivity : AppCompatActivity() { fun getArticleCommentIntent(context: Context, articleId: String, commentCount: Int? = 0, commentDraft: String? = null, showKeyboard: Boolean, articleCommunityId: String): Intent { - val intent = Intent(context, AnswerCommentActivity::class.java) + val intent = Intent(context, CommentActivity::class.java) intent.putExtra(ARTICLE_ID, articleId) intent.putExtra(COMMENT_COUNT, commentCount) intent.putExtra(COMMENT_DRAFT, commentDraft) @@ -73,14 +73,14 @@ class AnswerCommentActivity : AppCompatActivity() { } val answerCommentFragment = if (!answerId.isNullOrEmpty()) { - AnswerCommentFragment.getInstance( + CommentFragment.getInstance( answerId, showKeyboard, commentCount, commentDraft, value) } else { - AnswerCommentFragment.getArticleInstance( + CommentFragment.getArticleInstance( articleId, articleCommunityId, showKeyboard, diff --git a/app/src/main/java/com/gh/gamecenter/qa/answer/detail/comment/AnswerCommentAdapter.java b/app/src/main/java/com/gh/gamecenter/qa/comment/CommentAdapter.java similarity index 84% rename from app/src/main/java/com/gh/gamecenter/qa/answer/detail/comment/AnswerCommentAdapter.java rename to app/src/main/java/com/gh/gamecenter/qa/comment/CommentAdapter.java index e596ec1761..7198030d65 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/answer/detail/comment/AnswerCommentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/qa/comment/CommentAdapter.java @@ -1,4 +1,4 @@ -package com.gh.gamecenter.qa.answer.detail.comment; +package com.gh.gamecenter.qa.comment; import android.content.Context; import android.support.v7.widget.RecyclerView; @@ -7,6 +7,7 @@ import android.view.View; import android.view.ViewGroup; import com.gh.common.constant.ItemViewType; +import com.gh.common.util.CommentHelper; import com.gh.common.util.CommentUtils; import com.gh.gamecenter.PersonalHomeActivity; import com.gh.gamecenter.R; @@ -16,7 +17,7 @@ import com.gh.gamecenter.adapter.viewholder.FooterViewHolder; import com.gh.gamecenter.baselist.ListAdapter; import com.gh.gamecenter.entity.CommentEntity; -public class AnswerCommentAdapter extends ListAdapter { +public class CommentAdapter extends ListAdapter { private String mEntrance; private String mAnswerId; @@ -25,7 +26,7 @@ public class AnswerCommentAdapter extends ListAdapter { private boolean mIsShowingConversation; private OnCommentCallBackListener mOnCommentCallBackListener; - public AnswerCommentAdapter(Context context, String articleId, String articleCommunityId, String answerId + public CommentAdapter(Context context, String articleId, String articleCommunityId, String answerId , boolean isShowingConversation, OnCommentCallBackListener commentCallBackListener, String entrance) { super(context); mEntrance = entrance; @@ -93,8 +94,22 @@ public class AnswerCommentAdapter extends ListAdapter { holder.commentLikeIv.setOnClickListener(v -> CommentUtils.postVoteToAnswerComment(mContext, mAnswerId, mArticleId, mArticleCommunityId, commentEntity, holder.commentLikeCountTv, holder.commentLikeIv, null)); - holder.itemView.setOnClickListener(v -> CommentUtils.showAnswerCommentOptions(commentEntity, mContext, mOnCommentCallBackListener, null - , !mIsShowingConversation, mAnswerId, mArticleId, mArticleCommunityId)); + holder.itemView.setOnClickListener(v -> { + if (!TextUtils.isEmpty(mArticleId)) { + CommentHelper.showCommunityArticleCommentOptions(mContext, + commentEntity, + mIsShowingConversation, + mArticleId, + mArticleCommunityId, + mOnCommentCallBackListener); + } else { + CommentHelper.showAnswerCommentOptions(mContext, + commentEntity, + mIsShowingConversation, + mAnswerId, + mOnCommentCallBackListener); + } + }); String path = TextUtils.isEmpty(mAnswerId) ? "回答详情-评论管理" : "社区文章详情-评论管理"; holder.commentUserIconDv.setOnClickListener(v -> PersonalHomeActivity.startTargetActivity(mContext, commentEntity.getUser().getId(), mEntrance, path)); holder.commentUserNameTv.setOnClickListener(v -> PersonalHomeActivity.startTargetActivity(mContext, commentEntity.getUser().getId(), mEntrance, path)); diff --git a/app/src/main/java/com/gh/gamecenter/qa/answer/detail/comment/AnswerCommentConversationFragment.java b/app/src/main/java/com/gh/gamecenter/qa/comment/CommentConversationFragment.java similarity index 76% rename from app/src/main/java/com/gh/gamecenter/qa/answer/detail/comment/AnswerCommentConversationFragment.java rename to app/src/main/java/com/gh/gamecenter/qa/comment/CommentConversationFragment.java index 72cc2213e2..8a155cb654 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/answer/detail/comment/AnswerCommentConversationFragment.java +++ b/app/src/main/java/com/gh/gamecenter/qa/comment/CommentConversationFragment.java @@ -1,4 +1,4 @@ -package com.gh.gamecenter.qa.answer.detail.comment; +package com.gh.gamecenter.qa.comment; import android.annotation.SuppressLint; import android.app.Application; @@ -17,7 +17,7 @@ import com.gh.gamecenter.entity.CommentEntity; import butterknife.BindView; // 评论详情-查看对话 -public class AnswerCommentConversationFragment extends AnswerCommentFragment { +public class CommentConversationFragment extends CommentFragment { @BindView(R.id.answer_comment_content_container) View mCommentContainer; @@ -34,8 +34,8 @@ public class AnswerCommentConversationFragment extends AnswerCommentFragment { } else { entrance = "(文章-评论详情-查看对话)"; } - mAdapter = new AnswerCommentAdapter(getContext(), mArticleId, mArticleCommunityId, - mAnswerId, true, this, entrance); + mAdapter = new CommentAdapter(getContext(), mArticleId, mArticleCommunityId, + mAnswerId, false, this, entrance); } return mAdapter; } @@ -45,9 +45,9 @@ public class AnswerCommentConversationFragment extends AnswerCommentFragment { mCommentId = getArguments().getString(EntranceUtils.KEY_COMMENTID); mAnswerId = getArguments().getString(EntranceUtils.KEY_ANSWER_ID); - mArticleId = getArguments().getString(AnswerCommentActivity.ARTICLE_ID); + mArticleId = getArguments().getString(CommentActivity.ARTICLE_ID); mArticleCommentId = getArguments().getString(EntranceUtils.KEY_ARTICLE_COMMENT_ID); - mArticleCommunityId = getArguments().getString(AnswerCommentActivity.ARTICLE_COMMUNITY_ID); + mArticleCommunityId = getArguments().getString(CommentActivity.ARTICLE_COMMUNITY_ID); super.onCreate(savedInstanceState); } @@ -72,9 +72,9 @@ public class AnswerCommentConversationFragment extends AnswerCommentFragment { } @Override - protected AnswerCommentViewModel provideListViewModel() { - return ViewModelProviders.of(this, new AnswerCommentViewModel.Factory((Application) getContext().getApplicationContext() - , mAnswerId, mCommentId, mArticleId, mArticleCommunityId, mArticleCommentId)).get(AnswerCommentViewModel.class); + protected CommentViewModel provideListViewModel() { + return ViewModelProviders.of(this, new CommentViewModel.Factory((Application) getContext().getApplicationContext() + , mAnswerId, mCommentId, mArticleId, mArticleCommunityId, mArticleCommentId)).get(CommentViewModel.class); } @Override diff --git a/app/src/main/java/com/gh/gamecenter/qa/answer/detail/comment/AnswerCommentFragment.java b/app/src/main/java/com/gh/gamecenter/qa/comment/CommentFragment.java similarity index 92% rename from app/src/main/java/com/gh/gamecenter/qa/answer/detail/comment/AnswerCommentFragment.java rename to app/src/main/java/com/gh/gamecenter/qa/comment/CommentFragment.java index b8b0e03893..c1d0683b17 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/answer/detail/comment/AnswerCommentFragment.java +++ b/app/src/main/java/com/gh/gamecenter/qa/comment/CommentFragment.java @@ -1,4 +1,4 @@ -package com.gh.gamecenter.qa.answer.detail.comment; +package com.gh.gamecenter.qa.comment; import android.annotation.SuppressLint; import android.app.Activity; @@ -48,7 +48,7 @@ import butterknife.OnClick; import butterknife.Optional; import retrofit2.HttpException; -public class AnswerCommentFragment extends ListFragment implements OnCommentCallBackListener, KeyboardHeightObserver { +public class CommentFragment extends ListFragment implements OnCommentCallBackListener, KeyboardHeightObserver { @Nullable @BindView(R.id.answer_comment_container) @@ -73,7 +73,7 @@ public class AnswerCommentFragment extends ListFragment { +public class CommentViewModel extends ListViewModel { private String mAnswerId; private String mCommentId; @@ -34,7 +34,7 @@ public class AnswerCommentViewModel extends ListViewModel> mPostCommentLiveData = new MutableLiveData<>(); - public AnswerCommentViewModel(@NonNull Application application, String answerId, @Nullable String commentId + public CommentViewModel(@NonNull Application application, String answerId, @Nullable String commentId , String articleId, String articleCommunityId, String articleCommentId) { super(application); mAnswerId = answerId; @@ -79,7 +79,6 @@ public class AnswerCommentViewModel extends ListViewModel apiResponse = new ApiResponse<>(); if (e instanceof HttpException) { apiResponse.setHttpException((HttpException) e); @@ -120,7 +119,7 @@ public class AnswerCommentViewModel extends ListViewModel T create(Class modelClass) { - return (T) new AnswerCommentViewModel(mApplication, mAnswerId, mCommentId, mArticleId, mArticleCommunityId, mArticleCommentId); + return (T) new CommentViewModel(mApplication, mAnswerId, mCommentId, mArticleId, mArticleCommunityId, mArticleCommentId); } } } diff --git a/app/src/main/java/com/gh/gamecenter/qa/entity/ArticleEntity.kt b/app/src/main/java/com/gh/gamecenter/qa/entity/ArticleEntity.kt index 8a9364fc16..b5da6cc33d 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/entity/ArticleEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/qa/entity/ArticleEntity.kt @@ -17,7 +17,7 @@ data class ArticleEntity(@SerializedName("_id") @Parcelize data class Count( - val comment: Int = -1, + var comment: Int = -1, var vote: Int = -1, val answer: Int = -1) : Parcelable { 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 fb10b6adc8..27427aa9c2 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 @@ -1322,6 +1322,15 @@ public interface ApiService { @Path("article_id") String articled, @Path("comment_id") String commentId); + /** + * 举报社区文章评论 + */ + @POST("communities/{community_id}/articles/{article_id}/comments/{comment_id}:report") + Observable postCommunityArticleCommentReport(@Path("community_id") String communityId, + @Path("article_id") String articleId, + @Path("comment_id") String commentId, + @Body RequestBody reportData); + /** * 获取个人主页的回答列表 */ @@ -1340,6 +1349,13 @@ public interface ApiService { @GET("games/{game_id}/comments") Observable> getGameComments(@Path("game_id") String gameId, @Query("page") int page); + + /** + * 获取游戏详情介绍页面的评论 + */ + @GET("games/{game_id}/comments:hot") + Observable> getGameCommentsForDesc(@Path("game_id") String gameId, @Query("page") int page); + /** * 添加游戏评论 */