From 349e42c20dd37ef6013806a4b7f573980c89fd89 Mon Sep 17 00:00:00 2001 From: Brayan Oliveira <69634269+brayandso@users.noreply.github.com> Date: Sun, 10 Dec 2023 10:55:46 -0300 Subject: [PATCH] fix: previewer crash when cast to CardTemplatePreviewer --- AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.kt | 4 ---- .../src/main/java/com/ichi2/anki/ReviewerServer.kt | 13 ++----------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.kt b/AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.kt index f7e0ea154362..694bc9f9951b 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.kt @@ -1591,10 +1591,6 @@ open class Reviewer : } } - override fun javaScriptFunction(): AnkiDroidJsAPI { - return AnkiDroidJsAPI(this) - } - override fun getCardDataForJsApi(): AnkiDroidJsAPI.CardDataForJsApi { val cardDataForJsAPI = AnkiDroidJsAPI.CardDataForJsApi().apply { newCardCount = mNewCount.toString() diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/ReviewerServer.kt b/AnkiDroid/src/main/java/com/ichi2/anki/ReviewerServer.kt index 49347cea0159..f79eb2bb573a 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/ReviewerServer.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/ReviewerServer.kt @@ -16,7 +16,6 @@ package com.ichi2.anki -import androidx.fragment.app.FragmentActivity import anki.frontend.SetSchedulingStatesRequest import com.ichi2.anki.pages.AnkiServer import com.ichi2.utils.AssetHelper @@ -24,13 +23,9 @@ import timber.log.Timber import java.io.File import java.io.FileInputStream -class ReviewerServer(activity: FragmentActivity, val mediaDir: String) : AnkiServer(activity) { +class ReviewerServer(activity: AbstractFlashcardViewer, private val mediaDir: String) : AnkiServer(activity) { var reviewerHtml: String = "" - private val jsApi = if (activity is Reviewer) { - reviewer().javaScriptFunction() - } else { - cardTemplatePreviewer().javaScriptFunction() - } + private val jsApi = activity.javaScriptFunction() override fun start() { super.start() @@ -102,10 +97,6 @@ class ReviewerServer(activity: FragmentActivity, val mediaDir: String) : AnkiSer return (activity as Reviewer) } - private fun cardTemplatePreviewer(): CardTemplatePreviewer { - return (activity as CardTemplatePreviewer) - } - private fun getSchedulingStatesWithContext(): ByteArray { val state = reviewer().queueState ?: return ByteArray(0) return state.schedulingStatesWithContext().toBuilder()