Skip to content

Commit

Permalink
Expose card info/graph methods
Browse files Browse the repository at this point in the history
To enable krmanik#23

Also requires ankidroid/Anki-Android-Backend@4c3eea4
or similar
  • Loading branch information
dae authored and mikehardy committed Jun 29, 2022
1 parent 7831194 commit 34e3dae
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/libanki/CollectionV16.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
40 changes: 40 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/libanki/stats/BackendStats.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/***************************************************************************************
* Copyright (c) 2012 Ankitects Pty Ltd <http://apps.ankiweb.net> *
* *
* 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 <http://www.gnu.org/licenses/>. *
****************************************************************************************/

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)
}

0 comments on commit 34e3dae

Please sign in to comment.