Search in sources :

Example 1 with UserAutoCompleteAdapter

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

the class AccessControlDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    viewModel = new ViewModelProvider(requireActivity()).get(MainViewModel.class);
    final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(requireContext());
    binding = DialogBoardShareBinding.inflate(requireActivity().getLayoutInflater());
    adapter = new AccessControlAdapter(viewModel.getCurrentAccount(), this, requireContext());
    binding.peopleList.setAdapter(adapter);
    viewModel.getFullBoardById(viewModel.getCurrentAccount().getId(), boardId).observe(this, (FullBoard fullBoard) -> {
        if (fullBoard != null) {
            viewModel.getAccessControlByLocalBoardId(viewModel.getCurrentAccount().getId(), boardId).observe(this, (List<AccessControl> accessControlList) -> {
                final AccessControl ownerControl = new AccessControl();
                ownerControl.setLocalId(HEADER_ITEM_LOCAL_ID);
                ownerControl.setUser(fullBoard.getOwner());
                accessControlList.add(0, ownerControl);
                adapter.update(accessControlList, fullBoard.getBoard().isPermissionManage());
                userAutoCompleteAdapter = new UserAutoCompleteAdapter(requireActivity(), viewModel.getCurrentAccount(), boardId);
                binding.people.setAdapter(userAutoCompleteAdapter);
                binding.people.setOnItemClickListener(this);
            });
            applyBrand(fullBoard.getBoard().getColor());
        } else {
            // Happens when someone revokes his own access → board gets deleted locally → LiveData fires, but no board
            // see https://github.com/stefan-niedermann/nextcloud-deck/issues/410
            dismiss();
        }
    });
    return dialogBuilder.setTitle(R.string.share_board).setView(binding.getRoot()).setPositiveButton(R.string.simple_close, null).create();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) UserAutoCompleteAdapter(it.niedermann.nextcloud.deck.ui.card.UserAutoCompleteAdapter) FullBoard(it.niedermann.nextcloud.deck.model.full.FullBoard) List(java.util.List) AccessControl(it.niedermann.nextcloud.deck.model.AccessControl) ViewModelProvider(androidx.lifecycle.ViewModelProvider) MainViewModel(it.niedermann.nextcloud.deck.ui.MainViewModel) NonNull(androidx.annotation.NonNull)

Example 2 with UserAutoCompleteAdapter

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

the class CardDetailsFragment method setupAssignees.

private void setupAssignees() {
    adapter = new AssigneeAdapter((user) -> CardAssigneeDialog.newInstance(user).show(getChildFragmentManager(), CardAssigneeDialog.class.getSimpleName()), viewModel.getAccount());
    binding.assignees.setAdapter(adapter);
    binding.assignees.post(() -> {
        @Px final int gutter = DimensionUtil.INSTANCE.dpToPx(requireContext(), R.dimen.spacer_1x);
        final int spanCount = (int) (float) binding.assignees.getWidth() / (DimensionUtil.INSTANCE.dpToPx(requireContext(), R.dimen.avatar_size) + gutter);
        binding.assignees.setLayoutManager(new GridLayoutManager(getContext(), spanCount));
        binding.assignees.addItemDecoration(new AssigneeDecoration(gutter));
    });
    if (viewModel.canEdit()) {
        Long localCardId = viewModel.getFullCard().getCard().getLocalId();
        localCardId = localCardId == null ? -1 : localCardId;
        binding.people.setAdapter(new UserAutoCompleteAdapter(requireActivity(), viewModel.getAccount(), viewModel.getBoardId(), localCardId));
        binding.people.setOnItemClickListener((adapterView, view, position, id) -> {
            User user = (User) adapterView.getItemAtPosition(position);
            viewModel.getFullCard().getAssignedUsers().add(user);
            ((UserAutoCompleteAdapter) binding.people.getAdapter()).exclude(user);
            adapter.addUser(user);
            binding.people.setText("");
        });
        if (this.viewModel.getFullCard().getAssignedUsers() != null) {
            adapter.setUsers(this.viewModel.getFullCard().getAssignedUsers());
        }
    } else {
        binding.people.setEnabled(false);
    }
}
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) User(it.niedermann.nextcloud.deck.model.User) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) UserAutoCompleteAdapter(it.niedermann.nextcloud.deck.ui.card.UserAutoCompleteAdapter) Px(androidx.annotation.Px) CardAssigneeDialog(it.niedermann.nextcloud.deck.ui.card.assignee.CardAssigneeDialog)

Aggregations

NonNull (androidx.annotation.NonNull)2 ViewModelProvider (androidx.lifecycle.ViewModelProvider)2 UserAutoCompleteAdapter (it.niedermann.nextcloud.deck.ui.card.UserAutoCompleteAdapter)2 ColorStateList (android.content.res.ColorStateList)1 Drawable (android.graphics.drawable.Drawable)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 Nullable (androidx.annotation.Nullable)1 Px (androidx.annotation.Px)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 ContextCompat (androidx.core.content.ContextCompat)1