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

EditLabelDialogFragment.java « managelabels « board « 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: 7570510fd4c992907204096c372c75d679225926 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
package it.niedermann.nextcloud.deck.ui.board.managelabels;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

import it.niedermann.nextcloud.deck.R;
import it.niedermann.nextcloud.deck.databinding.DialogTextColorInputBinding;
import it.niedermann.nextcloud.deck.model.Label;
import it.niedermann.nextcloud.deck.ui.branding.BrandedActivity;
import it.niedermann.nextcloud.deck.ui.branding.BrandedAlertDialogBuilder;
import it.niedermann.nextcloud.deck.ui.branding.BrandedDialogFragment;

public class EditLabelDialogFragment extends BrandedDialogFragment {

    private DialogTextColorInputBinding binding;

    private static final String KEY_LABEL = "label";

    private EditLabelListener listener;

    private Label label = null;

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

        final Bundle args = getArguments();

        if (args == null) {
            throw new IllegalArgumentException("Provide at least " + KEY_LABEL);
        }

        final Label label = (Label) args.getSerializable(KEY_LABEL);
        if (label == null) {
            throw new IllegalArgumentException(KEY_LABEL + " must not be null");
        }
        this.label = new Label(label);
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DialogTextColorInputBinding.inflate(requireActivity().getLayoutInflater());

        AlertDialog.Builder dialogBuilder = new BrandedAlertDialogBuilder(requireContext());

        dialogBuilder.setTitle(getString(R.string.edit_tag, label.getTitle()));
        dialogBuilder.setPositiveButton(R.string.simple_save, (dialog, which) -> {
            this.label.setColor(binding.colorChooser.getSelectedColor().substring(1));
            this.label.setTitle(binding.input.getText().toString());
            listener.onLabelUpdated(this.label);
        });
        String title = this.label.getTitle();
        binding.input.setText(title);
        binding.input.setSelection(title.length());
        binding.colorChooser.selectColor("#" + this.label.getColor());

        return dialogBuilder
                .setView(binding.getRoot())
                .setNeutralButton(android.R.string.cancel, null)
                .create();
    }

    public static DialogFragment newInstance(@NonNull Label label) {
        final DialogFragment dialog = new EditLabelDialogFragment();

        final Bundle args = new Bundle();
        args.putSerializable(KEY_LABEL, label);
        dialog.setArguments(args);

        return dialog;
    }

    @Override
    public void applyBrand(int mainColor, int textColor) {
        BrandedActivity.applyBrandToEditText(mainColor, textColor, binding.input);
    }
}