diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-03-27 17:47:51 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2020-03-27 22:42:51 +0300 |
commit | eb9f5607e48333dfdac83daf962f164af8e44cd0 (patch) | |
tree | bdef61846065b6a64f80ce72b584650e28fc5d92 /app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments | |
parent | 53c9411460c219d9eae3b918be47c413b221ac05 (diff) |
#341 Delete comments
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments')
3 files changed, 18 insertions, 3 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsAdapter.java index 6ff482207..00dfaa0f1 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsAdapter.java @@ -51,12 +51,15 @@ public class CardCommentsAdapter extends RecyclerView.Adapter<CardCommentsAdapte private final Account account; @NonNull private final MenuInflater menuInflater; + @NonNull + private final CommentDeletedListener commentDeletedListener; - CardCommentsAdapter(@NonNull Context context, @NonNull List<DeckComment> comments, @NonNull Account account, @NonNull MenuInflater menuInflater) { + CardCommentsAdapter(@NonNull Context context, @NonNull List<DeckComment> comments, @NonNull Account account, @NonNull MenuInflater menuInflater, @NonNull CommentDeletedListener commentDeletedListener) { this.context = context; this.comments = comments; this.account = account; this.menuInflater = menuInflater; + this.commentDeletedListener = commentDeletedListener; setHasStableIds(true); } @@ -80,7 +83,7 @@ public class CardCommentsAdapter extends RecyclerView.Adapter<CardCommentsAdapte holder.binding.creationDateTime.setText(DateUtil.getRelativeDateTimeString(context, comment.getCreationDateTime().getTime())); holder.binding.getRoot().setOnClickListener(View::showContextMenu); holder.binding.getRoot().setOnCreateContextMenuListener((menu, v, menuInfo) -> { - menuInflater.inflate(R.menu.activity_menu, menu); + menuInflater.inflate(R.menu.comment_menu, menu); menu.findItem(android.R.id.copy).setOnMenuItemClickListener(item -> { final ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE); ClipData clipData = ClipData.newPlainText(comment.getMessage(), comment.getMessage()); @@ -93,6 +96,10 @@ public class CardCommentsAdapter extends RecyclerView.Adapter<CardCommentsAdapte Toast.makeText(context, R.string.simple_copied, Toast.LENGTH_SHORT).show(); return true; }); + menu.findItem(R.id.delete).setOnMenuItemClickListener(item -> { + commentDeletedListener.onCommentDeleted(comment.getLocalId()); + return true; + }); }); TooltipCompat.setTooltipText(holder.binding.creationDateTime, DateFormat.getDateTimeInstance().format(comment.getCreationDateTime())); setupMentions(comment.getMentions(), holder.binding.message); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsFragment.java index ff6b829f6..90feac94f 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsFragment.java @@ -46,6 +46,9 @@ public class CardCommentsFragment extends Fragment { @Override public void onAttach(@NonNull Context context) { super.onAttach(context); + if (!(requireActivity() instanceof CommentDeletedListener)) { + throw new IllegalArgumentException("Caller must implement \"" + CommentDeletedListener.class.getCanonicalName() + "\""); + } Bundle args = getArguments(); if (args == null || !args.containsKey(BUNDLE_KEY_ACCOUNT_ID) || !args.containsKey(BUNDLE_KEY_LOCAL_ID)) { throw new IllegalArgumentException("Arguments must at least contain an account and the local card id"); @@ -68,7 +71,7 @@ public class CardCommentsFragment extends Fragment { if (comments != null && comments.size() > 0) { binding.emptyContentView.setVisibility(GONE); binding.comments.setVisibility(VISIBLE); - binding.comments.setAdapter(new CardCommentsAdapter(requireContext(), comments, account, requireActivity().getMenuInflater())); + binding.comments.setAdapter(new CardCommentsAdapter(requireContext(), comments, account, requireActivity().getMenuInflater(), (CommentDeletedListener) requireActivity())); } else { binding.emptyContentView.setVisibility(VISIBLE); binding.comments.setVisibility(GONE); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CommentDeletedListener.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CommentDeletedListener.java new file mode 100644 index 000000000..45a0a4740 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CommentDeletedListener.java @@ -0,0 +1,5 @@ +package it.niedermann.nextcloud.deck.ui.card.comments; + +public interface CommentDeletedListener { + void onCommentDeleted(Long localId); +} |