Search in sources :

Example 1 with LabelAutoCompleteAdapter

use of it.niedermann.nextcloud.deck.ui.card.LabelAutoCompleteAdapter in project nextcloud-deck by stefan-niedermann.

the class CardDetailsFragment method setupLabels.

private void setupLabels() {
    final long accountId = viewModel.getAccount().getId();
    final long boardId = viewModel.getBoardId();
    binding.labelsGroup.removeAllViews();
    if (viewModel.canEdit()) {
        Long localCardId = viewModel.getFullCard().getCard().getLocalId();
        localCardId = localCardId == null ? -1 : localCardId;
        binding.labels.setAdapter(new LabelAutoCompleteAdapter(requireActivity(), accountId, boardId, localCardId));
        binding.labels.setOnItemClickListener((adapterView, view, position, id) -> {
            final var label = (Label) adapterView.getItemAtPosition(position);
            if (LabelAutoCompleteAdapter.ITEM_CREATE == label.getLocalId()) {
                final Label newLabel = new Label(label);
                newLabel.setBoardId(boardId);
                newLabel.setTitle(((LabelAutoCompleteAdapter) binding.labels.getAdapter()).getLastFilterText());
                newLabel.setLocalId(null);
                viewModel.createLabel(accountId, newLabel, boardId, new IResponseCallback<>() {

                    @Override
                    public void onResponse(Label response) {
                        requireActivity().runOnUiThread(() -> {
                            newLabel.setLocalId(response.getLocalId());
                            ((LabelAutoCompleteAdapter) binding.labels.getAdapter()).exclude(response);
                            viewModel.getFullCard().getLabels().add(response);
                            binding.labelsGroup.addView(createChipFromLabel(newLabel));
                            binding.labelsGroup.setVisibility(VISIBLE);
                        });
                    }

                    @Override
                    public void onError(Throwable throwable) {
                        IResponseCallback.super.onError(throwable);
                        requireActivity().runOnUiThread(() -> BrandedSnackbar.make(requireView(), getString(R.string.error_create_label, newLabel.getTitle()), Snackbar.LENGTH_LONG).setAction(R.string.simple_more, v -> ExceptionDialogFragment.newInstance(throwable, viewModel.getAccount()).show(getChildFragmentManager(), ExceptionDialogFragment.class.getSimpleName())).show());
                    }
                });
            } else {
                ((LabelAutoCompleteAdapter) binding.labels.getAdapter()).exclude(label);
                viewModel.getFullCard().getLabels().add(label);
                binding.labelsGroup.addView(createChipFromLabel(label));
                binding.labelsGroup.setVisibility(VISIBLE);
            }
            binding.labels.setText("");
        });
    } else {
        binding.labels.setEnabled(false);
    }
    if (viewModel.getFullCard().getLabels() != null && viewModel.getFullCard().getLabels().size() > 0) {
        for (final var label : viewModel.getFullCard().getLabels()) {
            binding.labelsGroup.addView(createChipFromLabel(label));
        }
        binding.labelsGroup.setVisibility(VISIBLE);
    } else {
        binding.labelsGroup.setVisibility(INVISIBLE);
    }
}
Also used : Chip(com.google.android.material.chip.Chip) LinearLayout(android.widget.LinearLayout) R(it.niedermann.nextcloud.deck.R) BrandingUtil.applyBrandToEditTextInputLayout(it.niedermann.nextcloud.deck.ui.branding.BrandingUtil.applyBrandToEditTextInputLayout) Bundle(android.os.Bundle) ColorUtil(it.niedermann.android.util.ColorUtil) INVISIBLE(android.view.View.INVISIBLE) NonNull(androidx.annotation.NonNull) TimePickerDialog(com.wdullaer.materialdatetimepicker.time.TimePickerDialog) ZonedDateTime(java.time.ZonedDateTime) DatePickerDialog(com.wdullaer.materialdatetimepicker.date.DatePickerDialog) LinkMovementMethod(android.text.method.LinkMovementMethod) Drawable(android.graphics.drawable.Drawable) ColorInt(androidx.annotation.ColorInt) ColorStateList(android.content.res.ColorStateList) BrandedTimePickerDialog(it.niedermann.nextcloud.deck.ui.branding.BrandedTimePickerDialog) IResponseCallback(it.niedermann.nextcloud.deck.api.IResponseCallback) Fragment(androidx.fragment.app.Fragment) LocalTime(java.time.LocalTime) VISIBLE(android.view.View.VISIBLE) View(android.view.View) ContextCompat(androidx.core.content.ContextCompat) Label(it.niedermann.nextcloud.deck.model.Label) MarkdownEditor(it.niedermann.android.markdown.MarkdownEditor) DeckLog(it.niedermann.nextcloud.deck.DeckLog) CardAssigneeListener(it.niedermann.nextcloud.deck.ui.card.assignee.CardAssigneeListener) OnTimeSetListener(com.wdullaer.materialdatetimepicker.time.TimePickerDialog.OnTimeSetListener) FullCard(it.niedermann.nextcloud.deck.model.full.FullCard) EditCardViewModel(it.niedermann.nextcloud.deck.ui.card.EditCardViewModel) ViewGroup(android.view.ViewGroup) ZoneId(java.time.ZoneId) ExceptionDialogFragment(it.niedermann.nextcloud.deck.ui.exception.ExceptionDialogFragment) Nullable(androidx.annotation.Nullable) GONE(android.view.View.GONE) LocalDate(java.time.LocalDate) FragmentCardEditTabDetailsBinding(it.niedermann.nextcloud.deck.databinding.FragmentCardEditTabDetailsBinding) Snackbar(com.google.android.material.snackbar.Snackbar) UserAutoCompleteAdapter(it.niedermann.nextcloud.deck.ui.card.UserAutoCompleteAdapter) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) FormatStyle(java.time.format.FormatStyle) LabelAutoCompleteAdapter(it.niedermann.nextcloud.deck.ui.card.LabelAutoCompleteAdapter) User(it.niedermann.nextcloud.deck.model.User) BrandedDatePickerDialog(it.niedermann.nextcloud.deck.ui.branding.BrandedDatePickerDialog) DimensionUtil(it.niedermann.android.util.DimensionUtil) DrawableCompat(androidx.core.graphics.drawable.DrawableCompat) OnDateSetListener(com.wdullaer.materialdatetimepicker.date.DatePickerDialog.OnDateSetListener) Px(androidx.annotation.Px) CardAssigneeDialog(it.niedermann.nextcloud.deck.ui.card.assignee.CardAssigneeDialog) BrandedSnackbar(it.niedermann.nextcloud.deck.ui.branding.BrandedSnackbar) ViewModelProvider(androidx.lifecycle.ViewModelProvider) LayoutInflater(android.view.LayoutInflater) TextUtils(android.text.TextUtils) DateTimeFormatter(java.time.format.DateTimeFormatter) ColorUtils(androidx.core.graphics.ColorUtils) ExceptionDialogFragment(it.niedermann.nextcloud.deck.ui.exception.ExceptionDialogFragment) LabelAutoCompleteAdapter(it.niedermann.nextcloud.deck.ui.card.LabelAutoCompleteAdapter) Label(it.niedermann.nextcloud.deck.model.Label)

Example 2 with LabelAutoCompleteAdapter

use of it.niedermann.nextcloud.deck.ui.card.LabelAutoCompleteAdapter in project nextcloud-deck by stefan-niedermann.

the class CardDetailsFragment method createChipFromLabel.

private Chip createChipFromLabel(Label label) {
    final var chip = new Chip(requireContext());
    chip.setText(label.getTitle());
    if (viewModel.canEdit()) {
        chip.setCloseIcon(ContextCompat.getDrawable(requireContext(), R.drawable.ic_close_circle_grey600));
        chip.setCloseIconVisible(true);
        chip.setOnCloseIconClickListener(v -> {
            binding.labelsGroup.removeView(chip);
            viewModel.getFullCard().getLabels().remove(label);
            ((LabelAutoCompleteAdapter) binding.labels.getAdapter()).exclude(label);
        });
    }
    try {
        final int labelColor = label.getColor();
        chip.setChipBackgroundColor(ColorStateList.valueOf(labelColor));
        final int color = ColorUtil.INSTANCE.getForegroundColorForBackgroundColor(labelColor);
        chip.setTextColor(color);
        if (chip.getCloseIcon() != null) {
            Drawable wrapDrawable = DrawableCompat.wrap(chip.getCloseIcon());
            DrawableCompat.setTint(wrapDrawable, ColorUtils.setAlphaComponent(color, 150));
        }
    } catch (IllegalArgumentException e) {
        DeckLog.logError(e);
    }
    return chip;
}
Also used : LabelAutoCompleteAdapter(it.niedermann.nextcloud.deck.ui.card.LabelAutoCompleteAdapter) Drawable(android.graphics.drawable.Drawable) Chip(com.google.android.material.chip.Chip)

Aggregations

Drawable (android.graphics.drawable.Drawable)2 Chip (com.google.android.material.chip.Chip)2 ColorStateList (android.content.res.ColorStateList)1 Bundle (android.os.Bundle)1 TextUtils (android.text.TextUtils)1 LinkMovementMethod (android.text.method.LinkMovementMethod)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 GONE (android.view.View.GONE)1 INVISIBLE (android.view.View.INVISIBLE)1 VISIBLE (android.view.View.VISIBLE)1 ViewGroup (android.view.ViewGroup)1 LinearLayout (android.widget.LinearLayout)1 ColorInt (androidx.annotation.ColorInt)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 Px (androidx.annotation.Px)1 ContextCompat (androidx.core.content.ContextCompat)1 ColorUtils (androidx.core.graphics.ColorUtils)1 DrawableCompat (androidx.core.graphics.drawable.DrawableCompat)1