Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions android/Gutenberg/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.jetbrains.kotlin.android)
alias(libs.plugins.jetbrains.kotlin.serialization)
id("com.automattic.android.publish-to-s3")
id("kotlin-parcelize")
}
Expand Down Expand Up @@ -42,6 +43,12 @@ android {
kotlinOptions {
jvmTarget = "1.8"
}

testOptions {
unitTests {
isReturnDefaultValues = true
}
}
}

dependencies {
Expand All @@ -52,11 +59,16 @@ dependencies {
implementation(libs.androidx.webkit)
implementation(libs.gson)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.kotlinx.serialization.json)
implementation(libs.jsoup)
implementation(libs.okhttp)

testImplementation(libs.junit)
testImplementation(libs.kotlinx.coroutines.test)
testImplementation(libs.mockito.core)
testImplementation(libs.mockito.kotlin)
testImplementation(libs.robolectric)
testImplementation(libs.okhttp.mockwebserver)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package org.wordpress.gutenberg
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
import android.util.Log
import org.wordpress.gutenberg.model.EditorAssetBundle
import java.io.ByteArrayInputStream

class CachedAssetRequestInterceptor(
private val library: EditorAssetsLibrary,
private val bundle: EditorAssetBundle,
private val allowedHosts: Set<String> = emptySet()
) : GutenbergRequestInterceptor {
companion object {
Expand Down Expand Up @@ -44,28 +45,21 @@ class CachedAssetRequestInterceptor(
}

// Handle asset caching - only serve if already cached
val cachedData = library.getCachedAsset(url)
if (cachedData != null) {
if (bundle.hasAssetData(url)) {
val cachedData = bundle.assetData(url)
Log.d(TAG, "Serving cached asset: $url")
return createResponse(url, cachedData)
}

// Not cached - let WebView fetch normally and cache in background
Log.d(TAG, "Asset not cached, will cache in background: $url")
// Start background caching for next time
library.cacheAssetInBackground(url)

// Not cached - let WebView fetch normally
Log.d(TAG, "Asset not cached: $url")
return null // Let WebView handle the request normally
} catch (e: Exception) {
Log.e(TAG, "Error handling request: $url", e)
return null
}
}

fun shutdown() {
library.shutdown()
}

private fun createResponse(url: String, data: ByteArray): WebResourceResponse {
val mimeType = getMimeType(url)
return WebResourceResponse(
Expand Down

This file was deleted.

Loading