From 29ac0f268cc213d9468af311ec82484ebbd0b2a8 Mon Sep 17 00:00:00 2001 From: Brayan Oliveira <69634269+brayandso@users.noreply.github.com> Date: Thu, 20 Jun 2024 11:48:03 -0300 Subject: [PATCH] refactor: handleNoteEditorResult and handleDeckOptionsResult --- .../ui/windows/reviewer/ReviewerFragment.kt | 8 ++++++-- .../ui/windows/reviewer/ReviewerViewModel.kt | 18 +++--------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragment.kt b/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragment.kt index 0d9697b46d25..3e46527dc926 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragment.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragment.kt @@ -252,7 +252,11 @@ class ReviewerFragment : private val noteEditorLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> - viewModel.handleNoteEditorResult(result) + if (result.data?.getBooleanExtra(NoteEditor.RELOAD_REQUIRED_EXTRA_KEY, false) == true || + result.data?.getBooleanExtra(NoteEditor.NOTE_CHANGED_EXTRA_KEY, false) == true + ) { + viewModel.refreshCard() + } } private fun launchEditNote() { @@ -277,7 +281,7 @@ class ReviewerFragment : } private val deckOptionsLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { - viewModel.handleDeckOptionsResult() + viewModel.refreshCard() } private fun launchDeckOptions() { diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt b/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt index d1ba5f9c4b97..02679dc28456 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt @@ -15,7 +15,6 @@ */ package com.ichi2.anki.ui.windows.reviewer -import androidx.activity.result.ActivityResult import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewmodel.initializer import androidx.lifecycle.viewmodel.viewModelFactory @@ -25,7 +24,6 @@ import com.ichi2.anki.CollectionManager import com.ichi2.anki.CollectionManager.withCol import com.ichi2.anki.Ease import com.ichi2.anki.Flag -import com.ichi2.anki.NoteEditor import com.ichi2.anki.Reviewer import com.ichi2.anki.asyncIO import com.ichi2.anki.cardviewer.CardMediaPlayer @@ -159,13 +157,9 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) : return NoteEditorDestination(currentCard.await().id) } - fun handleNoteEditorResult(result: ActivityResult) { - if (result.data?.getBooleanExtra(NoteEditor.RELOAD_REQUIRED_EXTRA_KEY, false) == true || - result.data?.getBooleanExtra(NoteEditor.NOTE_CHANGED_EXTRA_KEY, false) == true - ) { - launchCatchingIO { - updateCurrentCard() - } + fun refreshCard() { + launchCatchingIO { + updateCurrentCard() } } @@ -179,12 +173,6 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) : return DeckOptionsDestination(deckId, isFiltered) } - fun handleDeckOptionsResult() { - launchCatchingIO { - updateCurrentCard() - } - } - fun deleteNote() { launchCatchingIO { val cardId = currentCard.await().id