Check text to get comment actions

This commit is contained in:
seven332 committed 2019-05-07 21:00:07 +08:00
1 parent efe7d4757a
commit bd7c806ad9
10 files changed
+64 -31

No files matched your search

@@ -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:
@@ -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)
@@ -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();
@@ -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
@@ -358,17 +358,19 @@ public final class GalleryCommentsScene extends ToolbarScene
List<String> 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);