KamWithK / AnkiconnectAndroid

Unofficial Ankiconnect for Android (i.e. for Yomichan)
GNU General Public License v3.0
98 stars 14 forks source link

Implement full canAddNotes capabilities, add notesInfo and canAddNotesWithErrorDetail API #60

Open drakargx opened 2 months ago

drakargx commented 2 months ago

Based on #46 this implements just the functionality of notesInfo and canAddNotesWithErrorDetail, at least as much for yomitan to work.

https://github.com/themoeway/yomitan/pull/693 was recently pushed into yomitan's main release branch which prevents yomitan from displaying the add button when duplicate checking is enabled, as it relies on the canAddNotesWithErrorDetail API.

canAddNotesWithErrorDetail returns an array of JSON objects with a 'canAdd' field and an optional 'error' field. If canAdd is true then 'error' is not present. Yomitan is checking for the presence of the 'error' field so I also had to create another GSON instance that doesn't serialize nulls; if there's a better way let me know (this is the first time I've used Java in years).

canAddNotes is currently implemented by just checking if the card to add is a duplicate, so right now I pass the result of that over and if the result is false, I add the string Yomitan is checking for. If a future feature of Yomitan relies on the contents of the error message then this needs to be revisited.

I am also not sure how to credit @Aquafina-water-bottle for the work in implementing the notesInfo API, I simply added some performance improvements by caching model information.