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 1d6ae56d5d..ccc13aca6f 100644 --- a/app/src/main/java/com/gh/common/util/CommentUtils.java +++ b/app/src/main/java/com/gh/common/util/CommentUtils.java @@ -155,7 +155,7 @@ public class CommentUtils { List dialogType = new ArrayList<>(); - if (commentEntity.getUserData() == null || !commentEntity.getUserData().isCommentOwn()) { + if (commentEntity.getUserData() == null || !commentEntity.getUserData().isAnswerCommented()) { dialogType.add("回复"); } @@ -197,8 +197,7 @@ public class CommentUtils { LibaoUtils.copyLink(commentEntity.getContent(), context); break; case "举报": - CheckLoginUtils.checkLogin(context, () -> showReportTypeDialog(commentEntity, context)); - + CheckLoginUtils.checkLogin(context, () -> showAnswerReportDialog(answerId, commentEntity, context)); break; case "查看对话": context.startActivity(CommentDetailActivity.getAnswerCommentIntent(context, commentEntity.getId(), answerId)); @@ -212,6 +211,58 @@ public class CommentUtils { dialog.show(); } + private static void showAnswerReportDialog(final String answerId, final CommentEntity commentEntity, final Context context) { + final String[] arrReportType = new String[]{"垃圾广告营销", "恶意攻击谩骂", "淫秽色情信息", + "违法有害信息", "其它"}; + int widthPixels = context.getResources().getDisplayMetrics().widthPixels; + + final Dialog reportTypeDialog = new Dialog(context); + LinearLayout container = new LinearLayout(context); + container.setOrientation(LinearLayout.VERTICAL); + container.setPadding(0, DisplayUtils.dip2px(context, 12), 0, DisplayUtils.dip2px(context, 12)); + container.setBackgroundColor(Color.WHITE); + + for (final String s : arrReportType) { + TextView reportTypeTv = new TextView(context); + reportTypeTv.setText(s); + reportTypeTv.setTextSize(17); + reportTypeTv.setTextColor(ContextCompat.getColor(context, R.color.title)); + reportTypeTv.setBackgroundResource(R.drawable.textview_white_style); + reportTypeTv.setLayoutParams(new LinearLayout.LayoutParams((widthPixels * 9) / 10, + LinearLayout.LayoutParams.WRAP_CONTENT)); + reportTypeTv.setPadding(DisplayUtils.dip2px(context, 20), DisplayUtils.dip2px(context, 12), + 0, DisplayUtils.dip2px(context, 12)); + container.addView(reportTypeTv); + + reportTypeTv.setOnClickListener(v -> { + JSONObject jsonObject = new JSONObject(); + try { + jsonObject.put("reason", s); + } catch (JSONException e) { + e.printStackTrace(); + } + + PostCommentUtils.postAnswerReportData(context, commentEntity.getId(), answerId, jsonObject.toString(), + new PostCommentUtils.PostCommentListener() { + @Override + public void postSuccess(JSONObject response) { + Utils.toast(context, "感谢您的举报"); + } + + @Override + public void postFailed(Throwable error) { + Utils.toast(context, error.toString()); + } + }); + reportTypeDialog.cancel(); + }); + } + + reportTypeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + reportTypeDialog.setContentView(container); + reportTypeDialog.show(); + } + private static void showReportTypeDialog(final CommentEntity commentEntity, final Context context) { final String[] arrReportType = new String[]{"垃圾广告营销", "恶意攻击谩骂", "淫秽色情信息", "违法有害信息", "其它"}; 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 f373c70ccd..1f4401a35a 100644 --- a/app/src/main/java/com/gh/common/util/PostCommentUtils.java +++ b/app/src/main/java/com/gh/common/util/PostCommentUtils.java @@ -156,6 +156,26 @@ public class PostCommentUtils { }); } + public static void postAnswerReportData(final Context context, final String commentId, final String answerId, final String reportData, + final PostCommentListener listener) { + RequestBody body = RequestBody.create(MediaType.parse("application/json"), reportData); + RetrofitManager.getInstance(context).getApi() + .postReportOfAnswerComment(answerId, 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/common/view/RichEditor.java b/app/src/main/java/com/gh/common/view/RichEditor.java index 2116041900..6bdb00ae31 100644 --- a/app/src/main/java/com/gh/common/view/RichEditor.java +++ b/app/src/main/java/com/gh/common/view/RichEditor.java @@ -189,7 +189,7 @@ public class RichEditor extends WebView { try { exec("javascript:RE.setHtml('" + URLEncoder.encode(contents, "UTF-8") + "');"); - if (isLoadTbImage && NetworkUtils.isWifiConnected(getContext())) { + if (isLoadTbImage && !NetworkUtils.isWifiConnected(getContext())) { exec("javascript:RE.replaceTbImage()"); } diff --git a/app/src/main/java/com/gh/gamecenter/ask/AnswerCommentFragment.java b/app/src/main/java/com/gh/gamecenter/ask/AnswerCommentFragment.java index 20a937b563..d58a36a809 100644 --- a/app/src/main/java/com/gh/gamecenter/ask/AnswerCommentFragment.java +++ b/app/src/main/java/com/gh/gamecenter/ask/AnswerCommentFragment.java @@ -1,6 +1,7 @@ package com.gh.gamecenter.ask; import android.annotation.SuppressLint; +import android.app.Activity; import android.app.Application; import android.app.Dialog; import android.arch.lifecycle.ViewModelProviders; @@ -12,9 +13,12 @@ import android.support.v4.app.Fragment; import android.support.v7.widget.RecyclerView; import android.text.Editable; import android.text.TextWatcher; +import android.util.DisplayMetrics; import android.view.View; +import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; +import android.widget.FrameLayout; import android.widget.TextView; import com.gh.base.fragment.BaseDialogWrapperFragment; @@ -39,6 +43,9 @@ import retrofit2.HttpException; public class AnswerCommentFragment extends ListFragment implements OnCommentCallBackListener { + @Nullable + @BindView(R.id.answer_comment_container) + protected View mCommentContainer; @BindView(R.id.answer_comment_et) protected EditText mCommentDetailCommentEt; @BindView(R.id.answer_comment_send_btn) @@ -46,6 +53,7 @@ public class AnswerCommentFragment extends ListFragment { - if (mDetailEntity != null && !mDetailEntity.getMe().isAnswerVoted()) { - mViewModel.postVote(mAnswerId); - } else { - toast(R.string.ask_vote_hint); - } - }); - break; case R.id.reuse_no_connection: mNoConn.setVisibility(View.GONE); mLoading.setVisibility(View.VISIBLE); @@ -377,8 +367,14 @@ public class AnswerDetailFragment extends NormalFragment { startActivity(QuestionsDetailActivity.getIntent(getContext(), mDetailEntity.getQuestion().getId(), mEntrance)); } break; - case R.id.answer_detail_do_comment_container: - showCommentDialog(true); + case R.id.answer_detail_like_container: + CheckLoginUtils.checkLogin(getContext(), () -> { + if (mDetailEntity != null && !mDetailEntity.getMe().isAnswerVoted()) { + mViewModel.postVote(mAnswerId); + } else { + toast(R.string.ask_vote_hint); + } + }); break; case R.id.answer_detail_comment_count_container: showCommentDialog(false); @@ -410,7 +406,11 @@ public class AnswerDetailFragment extends NormalFragment { commentCount = mDetailEntity.getCommentCount(); } - BaseDialogWrapperFragment dialog = BaseDialogWrapperFragment.getInstance(AnswerCommentFragment.getInstance(mAnswerId, showKeyBoard, commentCount)); + BaseDialogWrapperFragment dialog = BaseDialogWrapperFragment.getInstance( + AnswerCommentFragment.getInstance(mAnswerId, showKeyBoard, commentCount, count -> { + mDetailEntity.setCommentCount(count); + mAnswerCommentCountTv.setText(String.format("%d 评论", mDetailEntity.getCommentCount())); + })); dialog.show(getFragmentManager(), "CommentDialog"); } @@ -481,15 +481,15 @@ public class AnswerDetailFragment extends NormalFragment { } private void updateVote() { - mVoteCount.setText(getString(R.string.ask_vote_count, AskUtils.voteCountFormat(mDetailEntity.getVote()))); + mAnswerDetailLikeTv.setText(getString(R.string.ask_vote_count, AskUtils.voteCountFormat(mDetailEntity.getVote()))); if (getContext() == null) return; if (mDetailEntity.getMe().isAnswerVoted()) { - mVote.setImageResource(R.drawable.answer_detail_unvote); - mVoteCount.setTextColor(ContextCompat.getColor(getContext(), R.color.theme)); + mAnswerDetailLiveIv.setImageResource(R.drawable.ic_answer_liked); + mAnswerDetailLikeTv.setTextColor(ContextCompat.getColor(getContext(), R.color.theme)); } else { - mVote.setImageResource(R.drawable.answer_detail_vote); - mVoteCount.setTextColor(ContextCompat.getColor(getContext(), R.color.hint)); + mAnswerDetailLiveIv.setImageResource(R.drawable.ic_answer_like); + mAnswerDetailLikeTv.setTextColor(ContextCompat.getColor(getContext(), R.color.text_5d5d5d)); } } @@ -531,4 +531,8 @@ public class AnswerDetailFragment extends NormalFragment { } } } + + public interface CommentCountListener { + void onChange(int count); + } } diff --git a/app/src/main/java/com/gh/gamecenter/entity/UserDataEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/UserDataEntity.kt index 4d62e4ea2e..fbb8ac31c5 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/UserDataEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/UserDataEntity.kt @@ -25,6 +25,9 @@ class UserDataEntity : Parcelable { @SerializedName("is_comment_voted") var isCommentVoted: Boolean = false + @SerializedName("is_answer_commented") + var isAnswerCommented: Boolean = false + @SerializedName("is_version_requested") var isVersionRequested: Boolean = false @@ -41,6 +44,7 @@ class UserDataEntity : Parcelable { dest.writeByte(if (this.isToolkitFavorite) 1.toByte() else 0.toByte()) dest.writeByte(if (this.isCommentOwn) 1.toByte() else 0.toByte()) dest.writeByte(if (this.isCommentVoted) 1.toByte() else 0.toByte()) + dest.writeByte(if (this.isAnswerCommented) 1.toByte() else 0.toByte()) dest.writeTypedList(this.userDataLibaoList) } @@ -52,6 +56,7 @@ class UserDataEntity : Parcelable { this.isToolkitFavorite = `in`.readByte().toInt() != 0 this.isCommentOwn = `in`.readByte().toInt() != 0 this.isCommentVoted = `in`.readByte().toInt() != 0 + this.isAnswerCommented = `in`.readByte().toInt() != 0 this.userDataLibaoList = `in`.createTypedArrayList(UserDataLibaoEntity.CREATOR) } 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 e0ceaf3555..8fc36a1c80 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 @@ -943,6 +943,12 @@ public interface ApiService { @POST("answers/{answer_id}/comments/{comment_id}:vote") Observable postVoteAnswerComment(@Path("answer_id") String answerId, @Path("comment_id") String commentId); + /** + * 举报回答的评论 + */ + @POST("answers/{answer_id}/comments/{comment_id}:report") + Observable postReportOfAnswerComment(@Path("answer_id") String answerId, @Path("comment_id") String commentId, @Body RequestBody reportData); + /** * 获取评论列表.可以分页 */ diff --git a/app/src/main/res/drawable-xhdpi/ic_answer_like.png b/app/src/main/res/drawable-xhdpi/ic_answer_like.png new file mode 100644 index 0000000000..499e8d5004 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_answer_like.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_answer_liked.png b/app/src/main/res/drawable-xhdpi/ic_answer_liked.png new file mode 100644 index 0000000000..8ec5058d9c Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_answer_liked.png differ diff --git a/app/src/main/res/drawable-xxhdpi/answer_detail_unvote.png b/app/src/main/res/drawable-xxhdpi/answer_detail_unvote.png deleted file mode 100644 index 970c57a282..0000000000 Binary files a/app/src/main/res/drawable-xxhdpi/answer_detail_unvote.png and /dev/null differ diff --git a/app/src/main/res/drawable-xxhdpi/answer_detail_vote.png b/app/src/main/res/drawable-xxhdpi/answer_detail_vote.png deleted file mode 100644 index f828684090..0000000000 Binary files a/app/src/main/res/drawable-xxhdpi/answer_detail_vote.png and /dev/null differ diff --git a/app/src/main/res/drawable-xxhdpi/answer_edit_questions_icon.png b/app/src/main/res/drawable-xxhdpi/answer_edit_questions_icon.png deleted file mode 100644 index 6e82ea6a94..0000000000 Binary files a/app/src/main/res/drawable-xxhdpi/answer_edit_questions_icon.png and /dev/null differ diff --git a/app/src/main/res/layout/fragment_answer_comment.xml b/app/src/main/res/layout/fragment_answer_comment.xml index 583a1501a7..8bcfc4f803 100644 --- a/app/src/main/res/layout/fragment_answer_comment.xml +++ b/app/src/main/res/layout/fragment_answer_comment.xml @@ -5,6 +5,7 @@ android:layout_height="wrap_content"> - - + + diff --git a/app/src/main/res/layout/fragment_answer_detail.xml b/app/src/main/res/layout/fragment_answer_detail.xml index 9e56ff1cd4..1f132b2be1 100644 --- a/app/src/main/res/layout/fragment_answer_detail.xml +++ b/app/src/main/res/layout/fragment_answer_detail.xml @@ -42,22 +42,12 @@ android:paddingRight="20dp" app:layout_constraintTop_toBottomOf="@id/answer_detail_line"> - - - - - - @@ -218,7 +185,7 @@ android:background="@android:color/white"> + android:src="@drawable/ic_answer_like" /> @@ -262,6 +231,7 @@ android:id="@+id/answer_detail_comment_count_tv" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:text="0 评论" android:layout_marginLeft="9dp" android:textColor="@color/text_5d5d5d" android:textSize="13sp" /> diff --git a/app/src/main/res/layout/fragment_answer_edit.xml b/app/src/main/res/layout/fragment_answer_edit.xml index e2b6e85320..9c230629c6 100644 --- a/app/src/main/res/layout/fragment_answer_edit.xml +++ b/app/src/main/res/layout/fragment_answer_edit.xml @@ -17,23 +17,13 @@ android:paddingLeft = "20dp" android:paddingRight = "10dp" > - -