Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FilterViewModel.java « filter « ui « deck « nextcloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c42a61ebd8733bb0f5c89d120af6cb7658b2a114 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package it.niedermann.nextcloud.deck.ui.filter;

import android.app.Application;

import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import java.util.List;

import it.niedermann.nextcloud.deck.model.Label;
import it.niedermann.nextcloud.deck.model.User;
import it.niedermann.nextcloud.deck.model.enums.EDueType;
import it.niedermann.nextcloud.deck.model.internal.FilterInformation;
import it.niedermann.nextcloud.deck.persistence.sync.SyncManager;

import static it.niedermann.nextcloud.deck.model.internal.FilterInformation.hasActiveFilter;

@SuppressWarnings("WeakerAccess")
public class FilterViewModel extends AndroidViewModel {

    private final SyncManager syncManager;

    @IntRange(from = 0, to = 2)
    private int currentFilterTab = 0;

    @NonNull
    private final MutableLiveData<FilterInformation> filterInformationDraft = new MutableLiveData<>(new FilterInformation());
    @NonNull
    private final MutableLiveData<FilterInformation> filterInformation = new MutableLiveData<>();

    public FilterViewModel(@NonNull Application application) {
        super(application);
        this.syncManager = new SyncManager(application);
    }

    public void publishFilterInformationDraft() {
        this.filterInformation.postValue(hasActiveFilter(filterInformationDraft.getValue()) ? filterInformationDraft.getValue() : null);
    }

    public void clearFilterInformation() {
        this.filterInformationDraft.setValue(new FilterInformation());
        this.publishFilterInformationDraft();
        this.currentFilterTab = 0;
    }

    @NonNull
    public LiveData<FilterInformation> getFilterInformationDraft() {
        return this.filterInformationDraft;
    }

    public void createFilterInformationDraft() {
        this.filterInformationDraft.postValue(new FilterInformation(this.filterInformation.getValue()));
    }

    @NonNull
    public LiveData<FilterInformation> getFilterInformation() {
        return this.filterInformation;
    }

    public void setFilterInformationDraftDueType(@NonNull EDueType dueType) {
        FilterInformation newDraft = new FilterInformation(filterInformationDraft.getValue());
        newDraft.setDueType(dueType);
        this.filterInformationDraft.postValue(newDraft);
    }

    public void addFilterInformationDraftLabel(@NonNull Label label) {
        FilterInformation newDraft = new FilterInformation(filterInformationDraft.getValue());
        newDraft.addLabel(label);
        this.filterInformationDraft.postValue(newDraft);
    }

    public void addFilterInformationUser(@NonNull User user) {
        FilterInformation newDraft = new FilterInformation(filterInformationDraft.getValue());
        newDraft.addUser(user);
        this.filterInformationDraft.postValue(newDraft);
    }

    public void setNotAssignedUser(boolean notAssignedUser) {
        FilterInformation newDraft = new FilterInformation(filterInformationDraft.getValue());
        newDraft.setNoAssignedUser(notAssignedUser);
        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);
        this.filterInformationDraft.postValue(newDraft);
    }

    public void removeFilterInformationUser(@NonNull User user) {
        FilterInformation newDraft = new FilterInformation(filterInformationDraft.getValue());
        newDraft.removeUser(user);
        this.filterInformationDraft.postValue(newDraft);
    }

    public void setCurrentFilterTab(@IntRange(from = 0, to = 2) int newFilterTab) {
        this.currentFilterTab = newFilterTab;
    }

    @IntRange(from = 0, to = 2)
    public int getCurrentFilterTab() {
        return this.currentFilterTab;
    }

    public LiveData<List<User>> findProposalsForUsersToAssign(final long accountId, long boardId) {
        return syncManager.findProposalsForUsersToAssign(accountId, boardId, -1L, -1);
    }

    public LiveData<List<Label>> findProposalsForLabelsToAssign(final long accountId, final long boardId) {
        return syncManager.findProposalsForLabelsToAssign(accountId, boardId, -1L);
    }
}