diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-12-10 13:02:58 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-12-10 13:02:58 +0300 |
commit | a99dfdb29569e788b83363949699a8596d653ab3 (patch) | |
tree | 4233c4cddcd1c2802c5d75f651b5f03e123fd1e4 /app/src/main/java/it/niedermann | |
parent | aec35e582d3c5a51d1ae1e7c2e107ebbedca1955 (diff) |
Assume successful saving of cards for better UX
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app/src/main/java/it/niedermann')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditActivity.java | 22 |
1 files changed, 13 insertions, 9 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 2e1ff5e06..fe4ea8c25 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 @@ -26,6 +26,7 @@ import it.niedermann.nextcloud.deck.R; import it.niedermann.nextcloud.deck.databinding.ActivityEditBinding; import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.full.FullCard; +import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.util.WrappedLiveData; import it.niedermann.nextcloud.deck.ui.branding.BrandedActivity; import it.niedermann.nextcloud.deck.ui.branding.BrandedAlertDialogBuilder; import it.niedermann.nextcloud.deck.ui.exception.ExceptionHandler; @@ -169,16 +170,15 @@ public class EditActivity extends BrandedActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.action_card_save) { - saveAndRun(super::finish); + saveAndFinish(); } return super.onOptionsItemSelected(item); } /** * Tries to save the current {@link FullCard} from the {@link EditCardViewModel} and then runs the given {@link Runnable} - * @param runnable */ - private void saveAndRun(@NonNull Runnable runnable) { + private void saveAndFinish() { if (!viewModel.isPendingCreation()) { viewModel.setPendingCreation(true); final String title = viewModel.getFullCard().getCard().getTitle(); @@ -195,11 +195,15 @@ public class EditActivity extends BrandedActivity { .setOnDismissListener(dialog -> viewModel.setPendingCreation(false)) .show(); } else { - if (viewModel.isCreateMode()) { - observeOnce(viewModel.createFullCard(viewModel.getAccount().getId(), viewModel.getBoardId(), viewModel.getFullCard().getCard().getStackId(), viewModel.getFullCard()), EditActivity.this, (card) -> runnable.run()); - } else { - observeOnce(viewModel.updateCard(viewModel.getFullCard()), EditActivity.this, (card) -> runnable.run()); - } + final WrappedLiveData<FullCard> save$ = viewModel.isCreateMode() + ? viewModel.createFullCard(viewModel.getAccount().getId(), viewModel.getBoardId(), viewModel.getFullCard().getCard().getStackId(), viewModel.getFullCard()) + : viewModel.updateCard(viewModel.getFullCard()); + save$.observe(this, (fullCard) -> { + if (save$.hasError()) { + DeckLog.logError(save$.getError()); + } + }); + super.finish(); } } } @@ -272,7 +276,7 @@ public class EditActivity extends BrandedActivity { new BrandedAlertDialogBuilder(this) .setTitle(R.string.simple_save) .setMessage(R.string.do_you_want_to_save_your_changes) - .setPositiveButton(R.string.simple_save, (dialog, whichButton) -> saveAndRun(super::finish)) + .setPositiveButton(R.string.simple_save, (dialog, whichButton) -> saveAndFinish()) .setNegativeButton(R.string.simple_discard, (dialog, whichButton) -> super.finish()).show(); } else { super.finish(); |