use of android.view.View.INVISIBLE 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);
}
}
Aggregations