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

DeleteStackDialogFragment.java « stack « ui « deck « nextcloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 65e4496860c999ab1056f5df997fd5edd7574dfe (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package it.niedermann.nextcloud.deck.ui.stack;

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.ui.theme.DeleteAlertDialogBuilder;
import it.niedermann.nextcloud.deck.ui.theme.ThemedDialogFragment;

public class DeleteStackDialogFragment extends ThemedDialogFragment {

    private static final String KEY_ACCOUNT_ID = "account_id";
    private static final String KEY_BOARD_ID = "board_id";
    private static final String KEY_STACK_ID = "stack_id";
    private static final String KEY_NUMBER_CARDS = "number_cards";

    private DeleteStackListener deleteStackListener;
    private long accountId;
    private long boardId;
    private long stackId;
    private int numberCards;

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        if (context instanceof DeleteStackListener) {
            this.deleteStackListener = (DeleteStackListener) context;
        } else {
            throw new ClassCastException("Caller must implement " + DeleteStackListener.class.getCanonicalName());
        }

        final Bundle args = getArguments();

        if (args == null || !args.containsKey(KEY_ACCOUNT_ID) || !args.containsKey(KEY_BOARD_ID) || !args.containsKey(KEY_STACK_ID) || !args.containsKey(KEY_NUMBER_CARDS)) {
            throw new IllegalArgumentException("Please provide at least " + KEY_ACCOUNT_ID + ", " + KEY_BOARD_ID + ", " + KEY_STACK_ID + " and " + KEY_NUMBER_CARDS + " as arguments");
        }

        this.accountId = args.getLong(KEY_ACCOUNT_ID);
        this.boardId = args.getLong(KEY_BOARD_ID);
        this.stackId = args.getLong(KEY_STACK_ID);
        this.numberCards = args.getInt(KEY_NUMBER_CARDS);
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        return new DeleteAlertDialogBuilder(requireContext())
                .setTitle(R.string.delete_list)
                .setMessage(getResources().getQuantityString(R.plurals.do_you_want_to_delete_the_current_list, numberCards, numberCards))
                .setPositiveButton(R.string.simple_delete, (dialog, whichButton) -> deleteStackListener.onDeleteStack(accountId, boardId, stackId))
                .setNeutralButton(android.R.string.cancel, null)
                .create();
    }

    @Override
    public void applyTheme(int color) {

    }

    public static DialogFragment newInstance(long accountId, long boardId, long stackId, int numberCards) {
        final var dialog = new DeleteStackDialogFragment();

        final var args = new Bundle();
        args.putLong(KEY_ACCOUNT_ID, accountId);
        args.putLong(KEY_BOARD_ID, boardId);
        args.putLong(KEY_STACK_ID, stackId);
        args.putInt(KEY_NUMBER_CARDS, numberCards);
        dialog.setArguments(args);

        return dialog;
    }
}