Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement(collection): implement browserRowForId #17779

Merged
merged 2 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,6 @@ open class CardBrowser :
}
}

@RustCleanup("remove card cache; switch to RecyclerView and browserRowForId (#11889)")
@VisibleForTesting
fun searchCards() {
launchCatchingTask {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ class CardBrowserViewModel(
flowOfColumn1.update { columns.columns[0] }
flowOfColumn2.update { columns.columns[1] }

// This impacts browserRowForId(), which we do not use yet
withCol { backend.setActiveBrowserColumns(columns.backendKeys) }
}

Expand Down
17 changes: 14 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/libanki/Collection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,21 @@ class Collection(
return null
}

// consider changing implementation to return protobuf directly
/**
* Returns a [BrowserRow], cells dependent on [Backend.setActiveBrowserColumns]
*
* WARN: As this is a latency-sensitive call, most callers should use [Backend.browserRowForId]
*
* @param id Either a [CardId] or a [NoteId], depending on the value of
* [ConfigKey.Bool.BROWSER_TABLE_SHOW_NOTES_MODE]
*
* @see [setBrowserCardColumns]
* @see [setBrowserNoteColumns]
*/
// For performance, this does not match upstream:
// https://github.com/ankitects/anki/blob/1fb1cbbf85c48a54c05cb4442b1b424a529cac60/pylib/anki/collection.py#L869-L881
@LibAnkiAlias("browser_row_for_id")
@Deprecated("not implemented", replaceWith = ReplaceWith("nothing"))
fun browserRowForId(id: Long): BrowserRow = TODO()
fun browserRowForId(id: Long): BrowserRow = backend.browserRowForId(id)

/** Return the stored card column names and ensure the backend columns are set and in sync. */
@LibAnkiAlias("load_browser_card_columns")
Expand Down
4 changes: 2 additions & 2 deletions AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ class CardBrowserTest : RobolectricTest() {
}

private fun getCardFlagAfterFlagChangeDone(cardId: CardId): Flag {
val data = col.backend.browserRowForId(cardId)
val data = col.browserRowForId(cardId)

return when (data.color) {
Color.COLOR_FLAG_BLUE -> Flag.BLUE
Expand Down Expand Up @@ -1173,7 +1173,7 @@ class CardBrowserTest : RobolectricTest() {
private fun CheckedCardResult.getColumnHeaderText(header: CardBrowserColumn): String? {
// There's currently a minimum of 2 columns
col.backend.setActiveBrowserColumns(listOf(header.ankiColumnKey, "answer"))
return col.backend
return col
.browserRowForId(this.cardOrNoteId)
.getCells(0)
.text
Expand Down
Loading