Implement editing comment

This commit is contained in:
seven332 committed 2019-05-08 11:29:59 +08:00
1 parent c9146324f8
commit 4064510b14
10 files changed
+77 -12

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], (String) params[1]);
return EhEngine.commentGallery(this, mOkHttpClient, (String) params[0], (String) params[1], (String) params[2]);
case METHOD_GET_GALLERY_TOKEN:
return EhEngine.getGalleryToken(this, mOkHttpClient, (Long) params[0], (String) params[1], (Integer) params[2]);
case METHOD_GET_FAVORITES:
@@ -422,10 +422,10 @@ public class EhEngine {
OkHttpClient okHttpClient, String url, String comment, String id) throws Throwable {
FormBody.Builder builder = new FormBody.Builder();
if (id == null) {
builder.add("commenttext_new", comment);
builder.add("commenttext_new", comment);
} else {
builder.add("commenttext_edit", comment);
builder.add("edit_comment", id);
builder.add("commenttext_edit", comment);
builder.add("edit_comment", id);
}
String origin = EhUrl.getOrigin();
Log.d(TAG, url);
@@ -126,6 +126,10 @@ public final class GalleryCommentsScene extends ToolbarScene
@Nullable
private ViewTransition mViewTransition;
private Drawable mSendDrawable;
private Drawable mPencilDrawable;
private long mCommentId;
private boolean mInAnimation = false;
@Override
@@ -201,6 +205,9 @@ public final class GalleryCommentsScene extends ToolbarScene
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
tip.setCompoundDrawables(null, drawable, null, null);
mSendDrawable = DrawableManager.getVectorDrawable(context, R.drawable.v_send_dark_x24);
mPencilDrawable = DrawableManager.getVectorDrawable(context, R.drawable.v_pencil_dark_x24);
mAdapter = new CommentAdapter();
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(context,
@@ -402,7 +409,10 @@ public final class GalleryCommentsScene extends ToolbarScene
showVoteStatusDialog(context, comment.voteState);
break;
case R.id.edit_comment:
// TODO
prepareEditComment(comment.id);
if (!mInAnimation && mEditPanel != null && mEditPanel.getVisibility() != View.VISIBLE) {
showEditPanel(true);
}
break;
}
}
@@ -445,6 +455,20 @@ public final class GalleryCommentsScene extends ToolbarScene
}
}
private void prepareNewComment() {
mCommentId = 0;
if (mSendImage != null) {
mSendImage.setImageDrawable(mSendDrawable);
}
}
private void prepareEditComment(long commentId) {
mCommentId = commentId;
if (mSendImage != null) {
mSendImage.setImageDrawable(mPencilDrawable);
}
}
private void showEditPanelWithAnimation() {
if (null == mFab || null == mEditPanel) {
return;
@@ -574,6 +598,7 @@ public final class GalleryCommentsScene extends ToolbarScene
if (mFab == v) {
if (!mInAnimation) {
prepareNewComment();
showEditPanel(true);
}
} else if (mSendImage == v) {
@@ -590,9 +615,9 @@ public final class GalleryCommentsScene extends ToolbarScene
// Request
EhRequest request = new EhRequest()
.setMethod(EhClient.METHOD_GET_COMMENT_GALLERY)
.setArgs(url, comment, null)
.setArgs(url, comment, mCommentId != 0 ? Long.toString(mCommentId) : null)
.setCallback(new CommentGalleryListener(context,
activity.getStageId(), getTag()));
activity.getStageId(), getTag(), mCommentId));
EhApplication.getEhClient(context).execute(request);
hideSoftInput();
hideEditPanel(true);
@@ -735,13 +760,16 @@ public final class GalleryCommentsScene extends ToolbarScene
private static class CommentGalleryListener extends EhCallback<GalleryCommentsScene, GalleryComment[]> {
public CommentGalleryListener(Context context, int stageId, String sceneTag) {
private long mCommentId;
public CommentGalleryListener(Context context, int stageId, String sceneTag, long commentId) {
super(context, stageId, sceneTag);
mCommentId = commentId;
}
@Override
public void onSuccess(GalleryComment[] result) {
showTip(R.string.comment_successfully, LENGTH_SHORT);
showTip(mCommentId != 0 ? R.string.edit_comment_successfully : R.string.comment_successfully, LENGTH_SHORT);
GalleryCommentsScene scene = getScene();
if (scene != null) {
@@ -751,7 +779,7 @@ public final class GalleryCommentsScene extends ToolbarScene
@Override
public void onFailure(Exception e) {
showTip(getContent().getString(R.string.comment_failed) + "\n" + ExceptionUtils.getReadableString(e), LENGTH_LONG);
showTip(getContent().getString(mCommentId != 0 ? R.string.edit_comment_failed : R.string.comment_failed) + "\n" + ExceptionUtils.getReadableString(e), LENGTH_LONG);
}
@Override
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2019 Hippo Seven
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/primary_drawable_dark"
android:pathData="@string/pd_pencil"/>
</vector>
@@ -75,8 +75,7 @@
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="bottom"
android:padding="16dp"
app:srcCompat="@drawable/v_send_dark_x24"/>
android:padding="16dp"/>
</LinearLayout>
</com.hippo.reveal.RevealLinearLayout>
@@ -280,6 +280,8 @@
<string name="comment_failed">评论失败</string>
<string name="copy_comment_text">复制评论文字</string>
<string name="edit_comment">修改评论</string>
<string name="edit_comment_successfully">评论已被修改</string>
<string name="edit_comment_failed">修改评论失败</string>
<string name="vote_up">深表赞同</string>
<string name="cancel_vote_up">不再深表赞同</string>
<string name="vote_down">垃圾评论</string>
@@ -280,6 +280,8 @@
<string name="comment_failed">評論失敗</string>
<string name="copy_comment_text">複製評論文字</string>
<string name="edit_comment">修改評論</string>
<string name="edit_comment_successfully">評論已被修改</string>
<string name="edit_comment_failed">修改評論失敗</string>
<string name="vote_up">深表贊同</string>
<string name="cancel_vote_up">不再深表贊同</string>
<string name="vote_down">垃圾評論</string>
@@ -279,6 +279,8 @@
<string name="comment_failed">留言失敗</string>
<string name="copy_comment_text">複製留言文字</string>
<string name="edit_comment">修改留言</string>
<string name="edit_comment_successfully">留言已被修改</string>
<string name="edit_comment_failed">修改留言失敗</string>
<string name="vote_up">推</string>
<string name="cancel_vote_up">收回推</string>
<string name="vote_down">噓</string>
+1
View File
@@ -65,6 +65,7 @@
<string name="pd_file_image" translatable="false">M13,9H18.5L13,3.5V9M6,2H14L20,8V20A2,2 0 0,1 18,22H6C4.89,22 4,21.1 4,20V4C4,2.89 4.89,2 6,2M6,20H15L18,20V12L14,16L12,14L6,20M8,9A2,2 0 0,0 6,11A2,2 0 0,0 8,13A2,2 0 0,0 10,11A2,2 0 0,0 8,9Z</string>
<string name="pd_eh_subscription" translatable="false">M20,8H4V6h16V8 M18,2H6v2h12V2 M20,10H4c-1.1,0-2,0.9-2,2v8c0,1.1,0.9,2,2,2h16c1.1,0,2-0.9,2-2v-8C22,10.9,21.1,10,20,10zM11,14H7v1h4v2H7v1h4v2H5v-8h6V14z M19,20h-2v-3h-2v3h-2v-8h2v3h2v-3h2V20z</string>
<string name="pd_copy" translatable="false">M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z</string>
<string name="pd_pencil" translatable="false">M20.71,7.04C21.1,6.65 21.1,6 20.71,5.63L18.37,3.29C18,2.9 17.35,2.9 16.96,3.29L15.12,5.12L18.87,8.87M3,17.25V21H6.75L17.81,9.93L14.06,6.18L3,17.25Z</string>
<string name="pd_big_label" translatable="false">M12.88,2H4V11L14.97,22.14L24,13.1L12.88,2ZM7.26,5.26C7.96,4.58,9.06,4.58,9.74,5.26C10.42,5.96,10.42,7.06,9.74,7.74S7.94,8.42,7.26,7.74S6.58,5.94,7.26,5.26ZM14.98,19.3L8.76,12.95L14.88,6.83L21.18,13.11L14.98,19.31ZM11.6,21.56L10.23,23L0,12.74V5H2V11.9L11.6,21.56Z</string>
<string name="pd_big_search" translatable="false">M20.46,14.65C21.86,16.15,20.31,18.6,18.32,17.87C19.78,17.57,20.79,16.37,20.46,14.65ZM4.32,17.87C6.32,18.6,7.86,16.17,6.46,14.65C6.79,16.38,5.78,17.55,4.32,17.87ZM16.87,4.3C16.6,3.56,15.87,3,15,3C13.7,3,12.7,4.24,13.1,5.58C14.2,5.18,15.44,4.48,16.87,4.31ZM24,16C24,18.76,21.76,21,19,21C14.96,21,14.84,16.88,12,16.88S9.04,21,5,21C2.24,21,0,18.76,0,16C0,13.87,1.53,11.43,3.94,7.18C5.84,3.81,8.69,5.92,10.76,6.58C11.54,6.85,12.41,6.88,13.24,6.58C15.3,5.92,18.14,3.81,20.06,7.18C22.46,11.43,24,13.88,24,16ZM8,16C8,14.35,6.65,13,5,13S2,14.35,2,16S3.35,19,5,19S8,17.65,8,16ZM13,14C13,13.45,12.55,13,12,13S11,13.45,11,14S11.45,15,12,15S13,14.55,13,14ZM22,16C22,14.35,20.65,13,19,13S16,14.35,16,16S17.35,19,19,19S22,17.65,22,16ZM9,3C8.14,3,7.4,3.55,7.13,4.3C8.56,4.48,9.79,5.2,10.9,5.58C11.3,4.24,10.3,3,9,3Z</string>
+2
View File
@@ -326,6 +326,8 @@
<string name="comment_failed">Failed to post the comment</string>
<string name="copy_comment_text">Copy comment text</string>
<string name="edit_comment">Edit comment</string>
<string name="edit_comment_successfully">The comment has been edited</string>
<string name="edit_comment_failed">Failed to edit the comment</string>
<string name="vote_up">Vote up</string>
<string name="cancel_vote_up">Cancel up-vote</string>
<string name="vote_down">Vote down</string>