Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstefan-niedermann <info@niedermann.it>2020-02-24 23:17:53 +0300
committerstefan-niedermann <info@niedermann.it>2020-02-24 23:17:53 +0300
commit68afde4e16cb47b1b3ac00ba4c064ee1c76be649 (patch)
tree464d0975adad956a6107eeff228bb3683c6decae
parent457e9948c23f2468293675303ad6e15f1da15a23 (diff)
Make attachments deletable on long press
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/ui/card/AttachmentAdapter.java24
-rw-r--r--app/src/main/res/layout/item_attachment_default.xml13
-rw-r--r--app/src/main/res/menu/attachment_menu.xml8
3 files changed, 21 insertions, 24 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/AttachmentAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/AttachmentAdapter.java
index dad498a62..2a60137cf 100644
--- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/AttachmentAdapter.java
+++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/AttachmentAdapter.java
@@ -1,5 +1,6 @@
package it.niedermann.nextcloud.deck.ui.card;
+import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
@@ -7,7 +8,6 @@ import android.text.format.Formatter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.ImageButton;
import android.widget.TextView;
import androidx.annotation.NonNull;
@@ -70,6 +70,18 @@ public class AttachmentAdapter extends RecyclerView.Adapter<AttachmentAdapter.At
Attachment attachment = attachments.get(position);
int viewType = getItemViewType(position);
holder.notSyncedYet.setVisibility(attachment.getStatusEnum() == DBStatus.UP_TO_DATE ? View.GONE : View.VISIBLE);
+ holder.preview.getRootView().setOnCreateContextMenuListener((menu, v, menuInfo) -> {
+ ((Activity) context).getMenuInflater().inflate(R.menu.attachment_menu, menu);
+ menu.findItem(R.id.delete).setOnMenuItemClickListener(item -> {
+ new DeleteDialogBuilder(context)
+ .setTitle(context.getString(R.string.delete_something, attachment.getFilename()))
+ .setMessage(R.string.attachment_delete_message)
+ .setNegativeButton(android.R.string.cancel, null)
+ .setPositiveButton(R.string.simple_delete, (dialog, which) -> attachmentDeletedListener.onAttachmentDeleted(attachment))
+ .show();
+ return false;
+ });
+ });
if (attachment.getMimetype() != null) {
if (attachment.getMimetype().startsWith("image")) {
@@ -113,14 +125,6 @@ public class AttachmentAdapter extends RecyclerView.Adapter<AttachmentAdapter.At
} else {
defaultHolder.modified.setVisibility(View.GONE);
}
- defaultHolder.deleteButton.setOnClickListener((v) -> {
- new DeleteDialogBuilder(context)
- .setTitle(context.getString(R.string.delete_something, attachment.getFilename()))
- .setMessage(R.string.attachment_delete_message)
- .setNegativeButton(android.R.string.cancel, null)
- .setPositiveButton(R.string.simple_delete, (dialog, which) -> attachmentDeletedListener.onAttachmentDeleted(attachment))
- .show();
- });
break;
}
}
@@ -155,8 +159,6 @@ public class AttachmentAdapter extends RecyclerView.Adapter<AttachmentAdapter.At
TextView filesize;
@BindView(R.id.modified)
TextView modified;
- @BindView(R.id.deleteButton)
- ImageButton deleteButton;
private DefaultAttachmentViewHolder(View view) {
super(view);
diff --git a/app/src/main/res/layout/item_attachment_default.xml b/app/src/main/res/layout/item_attachment_default.xml
index 26798c547..439e404c6 100644
--- a/app/src/main/res/layout/item_attachment_default.xml
+++ b/app/src/main/res/layout/item_attachment_default.xml
@@ -63,17 +63,4 @@
android:layout_gravity="end"
tools:text="Mar 4" />
</LinearLayout>
-
- <ImageButton
- android:id="@+id/deleteButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:layout_marginStart="@dimen/standard_half_margin"
- android:layout_marginLeft="@dimen/standard_half_margin"
- android:background="?android:selectableItemBackground"
- android:contentDescription="@string/simple_delete"
- android:padding="@dimen/standard_padding"
- android:scaleType="fitCenter"
- app:srcCompat="@drawable/ic_delete_black_24dp" />
</LinearLayout> \ No newline at end of file
diff --git a/app/src/main/res/menu/attachment_menu.xml b/app/src/main/res/menu/attachment_menu.xml
new file mode 100644
index 000000000..160cb63f8
--- /dev/null
+++ b/app/src/main/res/menu/attachment_menu.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto">
+ <item
+ android:id="@+id/delete"
+ android:title="@string/simple_delete"
+ app:showAsAction="never" />
+</menu>