Skip to content

Commit

Permalink
feat(previewers): load files directly
Browse files Browse the repository at this point in the history
with file:/ scheme
  • Loading branch information
BrayanDSO committed Mar 31, 2024
1 parent 0ff5be1 commit 03e081f
Showing 1 changed file with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 03e081f

Please sign in to comment.