diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-12-10 13:10:12 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-12-10 13:10:12 +0300 |
commit | 7b498614592bc8fd283e3172ad997f1f175bcfc0 (patch) | |
tree | 8be205906f56f1f3b5307c7f90fab2d66be495fd /app | |
parent | a99dfdb29569e788b83363949699a8596d653ab3 (diff) |
Small refactorings in the EditActivity
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditActivity.java | 6 | ||||
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditCardViewModel.java | 13 |
2 files changed, 9 insertions, 10 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditActivity.java index fe4ea8c25..ae57c9d9f 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditActivity.java @@ -176,7 +176,7 @@ public class EditActivity extends BrandedActivity { } /** - * Tries to save the current {@link FullCard} from the {@link EditCardViewModel} and then runs the given {@link Runnable} + * Tries to save the current {@link FullCard} from the {@link EditCardViewModel} and then finishes this activity. */ private void saveAndFinish() { if (!viewModel.isPendingCreation()) { @@ -195,9 +195,7 @@ public class EditActivity extends BrandedActivity { .setOnDismissListener(dialog -> viewModel.setPendingCreation(false)) .show(); } else { - final WrappedLiveData<FullCard> save$ = viewModel.isCreateMode() - ? viewModel.createFullCard(viewModel.getAccount().getId(), viewModel.getBoardId(), viewModel.getFullCard().getCard().getStackId(), viewModel.getFullCard()) - : viewModel.updateCard(viewModel.getFullCard()); + final WrappedLiveData<FullCard> save$ = viewModel.saveCard(); save$.observe(this, (fullCard) -> { if (save$.hasError()) { DeckLog.logError(save$.getError()); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditCardViewModel.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditCardViewModel.java index c754d0800..697566f84 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditCardViewModel.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditCardViewModel.java @@ -138,12 +138,13 @@ public class EditCardViewModel extends AndroidViewModel { return syncManager.getFullCardWithProjectsByLocalId(accountId, cardLocalId); } - public WrappedLiveData<FullCard> createFullCard(long accountId, long localBoardId, long localStackId, @NonNull FullCard card) { - return syncManager.createFullCard(accountId, localBoardId, localStackId, card); - } - - public WrappedLiveData<FullCard> updateCard(@NonNull FullCard card) { - return syncManager.updateCard(card); + /** + * Saves the current {@link #fullCard}. If it is a new card, it will be created, otherwise it will be updated. + */ + public WrappedLiveData<FullCard> saveCard() { + return isCreateMode() + ? syncManager.createFullCard(getAccount().getId(), getBoardId(), getFullCard().getCard().getStackId(), getFullCard()) + : syncManager.updateCard(getFullCard()); } public LiveData<List<Activity>> syncActivitiesForCard(@NonNull Card card) { |