Skip to content

Commit

Permalink
refactor: handleNoteEditorResult and handleDeckOptionsResult
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO authored and lukstbit committed Jun 21, 2024
1 parent 8ab378c commit a4f9f95
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -277,7 +281,7 @@ class ReviewerFragment :
}

private val deckOptionsLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
viewModel.handleDeckOptionsResult()
viewModel.refreshCard()
}

private fun launchDeckOptions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
}
}

Expand All @@ -179,12 +173,6 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) :
return DeckOptionsDestination(deckId, isFiltered)
}

fun handleDeckOptionsResult() {
launchCatchingIO {
updateCurrentCard()
}
}

fun deleteNote() {
launchCatchingIO {
val cardId = currentCard.await().id
Expand Down

0 comments on commit a4f9f95

Please sign in to comment.