diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-07-21 15:16:03 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2020-07-21 21:22:40 +0300 |
commit | 781b158a58c0948aa2e0e876fbfc141ae89a9245 (patch) | |
tree | 2deea75f5a6753492402b51db28aa4d1b786f7a2 /app/src | |
parent | ec11924585d21889cfb9588bbda89932d81173fb (diff) |
#615 Add filter "No tags"
Diffstat (limited to 'app/src')
5 files changed, 56 insertions, 7 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java index f69c93b19..74e609ea3 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java @@ -192,6 +192,11 @@ public class DataBaseAdapter { query.append("and exists(select 1 from joincardwithlabel j where c.localId = cardId and labelId in ("); fillSqlWithListValues(query, args, filter.getLabels()); query.append(") and j.status<>3) "); + if (filter.isNoAssignedLabel()) { + query.append("or not exists(select 1 from joincardwithlabel j where c.localId = cardId and j.status<>3)) "); + } else { + query.append(") "); + } } if (!filter.getUsers().isEmpty()) { @@ -555,7 +560,7 @@ public class DataBaseAdapter { } private void notifyStackWidgetsIfNeeded(String cardTitle, long... affectedStackIds) { - if (db.getStackWidgetModelDao().containsStackLocalId(affectedStackIds)){ + if (db.getStackWidgetModelDao().containsStackLocalId(affectedStackIds)) { DeckLog.info("Notifying " + StackWidget.class.getSimpleName() + " about card changes for \"" + cardTitle + "\""); StackWidget.notifyDatasetChanged(context); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterLabelsAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterLabelsAdapter.java index 096f0db9c..17d3599e7 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterLabelsAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterLabelsAdapter.java @@ -7,11 +7,13 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; import java.util.List; +import it.niedermann.nextcloud.deck.R; import it.niedermann.nextcloud.deck.databinding.ItemFilterLabelBinding; import it.niedermann.nextcloud.deck.model.Label; import it.niedermann.nextcloud.deck.util.ColorUtil; @@ -23,11 +25,16 @@ public class FilterLabelsAdapter extends RecyclerView.Adapter<FilterLabelsAdapte @NonNull private final List<Label> selectedLabels = new ArrayList<>(); @Nullable + private static final Label NOT_ASSIGNED = null; + @Nullable private final SelectionListener<Label> selectionListener; - public FilterLabelsAdapter(@NonNull List<Label> labels, @NonNull List<Label> selectedLabels, @Nullable SelectionListener<Label> selectionListener) { + public FilterLabelsAdapter(@NonNull List<Label> labels, @NonNull List<Label> selectedLabels, boolean noAssignedLabel, @Nullable SelectionListener<Label> selectionListener) { super(); this.labels.addAll(labels); + if (noAssignedLabel) { + this.selectedLabels.add(NOT_ASSIGNED); + } this.selectedLabels.addAll(selectedLabels); this.selectionListener = selectionListener; setHasStableIds(true); @@ -47,7 +54,13 @@ public class FilterLabelsAdapter extends RecyclerView.Adapter<FilterLabelsAdapte @Override public void onBindViewHolder(@NonNull LabelViewHolder viewHolder, int position) { + final Label label = labels.get(position); viewHolder.bind(labels.get(position)); + if (position == 0) { + viewHolder.bindNotAssigned(label); + } else { + viewHolder.bind(label); + } } @Override @@ -74,7 +87,19 @@ public class FilterLabelsAdapter extends RecyclerView.Adapter<FilterLabelsAdapte final int color = ColorUtil.getForegroundColorForBackgroundColor(labelColor); binding.label.setTextColor(color); itemView.setSelected(selectedLabels.contains(label)); + bindClickListener(label); + } + + public void bindNotAssigned(Label label) { + binding.label.setText(itemView.getContext().getString(R.string.no_assigned_label)); + binding.label.setTextColor(ColorStateList.valueOf(ContextCompat.getColor(itemView.getContext(), R.color.accent))); + binding.label.setChipIcon(ContextCompat.getDrawable(itemView.getContext(), R.drawable.ic_baseline_block_24)); + binding.label.setChipBackgroundColor(ColorStateList.valueOf(ContextCompat.getColor(itemView.getContext(), android.R.color.transparent))); + binding.label.setRippleColor(null); + bindClickListener(label); + } + private void bindClickListener(@Nullable Label label) { itemView.setOnClickListener(view -> { if (selectedLabels.contains(label)) { selectedLabels.remove(label); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterLabelsFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterLabelsFragment.java index 357f93cf9..fadf33b88 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterLabelsFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterLabelsFragment.java @@ -33,19 +33,31 @@ public class FilterLabelsFragment extends Fragment implements SelectionListener< observeOnce(new SyncManager(requireContext()).findProposalsForLabelsToAssign(mainViewModel.getCurrentAccount().getId(), mainViewModel.getCurrentBoardLocalId()), requireActivity(), (labels) -> { binding.labels.setNestedScrollingEnabled(false); - binding.labels.setAdapter(new FilterLabelsAdapter(labels, requireNonNull(filterViewModel.getFilterInformationDraft().getValue()).getLabels(), this)); + binding.labels.setAdapter(new FilterLabelsAdapter( + labels, + requireNonNull(filterViewModel.getFilterInformationDraft().getValue()).getLabels(), + requireNonNull(filterViewModel.getFilterInformationDraft().getValue()).isNoAssignedLabel(), + this)); }); return binding.getRoot(); } @Override - public void onItemSelected(Label item) { - filterViewModel.addFilterInformationDraftLabel(item); + public void onItemSelected(@Nullable Label item) { + if (item == null) { + filterViewModel.setNotAssignedLabel(true); + } else { + filterViewModel.addFilterInformationDraftLabel(item); + } } @Override - public void onItemDeselected(Label item) { - filterViewModel.removeFilterInformationLabel(item); + public void onItemDeselected(@Nullable Label item) { + if (item == null) { + filterViewModel.setNotAssignedLabel(false); + } else { + filterViewModel.removeFilterInformationLabel(item); + } } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterViewModel.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterViewModel.java index 121df3387..50f287d62 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterViewModel.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterViewModel.java @@ -72,6 +72,12 @@ public class FilterViewModel extends ViewModel { this.filterInformationDraft.postValue(newDraft); } + public void setNotAssignedLabel(boolean notAssignedLabel) { + FilterInformation newDraft = new FilterInformation(filterInformationDraft.getValue()); + newDraft.setNoAssignedLabel(notAssignedLabel); + this.filterInformationDraft.postValue(newDraft); + } + public void removeFilterInformationLabel(@NonNull Label label) { FilterInformation newDraft = new FilterInformation(filterInformationDraft.getValue()); newDraft.removeLabel(label); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1e1086a88..5991a1c64 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -295,4 +295,5 @@ <string name="widget_stack_header_icon">Widget header icon</string> <string name="widget_stack_placeholder_icon">Widget placeholder icon</string> <string name="select_stack">Select list</string> + <string name="no_assigned_label">No assigned label</string> </resources> |