From 03e081f0551c5c7d30f7895e12cf891935ffbae8 Mon Sep 17 00:00:00 2001 From: Brayan Oliveira <69634269+brayandso@users.noreply.github.com> Date: Sun, 31 Mar 2024 19:16:56 -0300 Subject: [PATCH] feat(previewers): load files directly with file:/ scheme --- .../ichi2/anki/previewer/CardViewerFragment.kt | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/previewer/CardViewerFragment.kt b/AnkiDroid/src/main/java/com/ichi2/anki/previewer/CardViewerFragment.kt index 2048559c34eb..aaed394db252 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/previewer/CardViewerFragment.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/previewer/CardViewerFragment.kt @@ -23,7 +23,6 @@ import android.webkit.CookieManager import android.webkit.WebChromeClient import android.webkit.WebResourceError import android.webkit.WebResourceRequest -import android.webkit.WebResourceResponse import android.webkit.WebView import android.webkit.WebViewClient import android.widget.FrameLayout @@ -36,11 +35,10 @@ import androidx.core.view.WindowInsetsControllerCompat import androidx.fragment.app.Fragment import androidx.lifecycle.flowWithLifecycle import androidx.lifecycle.lifecycleScope +import com.ichi2.anki.CollectionHelper import com.ichi2.anki.R -import com.ichi2.anki.ViewerResourceHandler import com.ichi2.anki.dialogs.TtsVoicesDialogFragment import com.ichi2.anki.localizedErrorMessage -import com.ichi2.anki.pages.AnkiServer import com.ichi2.anki.snackbar.showSnackbar import com.ichi2.themes.Themes import kotlinx.coroutines.flow.launchIn @@ -83,8 +81,9 @@ abstract class CardViewerFragment(@LayoutRes layout: Int) : Fragment(layout) { allowFileAccess = true domStorageEnabled = true } + val baseUrl = CollectionHelper.getMediaDirectory(requireContext()).toURI().toString() loadDataWithBaseURL( - "http://${AnkiServer.LOCALHOST}/", + baseUrl, stdHtml(requireContext(), Themes.currentTheme.isNightMode), "text/html", null, @@ -120,15 +119,7 @@ abstract class CardViewerFragment(@LayoutRes layout: Int) : Fragment(layout) { } private fun onCreateWebViewClient(savedInstanceState: Bundle?): WebViewClient { - val resourceHandler = ViewerResourceHandler(requireContext(), AnkiServer.LOCALHOST) return object : WebViewClient() { - override fun shouldInterceptRequest( - view: WebView?, - request: WebResourceRequest - ): WebResourceResponse? { - return resourceHandler.shouldInterceptRequest(request) - } - override fun onPageFinished(view: WebView?, url: String?) { viewModel.onPageFinished(isAfterRecreation = savedInstanceState != null) }