blob: 63441bbd49bc9a050f426a8646417fb21862c7db (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
package it.niedermann.nextcloud.deck.ui.card.attachments;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import it.niedermann.nextcloud.deck.R;
import it.niedermann.nextcloud.deck.model.Attachment;
import it.niedermann.nextcloud.deck.ui.branding.DeleteAlertDialogBuilder;
public class DeleteAttachmentDialogFragment extends DialogFragment {
private static final String KEY_ATTACHMENT = "attachment";
private AttachmentDeletedListener deleteAttachmentListener;
private Attachment attachment;
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
if (getParentFragment() instanceof AttachmentDeletedListener) {
this.deleteAttachmentListener = (AttachmentDeletedListener) getParentFragment();
} else if (context instanceof AttachmentDeletedListener) {
this.deleteAttachmentListener = (AttachmentDeletedListener) context;
} else {
throw new ClassCastException("Context or parent fragment must implement " + AttachmentDeletedListener.class.getCanonicalName());
}
if (getArguments() == null || !getArguments().containsKey(KEY_ATTACHMENT)) {
throw new IllegalArgumentException("Please provide at least " + KEY_ATTACHMENT + " as an argument");
} else {
this.attachment = (Attachment) getArguments().getSerializable(KEY_ATTACHMENT);
}
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new DeleteAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.delete_something, attachment.getFilename()))
.setMessage(R.string.attachment_delete_message)
.setPositiveButton(R.string.simple_delete, (dialog, whichButton) -> deleteAttachmentListener.onAttachmentDeleted(attachment))
.setNeutralButton(android.R.string.cancel, null)
.create();
}
public static DialogFragment newInstance(Attachment attachment) {
final var dialog = new DeleteAttachmentDialogFragment();
final var args = new Bundle();
args.putSerializable(KEY_ATTACHMENT, attachment);
dialog.setArguments(args);
return dialog;
}
}
|