blob: fadf33b88e8ee051627c274faf76fb2a42472af3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
package it.niedermann.nextcloud.deck.ui.filter;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import it.niedermann.nextcloud.deck.databinding.DialogFilterLabelsBinding;
import it.niedermann.nextcloud.deck.model.Label;
import it.niedermann.nextcloud.deck.persistence.sync.SyncManager;
import it.niedermann.nextcloud.deck.ui.MainViewModel;
import static it.niedermann.nextcloud.deck.persistence.sync.adapters.db.util.LiveDataHelper.observeOnce;
import static java.util.Objects.requireNonNull;
public class FilterLabelsFragment extends Fragment implements SelectionListener<Label> {
private FilterViewModel filterViewModel;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final DialogFilterLabelsBinding binding = DialogFilterLabelsBinding.inflate(requireActivity().getLayoutInflater());
final MainViewModel mainViewModel = new ViewModelProvider(requireActivity()).get(MainViewModel.class);
filterViewModel = new ViewModelProvider(requireActivity()).get(FilterViewModel.class);
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(),
requireNonNull(filterViewModel.getFilterInformationDraft().getValue()).isNoAssignedLabel(),
this));
});
return binding.getRoot();
}
@Override
public void onItemSelected(@Nullable Label item) {
if (item == null) {
filterViewModel.setNotAssignedLabel(true);
} else {
filterViewModel.addFilterInformationDraftLabel(item);
}
}
@Override
public void onItemDeselected(@Nullable Label item) {
if (item == null) {
filterViewModel.setNotAssignedLabel(false);
} else {
filterViewModel.removeFilterInformationLabel(item);
}
}
}
|