#45: Android: Add comments

This commit is contained in:
jendib 2015-11-22 20:32:26 +01:00
parent 634ab7ec38
commit 60ee000b6c
10 changed files with 102 additions and 4 deletions

View File

@ -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();

View File

@ -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.
*

Binary file not shown.

After

Width:  |  Height:  |  Size: 296 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 565 B

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:background="?android:attr/selectableItemBackground">

View File

@ -52,13 +52,22 @@
<!-- Comments -->
<TextView
android:drawableStart="@drawable/ic_comment_black_24dp"
android:drawableLeft="@drawable/ic_comment_black_24dp"
android:drawablePadding="6dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:gravity="center"
android:textColor="@color/primary_text_default_material_light"
android:text="@string/comments"
android:layout_margin="12dp"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#eee"/>
<ListView
android:layout_weight="1"
android:id="@+id/commentListView"
@ -89,12 +98,45 @@
android:visibility="gone"
android:padding="12dp"
android:gravity="center"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="0dp"
android:fontFamily="sans-serif-light"
android:text="@string/no_comments"
android:textSize="14sp"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#eee"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="6dp"
android:gravity="center">
<EditText
android:id="@+id/commentEditText"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:lines="1"
android:inputType="text"
android:hint="@string/add_comment"
android:maxLength="4000"/>
<ImageButton
android:id="@+id/addCommentBtn"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@drawable/ic_send_grey600_24dp"
android:contentDescription="@string/send"
android:background="?android:selectableItemBackground"/>
</LinearLayout>
</LinearLayout>
<!-- Right drawer -->

View File

@ -12,7 +12,7 @@
<item
android:id="@+id/comments"
app:showAsAction="collapseActionView"
android:title="@string/show_comments">
android:title="@string/comments">
</item>
<item

View File

@ -107,10 +107,13 @@
<string name="all_languages">All languages</string>
<string name="toggle_informations">Toggle informations</string>
<string name="who_can_access">Who can access</string>
<string name="show_comments">Show comments</string>
<string name="comments">Comments</string>
<string name="no_comments">No comments</string>
<string name="error_loading_comments">Error loading comments</string>
<string name="send">Send</string>
<string name="add_comment">Add a comment</string>
<string name="comment_add_failure">Error adding a comment</string>
<string name="adding_comment">Adding a comment...</string>
</resources>