mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-15 10:26:53 -04:00
#2222 Impossible to read warc2zim generated ZIM files - support service workers - load war2c as asset
This commit is contained in:
parent
5d4d767880
commit
03f97027a2
@ -48,6 +48,23 @@ object Libs {
|
|||||||
*/
|
*/
|
||||||
const val retrofit: String = "com.squareup.retrofit2:retrofit:" + Versions.com_squareup_retrofit2
|
const val retrofit: String = "com.squareup.retrofit2:retrofit:" + Versions.com_squareup_retrofit2
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://square.github.io/okhttp/
|
||||||
|
*/
|
||||||
|
const val logging_interceptor: String = "com.squareup.okhttp3:logging-interceptor:" +
|
||||||
|
Versions.com_squareup_okhttp3
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://square.github.io/okhttp/
|
||||||
|
*/
|
||||||
|
const val mockwebserver: String = "com.squareup.okhttp3:mockwebserver:" +
|
||||||
|
Versions.com_squareup_okhttp3
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://square.github.io/okhttp/
|
||||||
|
*/
|
||||||
|
const val okhttp: String = "com.squareup.okhttp3:okhttp:" + Versions.com_squareup_okhttp3
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://kotlinlang.org/
|
* https://kotlinlang.org/
|
||||||
*/
|
*/
|
||||||
@ -166,6 +183,11 @@ object Libs {
|
|||||||
const val objectbox_gradle_plugin: String = "io.objectbox:objectbox-gradle-plugin:" +
|
const val objectbox_gradle_plugin: String = "io.objectbox:objectbox-gradle-plugin:" +
|
||||||
Versions.io_objectbox
|
Versions.io_objectbox
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://objectbox.io
|
||||||
|
*/
|
||||||
|
const val objectbox_java: String = "io.objectbox:objectbox-java:" + Versions.io_objectbox
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://objectbox.io
|
* https://objectbox.io
|
||||||
*/
|
*/
|
||||||
@ -236,12 +258,6 @@ object Libs {
|
|||||||
const val javax_annotation_api: String = "javax.annotation:javax.annotation-api:" +
|
const val javax_annotation_api: String = "javax.annotation:javax.annotation-api:" +
|
||||||
Versions.javax_annotation_api
|
Versions.javax_annotation_api
|
||||||
|
|
||||||
/**
|
|
||||||
* https://square.github.io/okhttp/
|
|
||||||
*/
|
|
||||||
const val logging_interceptor: String = "com.squareup.okhttp3:logging-interceptor:" +
|
|
||||||
Versions.logging_interceptor
|
|
||||||
|
|
||||||
const val ink_page_indicator: String = "com.pacioianu.david:ink-page-indicator:" +
|
const val ink_page_indicator: String = "com.pacioianu.david:ink-page-indicator:" +
|
||||||
Versions.ink_page_indicator
|
Versions.ink_page_indicator
|
||||||
|
|
||||||
@ -272,11 +288,6 @@ object Libs {
|
|||||||
*/
|
*/
|
||||||
const val junit_jupiter: String = "org.junit.jupiter:junit-jupiter:" + Versions.junit_jupiter
|
const val junit_jupiter: String = "org.junit.jupiter:junit-jupiter:" + Versions.junit_jupiter
|
||||||
|
|
||||||
/**
|
|
||||||
* https://square.github.io/okhttp/
|
|
||||||
*/
|
|
||||||
const val mockwebserver: String = "com.squareup.okhttp3:mockwebserver:" + Versions.mockwebserver
|
|
||||||
|
|
||||||
const val xfetch2okhttp: String = "androidx.tonyodev.fetch2okhttp:xfetch2okhttp:" +
|
const val xfetch2okhttp: String = "androidx.tonyodev.fetch2okhttp:xfetch2okhttp:" +
|
||||||
Versions.xfetch2okhttp
|
Versions.xfetch2okhttp
|
||||||
|
|
||||||
@ -346,7 +357,7 @@ object Libs {
|
|||||||
const val kiwixlib: String = "org.kiwix.kiwixlib:kiwixlib:" + Versions.kiwixlib
|
const val kiwixlib: String = "org.kiwix.kiwixlib:kiwixlib:" + Versions.kiwixlib
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* http://developer.android.com/tools/extras/support-library.html
|
* https://github.com/material-components/material-components-android
|
||||||
*/
|
*/
|
||||||
const val material: String = "com.google.android.material:material:" + Versions.material
|
const val material: String = "com.google.android.material:material:" + Versions.material
|
||||||
|
|
||||||
@ -366,16 +377,16 @@ object Libs {
|
|||||||
*/
|
*/
|
||||||
const val ktlint: String = "com.pinterest:ktlint:" + Versions.ktlint
|
const val ktlint: String = "com.pinterest:ktlint:" + Versions.ktlint
|
||||||
|
|
||||||
/**
|
|
||||||
* https://square.github.io/okhttp/
|
|
||||||
*/
|
|
||||||
const val okhttp: String = "com.squareup.okhttp3:okhttp:" + Versions.okhttp
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://github.com/ReactiveX/RxJava
|
* https://github.com/ReactiveX/RxJava
|
||||||
*/
|
*/
|
||||||
const val rxjava: String = "io.reactivex.rxjava2:rxjava:" + Versions.rxjava
|
const val rxjava: String = "io.reactivex.rxjava2:rxjava:" + Versions.rxjava
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://developer.android.com/jetpack/androidx
|
||||||
|
*/
|
||||||
|
const val webkit: String = "androidx.webkit:webkit:" + Versions.webkit
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://developer.android.com/studio
|
* https://developer.android.com/studio
|
||||||
*/
|
*/
|
||||||
|
@ -16,17 +16,19 @@ object Versions {
|
|||||||
|
|
||||||
const val com_squareup_retrofit2: String = "2.5.0" // available: "2.9.0"
|
const val com_squareup_retrofit2: String = "2.5.0" // available: "2.9.0"
|
||||||
|
|
||||||
|
const val com_squareup_okhttp3: String = "3.6.0" // available: "4.8.0"
|
||||||
|
|
||||||
const val org_jetbrains_kotlin: String = "1.3.72"
|
const val org_jetbrains_kotlin: String = "1.3.72"
|
||||||
|
|
||||||
const val com_google_dagger: String = "2.26" // available: "2.28.1"
|
const val com_google_dagger: String = "2.26" // available: "2.28.3"
|
||||||
|
|
||||||
const val com_yahoo_squidb: String = "2.0.0" // available: "3.2.3"
|
const val com_yahoo_squidb: String = "2.0.0" // available: "3.2.3"
|
||||||
|
|
||||||
const val com_jakewharton: String = "10.2.1"
|
const val com_jakewharton: String = "10.2.1" // available: "10.2.2"
|
||||||
|
|
||||||
const val androidx_test: String = "1.2.0"
|
const val androidx_test: String = "1.2.0"
|
||||||
|
|
||||||
const val io_objectbox: String = "2.6.0"
|
const val io_objectbox: String = "2.6.0" // available: "2.7.0"
|
||||||
|
|
||||||
const val org_jacoco: String = "0.7.9"
|
const val org_jacoco: String = "0.7.9"
|
||||||
|
|
||||||
@ -44,8 +46,6 @@ object Versions {
|
|||||||
|
|
||||||
const val javax_annotation_api: String = "1.3.2"
|
const val javax_annotation_api: String = "1.3.2"
|
||||||
|
|
||||||
const val logging_interceptor: String = "3.6.0" // available: "4.7.2"
|
|
||||||
|
|
||||||
const val ink_page_indicator: String = "1.3.0"
|
const val ink_page_indicator: String = "1.3.0"
|
||||||
|
|
||||||
const val leakcanary_android: String = "2.4"
|
const val leakcanary_android: String = "2.4"
|
||||||
@ -58,8 +58,6 @@ object Versions {
|
|||||||
|
|
||||||
const val junit_jupiter: String = "5.6.2"
|
const val junit_jupiter: String = "5.6.2"
|
||||||
|
|
||||||
const val mockwebserver: String = "3.6.0" // available: "4.7.2"
|
|
||||||
|
|
||||||
const val xfetch2okhttp: String = "3.1.4"
|
const val xfetch2okhttp: String = "3.1.4"
|
||||||
|
|
||||||
const val assertj_core: String = "3.16.1"
|
const val assertj_core: String = "3.16.1"
|
||||||
@ -68,7 +66,7 @@ object Versions {
|
|||||||
|
|
||||||
const val fragment_ktx: String = "1.2.5"
|
const val fragment_ktx: String = "1.2.5"
|
||||||
|
|
||||||
const val lint_gradle: String = "27.0.0"
|
const val lint_gradle: String = "27.0.1"
|
||||||
|
|
||||||
const val testing_ktx: String = "1.1.2"
|
const val testing_ktx: String = "1.1.2"
|
||||||
|
|
||||||
@ -84,11 +82,11 @@ object Versions {
|
|||||||
|
|
||||||
const val rxandroid: String = "2.1.1"
|
const val rxandroid: String = "2.1.1"
|
||||||
|
|
||||||
const val core_ktx: String = "1.3.0"
|
const val core_ktx: String = "1.3.0" // available: "1.3.1"
|
||||||
|
|
||||||
const val kiwixlib: String = "9.2.3"
|
const val kiwixlib: String = "9.2.3" // available: "9.3.1"
|
||||||
|
|
||||||
const val material: String = "1.1.0"
|
const val material: String = "1.1.0" // available: "1.2.0"
|
||||||
|
|
||||||
const val multidex: String = "2.0.1"
|
const val multidex: String = "2.0.1"
|
||||||
|
|
||||||
@ -100,16 +98,16 @@ object Versions {
|
|||||||
|
|
||||||
const val ktlint: String = "0.36.0" // available: "0.37.2"
|
const val ktlint: String = "0.36.0" // available: "0.37.2"
|
||||||
|
|
||||||
const val okhttp: String = "3.6.0" // available: "4.7.2"
|
|
||||||
|
|
||||||
const val rxjava: String = "2.2.19"
|
const val rxjava: String = "2.2.19"
|
||||||
|
|
||||||
const val aapt2: String = "4.0.0-6051327"
|
const val webkit: String = "1.2.0"
|
||||||
|
|
||||||
|
const val aapt2: String = "4.0.1-6197926"
|
||||||
|
|
||||||
const val junit: String = "1.1.1"
|
const val junit: String = "1.1.1"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current version: "6.1.1"
|
* Current version: "6.2"
|
||||||
* See issue 19: How to update Gradle itself?
|
* See issue 19: How to update Gradle itself?
|
||||||
* https://github.com/jmfayard/buildSrcVersions/issues/19
|
* https://github.com/jmfayard/buildSrcVersions/issues/19
|
||||||
*/
|
*/
|
||||||
|
@ -60,4 +60,5 @@ dependencies {
|
|||||||
implementation(Libs.android_arch_lifecycle_extensions)
|
implementation(Libs.android_arch_lifecycle_extensions)
|
||||||
implementation(Libs.objectbox_kotlin)
|
implementation(Libs.objectbox_kotlin)
|
||||||
implementation(Libs.objectbox_rxjava)
|
implementation(Libs.objectbox_rxjava)
|
||||||
|
implementation(Libs.webkit)
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,13 @@ abstract class CoreApp : Application() {
|
|||||||
@Inject
|
@Inject
|
||||||
lateinit var fileLogger: FileLogger
|
lateinit var fileLogger: FileLogger
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The init of this class does the work of initializing,
|
||||||
|
* simply injecting it is all that there is to be done
|
||||||
|
*/
|
||||||
|
@Inject
|
||||||
|
lateinit var serviceWorkerInitialiser: ServiceWorkerInitialiser
|
||||||
|
|
||||||
override fun attachBaseContext(base: Context) {
|
override fun attachBaseContext(base: Context) {
|
||||||
super.attachBaseContext(base)
|
super.attachBaseContext(base)
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Kiwix Android
|
||||||
|
* Copyright (c) 2020 Kiwix <android.kiwix.org>
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.kiwix.kiwixmobile.core
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Build
|
||||||
|
import android.webkit.WebResourceRequest
|
||||||
|
import android.webkit.WebResourceResponse
|
||||||
|
import androidx.webkit.ServiceWorkerClientCompat
|
||||||
|
import androidx.webkit.ServiceWorkerControllerCompat
|
||||||
|
import androidx.webkit.WebViewFeature
|
||||||
|
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class ServiceWorkerInitialiser @Inject constructor(
|
||||||
|
context: Context,
|
||||||
|
zimReaderContainer: ZimReaderContainer
|
||||||
|
) {
|
||||||
|
init {
|
||||||
|
if (WebViewFeature.isFeatureSupported(WebViewFeature.SERVICE_WORKER_BASIC_USAGE)) {
|
||||||
|
ServiceWorkerControllerCompat.getInstance()
|
||||||
|
.setServiceWorkerClient(object : ServiceWorkerClientCompat() {
|
||||||
|
override fun shouldInterceptRequest(request: WebResourceRequest): WebResourceResponse? {
|
||||||
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
zimReaderContainer.load(request.url.toString())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -47,8 +47,10 @@ public abstract class CoreWebViewClient extends WebViewClient {
|
|||||||
protected final WebViewCallback callback;
|
protected final WebViewCallback callback;
|
||||||
protected final ZimReaderContainer zimReaderContainer;
|
protected final ZimReaderContainer zimReaderContainer;
|
||||||
private View home;
|
private View home;
|
||||||
private static String LEGACY_CONTENT_PREFIX =
|
private static String[] LEGACY_CONTENT_PREFIXES = new String[] {
|
||||||
Uri.parse("content://" + CoreApp.getInstance().getPackageName() + ".zim.base/").toString();
|
"zim://content/",
|
||||||
|
Uri.parse("content://" + CoreApp.getInstance().getPackageName() + ".zim.base/").toString()
|
||||||
|
};
|
||||||
private String urlWithAnchor;
|
private String urlWithAnchor;
|
||||||
|
|
||||||
public CoreWebViewClient(
|
public CoreWebViewClient(
|
||||||
@ -94,9 +96,12 @@ public abstract class CoreWebViewClient extends WebViewClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String convertLegacyUrl(String url) {
|
private String convertLegacyUrl(String url) {
|
||||||
return url.startsWith(LEGACY_CONTENT_PREFIX)
|
for (String legacyContentPrefix : LEGACY_CONTENT_PREFIXES) {
|
||||||
? url.replace(LEGACY_CONTENT_PREFIX, CONTENT_PREFIX)
|
if (url.startsWith(legacyContentPrefix)) {
|
||||||
: url;
|
return url.replace(legacyContentPrefix, CONTENT_PREFIX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean handleEpubAndPdf(String url) {
|
private boolean handleEpubAndPdf(String url) {
|
||||||
|
@ -236,7 +236,7 @@ class ZimFileReader constructor(
|
|||||||
@JvmField
|
@JvmField
|
||||||
val UI_URI: Uri? = Uri.parse("content://org.kiwix.ui/")
|
val UI_URI: Uri? = Uri.parse("content://org.kiwix.ui/")
|
||||||
|
|
||||||
const val CONTENT_PREFIX = "zim://content/"
|
const val CONTENT_PREFIX = "https://kiwix.app/"
|
||||||
|
|
||||||
private val INVERT_IMAGES_VIDEO =
|
private val INVERT_IMAGES_VIDEO =
|
||||||
"""
|
"""
|
||||||
@ -253,7 +253,8 @@ class ZimFileReader constructor(
|
|||||||
filter: invert(0);
|
filter: invert(0);
|
||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
private val assetExtensions = listOf("3gp", "mp4", "m4a", "webm", "mkv", "ogg", "ogv", "svg")
|
private val assetExtensions =
|
||||||
|
listOf("3gp", "mp4", "m4a", "webm", "mkv", "ogg", "ogv", "svg", "warc")
|
||||||
private const val DEFAULT_MIME_TYPE = "application/octet-stream"
|
private const val DEFAULT_MIME_TYPE = "application/octet-stream"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user