From bd7c806ad9a0748c419be13000210feb51f0ae66 Mon Sep 17 00:00:00 2001 From: seven332 Date: Tue, 7 May 2019 21:00:07 +0800 Subject: [PATCH] Check text to get comment actions --- .../com/hippo/ehviewer/client/EhClient.java | 2 +- .../com/hippo/ehviewer/client/EhEngine.java | 11 ++++-- .../ehviewer/client/data/GalleryComment.java | 21 +++++++---- .../client/parser/GalleryDetailParser.java | 21 +++++++---- .../ui/scene/GalleryCommentsScene.java | 35 +++++++++++-------- app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values/ids.xml | 1 + app/src/main/res/values/strings.xml | 1 + 10 files changed, 64 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhClient.java b/app/src/main/java/com/hippo/ehviewer/client/EhClient.java index 045facf19..0ff6d0828 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhClient.java +++ b/app/src/main/java/com/hippo/ehviewer/client/EhClient.java @@ -148,7 +148,7 @@ public class EhClient { case METHOD_GET_RATE_GALLERY: return EhEngine.rateGallery(this, mOkHttpClient, (Long) params[0], (String) params[1], (Long) params[2], (String) params[3], (Float) params[4]); case METHOD_GET_COMMENT_GALLERY: - return EhEngine.commentGallery(this, mOkHttpClient, (String) params[0], (String) params[1]); + return EhEngine.commentGallery(this, mOkHttpClient, (String) params[0], (String) params[1], (String) params[1]); case METHOD_GET_GALLERY_TOKEN: return EhEngine.getGalleryToken(this, mOkHttpClient, (Long) params[0], (String) params[1], (Integer) params[2]); case METHOD_GET_FAVORITES: diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java b/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java index bc6addc74..6acaf7b23 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java +++ b/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java @@ -419,9 +419,14 @@ public class EhEngine { } public static GalleryComment[] commentGallery(@Nullable EhClient.Task task, - OkHttpClient okHttpClient, String url, String comment) throws Throwable { - FormBody.Builder builder = new FormBody.Builder() - .add("commenttext_new", comment); + OkHttpClient okHttpClient, String url, String comment, String id) throws Throwable { + FormBody.Builder builder = new FormBody.Builder(); + if (id == null) { + builder.add("commenttext_new", comment); + } else { + builder.add("commenttext_edit", comment); + builder.add("edit_comment", id); + } String origin = EhUrl.getOrigin(); Log.d(TAG, url); Request request = new EhRequestBuilder(url, url, origin) diff --git a/app/src/main/java/com/hippo/ehviewer/client/data/GalleryComment.java b/app/src/main/java/com/hippo/ehviewer/client/data/GalleryComment.java index 66ddf2889..58f39fef5 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/data/GalleryComment.java +++ b/app/src/main/java/com/hippo/ehviewer/client/data/GalleryComment.java @@ -24,8 +24,11 @@ public class GalleryComment implements Parcelable { // 0 for uploader comment. can't vote public long id; public int score; - public boolean voteUp; - public boolean voteDown; + public boolean editable; + public boolean voteUpAble; + public boolean voteUpEd; + public boolean voteDownAble; + public boolean voteDownEd; public String voteState; public long time; public String user; @@ -40,8 +43,11 @@ public class GalleryComment implements Parcelable { public void writeToParcel(Parcel dest, int flags) { dest.writeLong(this.id); dest.writeInt(this.score); - dest.writeByte(voteUp ? (byte) 1 : (byte) 0); - dest.writeByte(voteDown ? (byte) 1 : (byte) 0); + dest.writeByte(editable ? (byte) 1 : (byte) 0); + dest.writeByte(voteUpAble ? (byte) 1 : (byte) 0); + dest.writeByte(voteUpEd ? (byte) 1 : (byte) 0); + dest.writeByte(voteDownAble ? (byte) 1 : (byte) 0); + dest.writeByte(voteDownEd ? (byte) 1 : (byte) 0); dest.writeString(this.voteState); dest.writeLong(this.time); dest.writeString(this.user); @@ -54,8 +60,11 @@ public class GalleryComment implements Parcelable { protected GalleryComment(Parcel in) { this.id = in.readLong(); this.score = in.readInt(); - this.voteUp = in.readByte() != 0; - this.voteDown = in.readByte() != 0; + this.editable = in.readByte() != 0; + this.voteUpAble = in.readByte() != 0; + this.voteUpEd = in.readByte() != 0; + this.voteDownAble = in.readByte() != 0; + this.voteDownEd = in.readByte() != 0; this.voteState = in.readString(); this.time = in.readLong(); this.user = in.readString(); diff --git a/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryDetailParser.java b/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryDetailParser.java index 7b7b7b998..b689756ad 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryDetailParser.java +++ b/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryDetailParser.java @@ -16,7 +16,6 @@ package com.hippo.ehviewer.client.parser; -import android.text.TextUtils; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.hippo.ehviewer.Settings; @@ -399,13 +398,23 @@ public class GalleryDetailParser { Element a = element.previousElementSibling(); String name = a.attr("name"); comment.id = Integer.parseInt(StringUtils.trim(name).substring(1)); - // Vote up and vote down + // Editable, vote up and vote down Element c4 = JsoupUtils.getElementByClass(element, "c4"); if (null != c4) { - Elements es = c4.children(); - if (2 == es.size()) { - comment.voteUp = !TextUtils.isEmpty(StringUtils.trim(es.get(0).attr("style"))); - comment.voteDown = !TextUtils.isEmpty(StringUtils.trim(es.get(1).attr("style"))); + for (Element e : c4.children()) { + switch (e.text()) { + case "Vote+": + comment.voteUpAble = true; + comment.voteUpEd = !StringUtils.trim(e.attr("style")).isEmpty(); + break; + case "Vote-": + comment.voteDownAble = true; + comment.voteDownEd = !StringUtils.trim(e.attr("style")).isEmpty(); + break; + case "Edit": + comment.editable = true; + break; + } } } // Vote state diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.java index c892d12ff..865179805 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.java @@ -358,17 +358,19 @@ public final class GalleryCommentsScene extends ToolbarScene List menu = new ArrayList<>(); final IntList menuId = new IntList(); Resources resources = context.getResources(); - if (0 == comment.id || mApiUid < 0) { - // 0 id is uploader comment, can't vote - // Not sign in, can't vote - menu.add(resources.getString(R.string.copy_comment_text)); - menuId.add(R.id.copy); - } else { - menu.add(resources.getString(R.string.copy_comment_text)); - menuId.add(R.id.copy); - menu.add(resources.getString(comment.voteUp ? R.string.cancel_vote_up : R.string.vote_up)); + + menu.add(resources.getString(R.string.copy_comment_text)); + menuId.add(R.id.copy); + if (comment.editable) { + menu.add(resources.getString(R.string.edit_comment)); + menuId.add(R.id.edit_comment); + } + if (comment.voteUpAble) { + menu.add(resources.getString(comment.voteUpEd ? R.string.cancel_vote_up : R.string.vote_up)); menuId.add(R.id.vote_up); - menu.add(resources.getString(comment.voteDown ? R.string.cancel_vote_down : R.string.vote_down)); + } + if (comment.voteDownAble) { + menu.add(resources.getString(comment.voteDownEd ? R.string.cancel_vote_down : R.string.vote_down)); menuId.add(R.id.vote_down); } if (!TextUtils.isEmpty(comment.voteState)) { @@ -399,6 +401,9 @@ public final class GalleryCommentsScene extends ToolbarScene case R.id.check_vote_status: showVoteStatusDialog(context, comment.voteState); break; + case R.id.edit_comment: + // TODO + break; } } }).show(); @@ -585,7 +590,7 @@ public final class GalleryCommentsScene extends ToolbarScene // Request EhRequest request = new EhRequest() .setMethod(EhClient.METHOD_GET_COMMENT_GALLERY) - .setArgs(url, comment) + .setArgs(url, comment, null) .setCallback(new CommentGalleryListener(context, activity.getStageId(), getTag())); EhApplication.getEhClient(context).execute(request); @@ -714,11 +719,11 @@ public final class GalleryCommentsScene extends ToolbarScene GalleryComment comment = mComments[position]; comment.score = result.score; if (result.expectVote > 0) { - comment.voteUp = 0 != result.vote; - comment.voteDown = false; + comment.voteUpEd = 0 != result.vote; + comment.voteDownEd = false; } else { - comment.voteDown = 0 != result.vote; - comment.voteUp = false; + comment.voteDownEd = 0 != result.vote; + comment.voteUpEd = false; } mAdapter.notifyItemChanged(position); diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 985313d6b..afd13a0da 100755 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -279,6 +279,7 @@ 评论成功 评论失败 复制评论文字 + 修改评论 深表赞同 不再深表赞同 垃圾评论 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 3030fc20e..0c3b9c51c 100755 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -279,6 +279,7 @@ 評論成功 評論失敗 複製評論文字 + 修改評論 深表贊同 不再深表贊同 垃圾評論 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index f655b093a..7c5ca0af2 100755 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -278,6 +278,7 @@ 留言成功 留言失敗 複製留言文字 + 修改留言 推 收回推 噓 diff --git a/app/src/main/res/values/ids.xml b/app/src/main/res/values/ids.xml index 04c8cc8b7..e41a60d6c 100644 --- a/app/src/main/res/values/ids.xml +++ b/app/src/main/res/values/ids.xml @@ -26,6 +26,7 @@ + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 408bef374..cd34541de 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -325,6 +325,7 @@ Comment post successfully Failed to post the comment Copy comment text + Edit comment Vote up Cancel up-vote Vote down