diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-06-09 18:14:16 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-06-09 18:14:16 +0300 |
commit | 41fc133cbb4b692e34588142fad8a73f93017790 (patch) | |
tree | 9af2cdfdf98e5d2ccc8fb7ae5deab1b341609086 | |
parent | fe94b20ed783186964c72dd9459e5ace4d65703a (diff) |
Simplify stack deletion call and remove unnecessary database call
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/SyncManager.java | 8 | ||||
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java | 13 |
2 files changed, 9 insertions, 12 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/SyncManager.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/SyncManager.java index 37ffd9742..c4f86e5bb 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/SyncManager.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/SyncManager.java @@ -584,12 +584,12 @@ public class SyncManager { return liveData; } - public WrappedLiveData<Void> deleteStack(Stack stack) { + public WrappedLiveData<Void> deleteStack(long accountId, long stackLocalId, long boardLocalId) { WrappedLiveData<Void> liveData = new WrappedLiveData<>(); doAsync(() -> { - Account account = dataBaseAdapter.getAccountByIdDirectly(stack.getAccountId()); - FullStack fullStack = dataBaseAdapter.getFullStackByLocalIdDirectly(stack.getLocalId()); - FullBoard board = dataBaseAdapter.getFullBoardByLocalIdDirectly(stack.getAccountId(), stack.getBoardId()); + Account account = dataBaseAdapter.getAccountByIdDirectly(accountId); + FullStack fullStack = dataBaseAdapter.getFullStackByLocalIdDirectly(stackLocalId); + FullBoard board = dataBaseAdapter.getFullBoardByLocalIdDirectly(accountId, boardLocalId); new DataPropagationHelper(serverAdapter, dataBaseAdapter).deleteEntity(new StackDataProvider(null, board), fullStack, getCallbackToLiveDataConverter(account, liveData)); }); return liveData; diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java index 1229d2488..b4d545e42 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java @@ -990,14 +990,11 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener @Override public void onStackDeleted(Long stackLocalId) { long stackId = stackAdapter.getItem(binding.viewPager.getCurrentItem()).getLocalId(); - observeOnce(syncManager.getStack(mainViewModel.getCurrentAccount().getId(), stackId), MainActivity.this, fullStack -> { - DeckLog.info("Delete stack #" + fullStack.getLocalId() + ": " + fullStack.getStack().getTitle()); - final WrappedLiveData<Void> deleteStackLiveData = syncManager.deleteStack(fullStack.getStack()); - observeOnce(deleteStackLiveData, this, (v) -> { - if (deleteStackLiveData.hasError()) { - ExceptionDialogFragment.newInstance(deleteStackLiveData.getError(), mainViewModel.getCurrentAccount()).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName()); - } - }); + final WrappedLiveData<Void> deleteStackLiveData = syncManager.deleteStack(mainViewModel.getCurrentAccount().getId(), stackId, mainViewModel.getCurrentBoardLocalId()); + observeOnce(deleteStackLiveData, this, (v) -> { + if (deleteStackLiveData.hasError()) { + ExceptionDialogFragment.newInstance(deleteStackLiveData.getError(), mainViewModel.getCurrentAccount()).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName()); + } }); } |