David
August 24, 2024, 3:58pm
1
I’ve had a request that AnkiDroid should update its UI after 'Check → Empty Cards.
Architecturally, an ideal solution seems to be that RemoveCards
should return an OpChanges[WithCount]
RemoveNotes
returns collection.OpChangesWithCount
RemoveCards
returns generic.empty
Implementation
fn remove_cards(&mut self, input: anki_proto::cards::RemoveCardsRequest) -> error::Result<()> {
self.transact_no_undo(|col| {
col.remove_cards_and_orphaned_notes(
&input
.card_ids
.into_iter()
.map(Into::into)
.collect::<Vec<_>>(),
)?;
Ok(())
})
}
ref:
opened 02:52AM - 24 Aug 24 UTC
See #16941 for the details. This issue can be closed specifically when, after a … "Check cards" ends by deleting cards, `ChangeManager.notifySubscribers` is called with a `OpChanges` where all at least `card`, `browser_table`, `study_queues` are set to true
1 Like
In case it can’t easily be done, I think this can be done directly in the DeckPicker’s callback after removing the cards is done.
Anyway, unless it becomes undoable, having a OpChanges from the backend is not needed.
For the context, the UI that I wanted to update is a widget, created during google summer of code.
I guess the deck picker should also update. I have not even realized that
1 Like
David
August 24, 2024, 9:23pm
3
I’ve already implement this in the AnkiDroid code, longer-term it’d be better in the shared backend if at all possible
David
August 25, 2024, 10:59am
4
No longer requesting this: we have bigger fish to fry
opened 02:34AM - 24 Aug 24 UTC
Right now, `notifySubscribers` is called on any undoable operation and on new da… y. (Funnily enough "undo" is an `undoableOp` too, so "undo" also notifies the subscriber)
It's not yet done on undoable operations. Which means that, for example, the widget does not get notified that there its content should be updated.
So, this issue has two tasks:
* find all operation that change the database and can't be undone.
* ensure that all such operations calls `notifySubscribers`.
If there are actions that you find that can't be undone, and you can't easily find how to create the notification, you can simply create a new issue. Otherwise, you can directly create a PR to add the notification.
Right now, the operations I know of are:
* syncing
* full sync
* check card
* check database
I should note that those four operations are done in the deck picker, and we hard coded the deck picker to update when those operations are done. Previously, no other views could be opened while the deck picker was on screen, so it was never necessary to notify subscribers, because the only subscriber is the deck picker, and it was already listening.
Now that we are introducing widgets that display the state of the collection, it'll be necessary to notify the observers.
I think the object sent for notification should be simply `OpChanges` with all fields set to true, given that it's too hard to know what actually was changed.
Honestly, I don't even know how to find all tasks that need to be updated. I assume most of those tasks are in GeneratedBackend.kt. But it contains 445 functions, and there is no way to read all of them and be certain that we won't miss any function that change the collection and is not undoable.
Given that it seemed relatively simple to do (assuming we accept to make “Empty Cards” undoable) I opened a PR for it Empty cards become undoable by Arthur-Milchior · Pull Request #3386 · ankitects/anki · GitHub
1 Like