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

UpcomingCardsViewModel.java « upcomingcards « 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: 870a23cdcbbc97af4a6fc7607019388e9ed22a6d (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
package it.niedermann.nextcloud.deck.ui.upcomingcards;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;

import com.nextcloud.android.sso.api.EmptyResponse;
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException;

import java.util.List;

import it.niedermann.nextcloud.deck.model.Account;
import it.niedermann.nextcloud.deck.model.Card;
import it.niedermann.nextcloud.deck.model.full.FullCard;
import it.niedermann.nextcloud.deck.remote.api.IResponseCallback;
import it.niedermann.nextcloud.deck.repository.SyncRepository;
import it.niedermann.nextcloud.deck.ui.viewmodel.BaseViewModel;

@SuppressWarnings("WeakerAccess")
public class UpcomingCardsViewModel extends BaseViewModel {

    public UpcomingCardsViewModel(@NonNull Application application) {
        super(application);
    }

    public LiveData<List<UpcomingCardsAdapterItem>> getUpcomingCards() {
        return this.baseRepository.getCardsForUpcomingCards();
    }

    public void assignUser(@NonNull Account account, @NonNull Card card) throws NextcloudFilesAppAccountNotFoundException {
        final var syncManager = new SyncRepository(getApplication(), account);
        executor.submit(() -> syncManager.assignUserToCard(baseRepository.getUserByUidDirectly(card.getAccountId(), account.getUserName()), card));
    }

    public void unassignUser(@NonNull Account account, @NonNull Card card) throws NextcloudFilesAppAccountNotFoundException {
        final var syncManager = new SyncRepository(getApplication(), account);
        executor.submit(() -> syncManager.unassignUserFromCard(baseRepository.getUserByUidDirectly(card.getAccountId(), account.getUserName()), card));
    }

    public void archiveCard(@NonNull FullCard card, @NonNull IResponseCallback<FullCard> callback) {
        executor.submit(() -> {
            final var account = baseRepository.readAccountDirectly(card.getAccountId());
            try {
                final var syncManager = new SyncRepository(getApplication(), account);
                syncManager.archiveCard(card, callback);
            } catch (NextcloudFilesAppAccountNotFoundException e) {
                callback.onError(e);
            }
        });
    }

    public void deleteCard(@NonNull Card card, @NonNull IResponseCallback<EmptyResponse> callback) {
        executor.submit(() -> {
            final var account = baseRepository.readAccountDirectly(card.getAccountId());
            try {
                final var syncManager = new SyncRepository(getApplication(), account);
                syncManager.deleteCard(card, callback);
            } catch (NextcloudFilesAppAccountNotFoundException e) {
                callback.onError(e);
            }
        });
    }

    public void moveCard(long originAccountId, long originCardLocalId, long targetAccountId, long targetBoardLocalId, long targetStackLocalId, @NonNull IResponseCallback<EmptyResponse> callback) {
        executor.submit(() -> {
            final var account = baseRepository.readAccountDirectly(originAccountId);
            try {
                final var syncManager = new SyncRepository(getApplication(), account);
                syncManager.moveCard(originAccountId, originCardLocalId, targetAccountId, targetBoardLocalId, targetStackLocalId, callback);
            } catch (NextcloudFilesAppAccountNotFoundException e) {
                callback.onError(e);
            }
        });
    }
}