Drive Kit allows your app to provide the reply function for users, including adding, viewing, updating, and deleting replies to comments on files in the cloud.
1. You have made all necessary preparations.
2. You have downloaded the client sample code and tried it out.
private Drive buildDrive() {
Drive service = new Drive.Builder(CredentialManager.getInstance().getCredential(), context).build();
return service;
} Call the Replies.Create API to create a reply to a comment.
/**
* Create a reply to a comment.
*
* @param fileId File ID.
* @param commentId Comment ID.
*/
private Reply createReplies(String fileId, String commentId) {
Reply replyResponse = null;
Drive drive = buildDrive();
try {
Reply reply = new Reply();
reply.setDescription("interface test reply");
reply.setOperate("resolve");
replyResponse = drive.replies().create(fileId, commentId, reply).setFields("*").execute();
} catch (Exception ex) {
Log.e(TAG, "createReplies error: " + ex.toString());
}
return replyResponse;
} Call the Replies.List API to list replies to a comment.
/**
* List replies to the comment.
*
* @param fileId File ID.
* @param commentId Comment ID.
*/
private List<Reply> listReplies(String fileId, String commentId) {
Drive drive = buildDrive();
List<Reply> replyResponse = new ArrayList<>();
String nextCursor = null;
try {
Drive.Replies.List listReq = drive.replies().list(fileId, commentId);
do {
if (nextCursor != null) {
listReq.setCursor(nextCursor);
}
ReplyList replyList = listReq.setFields("*").execute();
List<Reply> replies = replyList.getReplies();
if (replies == null) {
break;
}
replyResponse.addAll(replies);
nextCursor = replyList.getNextCursor();
} while (StringUtils.isNullOrEmpty(nextCursor));
} catch (Exception ex) {
Log.e(TAG, "listReplies error: " + ex.toString());
}
return replyResponse;
} Call the Replies.Get API to obtain reply details.
/**
* Obtain reply details.
*
* @param fileId File ID.
* @param commentId Comment ID.
* @param replyId Reply ID.
*/
private Reply getReplies(String fileId, String commentId, String replyId) {
Reply reply = null;
Drive drive = buildDrive();
try {
reply = drive.replies().get(fileId, commentId, replyId).setFields("*").execute();
} catch (Exception ex) {
Log.e(TAG, "getReplies error: " + ex.toString());
}
return reply;
} Call the Replies.Update API to update a reply.
/**
* Update a reply.
*
* @param fileId File ID.
* @param commentId Comment ID.
* @param replyId Reply ID.
*/
private void updateReplies(String fileId, String commentId, String replyId) {
Drive drive = buildDrive();
try {
Reply reply = new Reply();
reply.setDescription("interface test reply");
reply.setOperate("reopen");
drive.replies().update(fileId, commentId, replyId, reply).execute();
} catch (Exception ex) {
Log.e(TAG, "updateReplies error: " + ex.toString());
}
} Call the Replies.Delete API to delete a reply.
/**
* Delete a reply.
*
* @param fileId File ID.
* @param commentId Comment ID.
* @param replyId Reply ID.
*/
private void deleteReplies(String fileId, String commentId, String replyId) {
Drive drive = buildDrive();
try {
drive.replies().delete(fileId, commentId, replyId).execute();
} catch (Exception ex) {
Log.e(TAG, "deleteReplies error: " + ex.toString());
}
}
Call the Replies APIs in the subthread. The process of replying to a comment takes a while and requires an Internet connection.