1
0
mirror of https://github.com/sismics/docs.git synced 2025-12-26 16:11:42 +00:00

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