Skip to content

Commit

Permalink
show graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
krmanik committed Jun 4, 2022
1 parent fb8c12e commit 6e4e3eb
Show file tree
Hide file tree
Showing 7 changed files with 14,299 additions and 13,209 deletions.
27,479 changes: 14,274 additions & 13,205 deletions AnkiDroid/src/main/assets/pages/card-info.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions AnkiDroid/src/main/assets/pages/graphs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!doctype html><html><head><meta charset="utf-8"/><meta name="viewport" id="viewport" content="width=device-width"/></head><body><div id="main"></div><script src="graphs.js"></script></body><script>const nightMode = window.location.hash == "#night";
if (nightMode) {
document.body.className = "night-mode";
}
anki.graphs(document.getElementById("main"), nightMode);</script></html>
1 change: 1 addition & 0 deletions AnkiDroid/src/main/assets/pages/graphs.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions AnkiDroid/src/main/java/com/ichi2/anki/pages/AnkiWebview.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AnkiWebview : AnkiActivity() {
webview.webChromeClient = WebChromeClient()
// passing col in here is presumably the wrong way to do this
webview.webViewClient = AnkiWebChromeClient(col)
webview.loadUrl("https://127.0.0.1/card-info.html")
webview.loadUrl("https://127.0.0.1/graphs.html")
}

class AnkiWebChromeClient(val col: Collection) : WebViewClient() {
Expand All @@ -39,9 +39,13 @@ class AnkiWebview : AnkiActivity() {
return request?.url?.let { url ->
Timber.i("************** request %s", url)
when (val path = url.path) {
"/card-info.html" -> fileResponse(path, "text/html")
"/card-info.css" -> fileResponse(path, "text/css")
"/card-info.js" -> fileResponse(path, "text/javascript")
"/graphs.html" -> fileResponse(path, "text/html")
// "/card-info.css" -> fileResponse(path, "text/css")
"/graphs.js" -> fileResponse(path, "text/javascript")
"/_anki/graphData" -> {
val data = ByteArrayInputStream(col.backend.graphData().toByteArray())
streamResponse(data, "application/binary")
}
"/_anki/i18nResources" -> {
val data = ByteArrayInputStream(col.backend.i18nResources().toByteArray())
streamResponse(data, "application/binary")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,7 @@ interface DroidBackend {

@Throws(BackendNotSupportedException::class)
fun i18nResources(): ByteString

@Throws(BackendNotSupportedException::class)
fun graphData(): ByteString
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,10 @@ public void useNewTimezoneCode(Collection col) {
public ByteString i18nResources() throws BackendNotSupportedException {
throw new BackendNotSupportedException();
}

@NonNull
@Override
public ByteString graphData() throws BackendNotSupportedException {
throw new BackendNotSupportedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ open class RustDroidBackend(

override fun i18nResources(): ByteString = backend.backend.i18nResources().json

override fun graphData(): ByteString = backend.backend.graphs("", 100).toByteString()

companion object {
const val UNUSED_VALUE = 0
}
Expand Down

0 comments on commit 6e4e3eb

Please sign in to comment.