From 95e60cb2631a3a0d9dd02c79bcd3bcf0e5a92a37 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 21 Jun 2022 21:22:59 +1000 Subject: [PATCH] Expose card info/graph methods To enable https://github.com/krmanik/Anki-Android/pull/23 Also requires https://github.com/ankidroid/Anki-Android-Backend/pull/202/commits/4c3eea41779ad6323027cd25bf0e97289a9d2fc3 or similar --- .../java/com/ichi2/libanki/CollectionV16.kt | 5 +++ .../com/ichi2/libanki/stats/BackendStats.kt | 40 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/stats/BackendStats.kt diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/CollectionV16.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/CollectionV16.kt index 97dd0cb31051..ebf102991e0d 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/CollectionV16.kt +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/CollectionV16.kt @@ -116,4 +116,9 @@ class CollectionV16( task?.doProgress(cardIdsList) return cardIdsList } + + /** Takes raw input from TypeScript frontend and returns suitable translations. */ + fun i18nResourcesRaw(input: ByteArray): ByteArray { + return backend.i18nResourcesRaw(input) + } } diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/stats/BackendStats.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/stats/BackendStats.kt new file mode 100644 index 000000000000..b50bf4a6caaa --- /dev/null +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/stats/BackendStats.kt @@ -0,0 +1,40 @@ +/*************************************************************************************** + * Copyright (c) 2012 Ankitects Pty Ltd * + * * + * This program is free software; you can redistribute it and/or modify it under * + * the terms of the GNU General Public License as published by the Free Software * + * Foundation; either version 3 of the License, or (at your option) any later * + * version. * + * * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY * + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * + * PARTICULAR PURPOSE. See the GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License along with * + * this program. If not, see . * + ****************************************************************************************/ + +package com.ichi2.libanki.stats + +// These take and return bytes that the frontend TypeScript code will encode/decode. + +import com.ichi2.libanki.CollectionV16 + +fun CollectionV16.cardStatsRaw(input: ByteArray): ByteArray { + return backend.cardStatsRaw(input) +} + +fun CollectionV16.graphsRaw(input: ByteArray): ByteArray { + return backend.graphsRaw(input) +} + +fun CollectionV16.getGraphPreferencesRaw(): ByteArray { + val prefs = backend.getGraphPreferences().toBuilder() + .setBrowserLinksSupported(false) + .build() + return prefs.toByteArray() +} + +fun CollectionV16.setGraphPreferencesRaw(input: ByteArray) { + backend.setGraphPreferencesRaw(input) +}