diff --git a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java index 1e056730..5076978c 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java +++ b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java @@ -24,6 +24,8 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.Button; +import android.widget.EditText; +import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; @@ -243,6 +245,39 @@ public class DocumentViewActivity extends AppCompatActivity { } }); + // TODO Delete comment button + + ImageButton imageButton = (ImageButton) findViewById(R.id.addCommentBtn); + imageButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + final EditText commentEditText = (EditText) findViewById(R.id.commentEditText); + if (commentEditText.getText().length() == 0) { + // No content for the new comment + return; + } + + Toast.makeText(DocumentViewActivity.this, R.string.adding_comment, Toast.LENGTH_LONG).show(); + + CommentResource.add(DocumentViewActivity.this, + DocumentViewActivity.this.document.optString("id"), + commentEditText.getText().toString(), + new JsonHttpResponseHandler() { + public void onSuccess(int statusCode, Header[] headers, JSONObject response) { + // TODO Send a new comment event and update the adapter properly + // if there is no adapter yet (comments not loaded), do nothing + commentEditText.setText(""); + updateComments(); + } + + @Override + public void onAllFailure(int statusCode, Header[] headers, byte[] responseBytes, Throwable throwable) { + Toast.makeText(DocumentViewActivity.this, R.string.comment_add_failure, Toast.LENGTH_LONG).show(); + } + }); + } + }); + // Grab the comments updateComments(); diff --git a/docs-android/app/src/main/java/com/sismics/docs/resource/CommentResource.java b/docs-android/app/src/main/java/com/sismics/docs/resource/CommentResource.java index cf7bec0b..ca330ee1 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/resource/CommentResource.java +++ b/docs-android/app/src/main/java/com/sismics/docs/resource/CommentResource.java @@ -2,6 +2,7 @@ package com.sismics.docs.resource; import android.content.Context; +import com.loopj.android.http.RequestParams; import com.sismics.docs.listener.JsonHttpResponseHandler; @@ -24,6 +25,23 @@ public class CommentResource extends BaseResource { client.get(getApiUrl(context) + "/comment/" + documentId, responseHandler); } + /** + * PUT /comment. + * + * @param context Context + * @param documentId Document ID + * @param content Comment content + * @param responseHandler Callback + */ + public static void add(Context context, String documentId, String content, JsonHttpResponseHandler responseHandler) { + init(context); + + RequestParams params = new RequestParams(); + params.put("id", documentId); + params.put("content", content); + client.put(getApiUrl(context) + "/comment", params, responseHandler); + } + /** * Cancel pending requests. * diff --git a/docs-android/app/src/main/res/drawable-xhdpi/ic_comment_black_24dp.png b/docs-android/app/src/main/res/drawable-xhdpi/ic_comment_black_24dp.png new file mode 100644 index 00000000..412de9b0 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xhdpi/ic_comment_black_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xhdpi/ic_send_grey600_24dp.png b/docs-android/app/src/main/res/drawable-xhdpi/ic_send_grey600_24dp.png new file mode 100644 index 00000000..e1380462 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xhdpi/ic_send_grey600_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xxhdpi/ic_comment_black_24dp.png b/docs-android/app/src/main/res/drawable-xxhdpi/ic_comment_black_24dp.png new file mode 100644 index 00000000..382ee7a1 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xxhdpi/ic_comment_black_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xxhdpi/ic_send_grey600_24dp.png b/docs-android/app/src/main/res/drawable-xxhdpi/ic_send_grey600_24dp.png new file mode 100644 index 00000000..2c7a8026 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xxhdpi/ic_send_grey600_24dp.png differ diff --git a/docs-android/app/src/main/res/layout/comment_list_item.xml b/docs-android/app/src/main/res/layout/comment_list_item.xml index 7396aac6..eb444391 100644 --- a/docs-android/app/src/main/res/layout/comment_list_item.xml +++ b/docs-android/app/src/main/res/layout/comment_list_item.xml @@ -1,7 +1,7 @@ diff --git a/docs-android/app/src/main/res/layout/document_view_activity.xml b/docs-android/app/src/main/res/layout/document_view_activity.xml index 7a0d3cf9..b437c238 100644 --- a/docs-android/app/src/main/res/layout/document_view_activity.xml +++ b/docs-android/app/src/main/res/layout/document_view_activity.xml @@ -52,13 +52,22 @@ + + + + + + + + + + + + diff --git a/docs-android/app/src/main/res/menu/document_view_activity.xml b/docs-android/app/src/main/res/menu/document_view_activity.xml index bcf880e0..66ca28bf 100644 --- a/docs-android/app/src/main/res/menu/document_view_activity.xml +++ b/docs-android/app/src/main/res/menu/document_view_activity.xml @@ -12,7 +12,7 @@ + android:title="@string/comments"> All languages Toggle informations Who can access - Show comments Comments No comments Error loading comments + Send + Add a comment + Error adding a comment + Adding a comment...