diff options
author | stefan-niedermann <info@niedermann.it> | 2020-03-07 13:53:36 +0300 |
---|---|---|
committer | stefan-niedermann <info@niedermann.it> | 2020-03-07 13:53:36 +0300 |
commit | 49534523248dfb3a6b54be41826944a62e4196d0 (patch) | |
tree | 23fdfdf9738c8f9cf42fc1280f6b7ffb8188e793 /app/src/main/java/it/niedermann/nextcloud/deck/ui/card/LabelAutoCompleteAdapter.java | |
parent | 1da0eeb70e98ac357861380788ea8cbbfb2dce84 (diff) |
#276 Add labels: possible adding a label more than once
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui/card/LabelAutoCompleteAdapter.java')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/card/LabelAutoCompleteAdapter.java | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/LabelAutoCompleteAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/LabelAutoCompleteAdapter.java index 685214ea9..ae9c77d1f 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/LabelAutoCompleteAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/LabelAutoCompleteAdapter.java @@ -9,7 +9,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.lifecycle.LiveData; -import java.util.ArrayList; import java.util.List; import it.niedermann.nextcloud.deck.R; @@ -24,8 +23,8 @@ public class LabelAutoCompleteAdapter extends AutoCompleteAdapter<Label> { private String lastFilterText; private boolean canManage = false; - LabelAutoCompleteAdapter(@NonNull ComponentActivity activity, long accountId, long boardId, long cardId) { - super(activity, accountId, boardId, cardId); + LabelAutoCompleteAdapter(@NonNull ComponentActivity activity, long accountId, long boardId, long cardId, List<Label> itemsToExclude) { + super(activity, accountId, boardId, cardId, itemsToExclude); syncManager.getFullBoardById(accountId, boardId).observe(activity, (fullBoard) -> { if (fullBoard.getBoard().isPermissionManage()) { canManage = true; @@ -74,28 +73,18 @@ public class LabelAutoCompleteAdapter extends AutoCompleteAdapter<Label> { ? syncManager.searchNotYetAssignedLabelsByTitle(accountId, boardId, cardId, constraint.toString()) : syncManager.findProposalsForLabelsToAssign(accountId, boardId, cardId, activity.getResources().getInteger(R.integer.max_labels_suggested)); liveData.observe(activity, (labels -> { + labels.removeAll(itemsToExclude); final boolean constraintLengthGreaterZero = constraint.toString().trim().length() > 0; if (canManage && constraintLengthGreaterZero) { if (createLabel == null) { throw new IllegalStateException("Owner has right to edit card, but createLable is null"); } createLabel.setTitle(String.format(activity.getString(R.string.label_add), constraint)); + labels.add(createLabel); } - if (labels != null) { - if (canManage && constraintLengthGreaterZero) { - labels.add(createLabel); - } - filterResults.values = labels; - filterResults.count = labels.size(); - publishResults(constraint, filterResults); - } else { - List<Label> createLabels = new ArrayList<>(); - if (canManage && constraintLengthGreaterZero) { - createLabels.add(createLabel); - } - filterResults.values = createLabels; - filterResults.count = createLabels.size(); - } + filterResults.values = labels; + filterResults.count = labels.size(); + publishResults(constraint, filterResults); })); }); } |