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>2019-12-07 01:08:22 +0300
committerstefan-niedermann <info@niedermann.it>2019-12-07 01:08:22 +0300
commit21e4b31bf7da469723e7504d182108d5cea8a4f9 (patch)
tree0aaf5b46ac2e3fb0f676b29d0f7850f7ceab76d6 /app/src/main/java
parent4389ec3cb997f6288ea0899584dca38bf083f51a (diff)
#211 Add / Delete attachments
User interface for deleting attachments
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/ui/card/AttachmentAdapter.java21
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardAttachmentsFragment.java10
2 files changed, 28 insertions, 3 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 5f1bddb42..49a9329a0 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
@@ -8,6 +8,7 @@ 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;
@@ -20,6 +21,7 @@ import butterknife.ButterKnife;
import it.niedermann.nextcloud.deck.R;
import it.niedermann.nextcloud.deck.model.Account;
import it.niedermann.nextcloud.deck.model.Attachment;
+import it.niedermann.nextcloud.deck.util.DeleteDialogBuilder;
public class AttachmentAdapter extends RecyclerView.Adapter<AttachmentAdapter.AttachmentViewHolder> {
@@ -27,10 +29,13 @@ public class AttachmentAdapter extends RecyclerView.Adapter<AttachmentAdapter.At
private final long cardRemoteId;
@NonNull
private List<Attachment> attachments;
+ @NonNull
+ private AttachmentDeletedListener attachmentDeletedListener;
private Context context;
- AttachmentAdapter(@NonNull Account account, long cardRemoteId, @NonNull List<Attachment> attachments) {
+ AttachmentAdapter(@NonNull AttachmentDeletedListener attachmentDeletedListener, @NonNull Account account, long cardRemoteId, @NonNull List<Attachment> attachments) {
super();
+ this.attachmentDeletedListener = attachmentDeletedListener;
this.attachments = attachments;
this.account = account;
this.cardRemoteId = cardRemoteId;
@@ -55,6 +60,14 @@ public class AttachmentAdapter extends RecyclerView.Adapter<AttachmentAdapter.At
openURL.setData(Uri.parse(account.getUrl() + "/index.php/apps/deck/cards/" + cardRemoteId + "/attachment/" + attachment.getId()));
context.startActivity(openURL);
});
+ holder.deleteButton.setOnClickListener((v) -> {
+ new DeleteDialogBuilder(context)
+ .setTitle(context.getString(R.string.delete_attachment, attachment.getFilename()))
+ .setMessage(R.string.attachment_delete_message)
+ .setNegativeButton(R.string.simple_cancel, null)
+ .setPositiveButton(R.string.simple_delete, (dialog, which) -> attachmentDeletedListener.onAttachmentDeleted(attachment))
+ .show();
+ });
}
@Override
@@ -69,10 +82,16 @@ public class AttachmentAdapter extends RecyclerView.Adapter<AttachmentAdapter.At
TextView filesize;
@BindView(R.id.modified)
TextView modified;
+ @BindView(R.id.deleteButton)
+ ImageButton deleteButton;
private AttachmentViewHolder(View view) {
super(view);
ButterKnife.bind(this, view);
}
}
+
+ public interface AttachmentDeletedListener {
+ void onAttachmentDeleted(Attachment attachment);
+ }
}
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardAttachmentsFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardAttachmentsFragment.java
index 70de758ab..94ccbb372 100644
--- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardAttachmentsFragment.java
+++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardAttachmentsFragment.java
@@ -26,6 +26,7 @@ import butterknife.ButterKnife;
import butterknife.Unbinder;
import it.niedermann.nextcloud.deck.R;
import it.niedermann.nextcloud.deck.model.Account;
+import it.niedermann.nextcloud.deck.model.Attachment;
import it.niedermann.nextcloud.deck.persistence.sync.SyncManager;
import static it.niedermann.nextcloud.deck.persistence.sync.adapters.db.util.LiveDataHelper.observeOnce;
@@ -34,7 +35,7 @@ import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.BUNDLE_KEY_BOARD_
import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.BUNDLE_KEY_CAN_EDIT;
import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.BUNDLE_KEY_LOCAL_ID;
-public class CardAttachmentsFragment extends Fragment {
+public class CardAttachmentsFragment extends Fragment implements AttachmentAdapter.AttachmentDeletedListener {
private Unbinder unbinder;
private static final String TAG = CardAttachmentsFragment.class.getCanonicalName();
@@ -77,7 +78,7 @@ public class CardAttachmentsFragment extends Fragment {
this.noAttachments.setVisibility(View.GONE);
this.attachmentsList.setVisibility(View.VISIBLE);
syncManager.readAccount(accountId).observe(CardAttachmentsFragment.this, (Account account) -> {
- RecyclerView.Adapter adapter = new AttachmentAdapter(account, fullCard.getCard().getId(), fullCard.getAttachments());
+ RecyclerView.Adapter adapter = new AttachmentAdapter(this, account, fullCard.getCard().getId(), fullCard.getAttachments());
attachmentsList.setAdapter(adapter);
});
}
@@ -145,4 +146,9 @@ public class CardAttachmentsFragment extends Fragment {
super.onDestroy();
unbinder.unbind();
}
+
+ @Override
+ public void onAttachmentDeleted(Attachment attachment) {
+ syncManager.deleteAttachmentToCard(accountId, cardId, attachment.getLocalId());
+ }
}