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

github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Niedermann <info@niedermann.it>2020-12-09 19:12:32 +0300
committerStefan Niedermann <info@niedermann.it>2020-12-09 19:12:32 +0300
commita2cd1b556c806c2521924b62eada5751585b1c86 (patch)
tree19bff1e5630aac90e3e63c3dbb75fb0a94c3d6af /app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationViewModel.java
parent12781a2ec9e0b8f0e8048a41d187176dbed4afc4 (diff)
Decouple SyncManager from UIs and use ViewModel between them
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationViewModel.java')
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationViewModel.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationViewModel.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationViewModel.java
new file mode 100644
index 000000000..d15b412f4
--- /dev/null
+++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationViewModel.java
@@ -0,0 +1,52 @@
+package it.niedermann.nextcloud.deck.ui;
+
+import android.app.Application;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.lifecycle.AndroidViewModel;
+import androidx.lifecycle.LiveData;
+
+import com.nextcloud.android.sso.helper.SingleAccountHelper;
+
+import it.niedermann.nextcloud.deck.api.IResponseCallback;
+import it.niedermann.nextcloud.deck.model.Account;
+import it.niedermann.nextcloud.deck.model.Board;
+import it.niedermann.nextcloud.deck.model.Card;
+import it.niedermann.nextcloud.deck.persistence.sync.SyncManager;
+
+public class PushNotificationViewModel extends AndroidViewModel {
+
+ private final SyncManager readAccountSyncManager;
+ private SyncManager accountSpecificSyncManager;
+
+ public PushNotificationViewModel(@NonNull Application application) {
+ super(application);
+ this.readAccountSyncManager = new SyncManager(application);
+ }
+
+ public LiveData<Account> readAccount(@Nullable String name) {
+ return readAccountSyncManager.readAccount(name);
+ }
+
+ public void setAccount(@NonNull String accountName) {
+ SingleAccountHelper.setCurrentAccount(getApplication(), accountName);
+ accountSpecificSyncManager = new SyncManager(getApplication());
+ }
+
+ public LiveData<Board> getBoardByRemoteId(long accountId, long remoteId) {
+ return accountSpecificSyncManager.getBoardByRemoteId(accountId, remoteId);
+ }
+
+ public LiveData<Card> getCardByRemoteID(long accountId, long remoteId) {
+ return accountSpecificSyncManager.getCardByRemoteID(accountId, remoteId);
+ }
+
+ public void synchronizeCard(@NonNull IResponseCallback<Boolean> responseCallback, Card card) {
+ accountSpecificSyncManager.synchronizeCard(responseCallback, card);
+ }
+
+ public void synchronizeBoard(@NonNull IResponseCallback<Boolean> responseCallback, long localBoadId) {
+ accountSpecificSyncManager.synchronizeBoard(responseCallback, localBoadId);
+ }
+}