diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt b/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt index 119a8ac61c0d..77d45c0b6e23 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt @@ -1154,7 +1154,7 @@ open class CardBrowser : prompt = this@CardBrowser.getString(R.string.reposition_card_dialog_message), digits = 5 ) - setCallbackRunnable { pos -> repositionCardsNoValidation(selectedCardIds, pos) } + setCallbackRunnable(::repositionCardsNoValidation) } showDialogFragment(repositionDialog) return true @@ -1226,23 +1226,16 @@ open class CardBrowser : } @VisibleForTesting - fun repositionCardsNoValidation(cardIds: List, position: Int) { - launchCatchingTask { - val changes = withProgress { - undoableOp { - sched.sortCards(cardIds, position, 1, false, true) - } - } - val count = changes.count - showSnackbar( - resources.getQuantityString( - R.plurals.reposition_card_dialog_acknowledge, - count, - count - ), - Snackbar.LENGTH_SHORT - ) - } + fun repositionCardsNoValidation(position: Int) = launchCatchingTask { + val count = withProgress { viewModel.repositionSelectedRows(position) } + showSnackbar( + resources.getQuantityString( + R.plurals.reposition_card_dialog_acknowledge, + count, + count + ), + Snackbar.LENGTH_SHORT + ) } protected fun onPreview() { diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/browser/CardBrowserViewModel.kt b/AnkiDroid/src/main/java/com/ichi2/anki/browser/CardBrowserViewModel.kt index 1601cfd6cd3c..ce5ad0cd0866 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/browser/CardBrowserViewModel.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/browser/CardBrowserViewModel.kt @@ -209,6 +209,14 @@ class CardBrowserViewModel( } } + /** + * @see [com.ichi2.libanki.sched.Scheduler.sortCards] + * @return the number of cards which were repositioned + */ + suspend fun repositionSelectedRows(position: Int) = undoableOp { + sched.sortCards(selectedCardIds, position, 1, shuffle = false, shift = true) + }.count + companion object { const val DISPLAY_COLUMN_1_KEY = "cardBrowserColumn1" const val DISPLAY_COLUMN_2_KEY = "cardBrowserColumn2" diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt index f31e2222f1a4..e0c71821d1f5 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt @@ -519,7 +519,7 @@ class CardBrowserTest : RobolectricTest() { equalTo("1") ) - b.repositionCardsNoValidation(listOf(card.id), 2) + b.viewModel.repositionSelectedRows(2) card.reload() @@ -601,7 +601,7 @@ class CardBrowserTest : RobolectricTest() { equalTo("1") ) - b.repositionCardsNoValidation(listOf(card.id), 2) + b.repositionCardsNoValidation(2) assertThat( "Position of checked card after reposition",