Skip to content

Commit

Permalink
Comment functionality customized as per NMC.
Browse files Browse the repository at this point in the history
  • Loading branch information
surinder-tsys committed Jan 10, 2025
1 parent 50b4a86 commit d87ada7
Show file tree
Hide file tree
Showing 42 changed files with 1,718 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.nmc.android.ui

import android.content.Context
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.owncloud.android.databinding.CommentsActionsBottomSheetFragmentBinding
import com.owncloud.android.operations.comments.Comments


class CommentsActionsBottomSheetDialog(context: Context,
private val comments: Comments,
private val commentsBottomSheetActions: CommentsBottomSheetActions) : BottomSheetDialog(context) {

private lateinit var binding: CommentsActionsBottomSheetFragmentBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding = CommentsActionsBottomSheetFragmentBinding.inflate(layoutInflater)

setContentView(binding.root)

window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)

setOnShowListener {
BottomSheetBehavior.from(binding.root.parent as View)
.setPeekHeight(binding.root.measuredHeight)
}


binding.menuEditComment.setOnClickListener {
commentsBottomSheetActions.onUpdateComment(comments)
dismiss()
}

binding.menuDeleteComment.setOnClickListener {
commentsBottomSheetActions.onDeleteComment(comments)
dismiss()
}


}

interface CommentsBottomSheetActions {
fun onUpdateComment(comments: Comments)
fun onDeleteComment(comments: Comments)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.owncloud.android.operations.comments

/**
* response from the Get comments api
* <?xml version="1.0" encoding="UTF-8"?>
* <d:multistatus xmlns:d="DAV:" xmlns:nc="http://nextcloud.org/ns" xmlns:oc="http://owncloud.org/ns" xmlns:s="http://sabredav.org/ns">
* <d:response>
* <d:href>/remote.php/dav/comments/files/581625/</d:href>
* <d:propstat>
* <d:prop>
* <d:resourcetype>
* <d:collection />
* </d:resourcetype>
* <oc:readMarker>Wed, 05 Oct 2022 07:54:20 GMT</oc:readMarker>
* </d:prop>
* <d:status>HTTP/1.1 200 OK</d:status>
* </d:propstat>
* </d:response>
* <d:response>
* <d:href>/remote.php/dav/comments/files/581625/99</d:href>
* <d:propstat>
* <d:prop>
* <d:resourcetype />
* <oc:id>99</oc:id>
* <oc:parentId>0</oc:parentId>
* <oc:topmostParentId>0</oc:topmostParentId>
* <oc:childrenCount>0</oc:childrenCount>
* <oc:message>Cghjgrrg</oc:message>
* <oc:verb>comment</oc:verb>
* <oc:actorType>users</oc:actorType>
* <oc:actorId>120049010000000010088671</oc:actorId>
* <oc:creationDateTime>Wed, 05 Oct 2022 07:54:20 GMT</oc:creationDateTime>
* <oc:latestChildDateTime />
* <oc:objectType>files</oc:objectType>
* <oc:objectId>581625</oc:objectId>
* <oc:referenceId />
* <oc:reactions />
* <oc:actorDisplayName>Dev.Kumar</oc:actorDisplayName>
* <oc:mentions />
* <oc:isUnread>false</oc:isUnread>
* </d:prop>
* <d:status>HTTP/1.1 200 OK</d:status>
* </d:propstat>
* </d:response>
* </d:multistatus>
*/

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import java.util.*

@Parcelize
data class Comments(val path: String,
val commentId: Int,
val message: String,
val actorId: String,
val actorDisplayName: String,
val actorType: String,
val creationDateTime: Date? = null,
val isUnread: Boolean = false,
val objectId: String,
val objectType: String,
val verb: String) : Parcelable
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* ownCloud Android client application
*
* @author TSI-mc Copyright (C) 2021 TSI-mc
* <p>
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation.
* <p>
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* <p>
* You should have received a copy of the GNU General Public License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/

package com.owncloud.android.operations.comments;

import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.DeleteMethod;

/**
* class to delete the comment
* <p>
* API : //DELETE to dav/comments/files/{file_id}/{comment_id}
*/
public class DeleteCommentRemoteOperation extends RemoteOperation {

private static final String TAG = DeleteCommentRemoteOperation.class.getSimpleName();

private final long fileId;
private final int commentId;

public DeleteCommentRemoteOperation(long fileId, int commentId) {
this.fileId = fileId;
this.commentId = commentId;
}

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result;
int status;

DeleteMethod deleteMethod = null;

try {
//Delete Method
deleteMethod = new DeleteMethod(client.getCommentsUri(fileId) + "/" + commentId);

status = client.executeMethod(deleteMethod);

if (isSuccess(status)) {
result = new RemoteOperationResult<>(true, status, deleteMethod.getResponseHeaders());
return result;
} else {
result = new RemoteOperationResult<>(false, deleteMethod);
}

} catch (Exception e) {
result = new RemoteOperationResult<>(e);
Log_OC.e(TAG, "Exception while deleting comment", e);

} finally {
if (deleteMethod != null) {
deleteMethod.releaseConnection();
}
}
return result;
}

private boolean isSuccess(int status) {
return status == HttpStatus.SC_OK
|| status == HttpStatus.SC_NO_CONTENT
|| status == HttpStatus.SC_MULTI_STATUS;
}

}
Loading

0 comments on commit d87ada7

Please sign in to comment.