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();
}
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);
}
}
Aggregations