#1659 Autoload next video - fix instrumentation compilation - use constant for comparing urls - update constant to now longer be content provider related

This commit is contained in:
Sean Mac Gillicuddy 2020-03-30 14:13:20 +01:00
parent 3a2ac5f064
commit 883641076e
4 changed files with 12 additions and 16 deletions

View File

@ -39,7 +39,6 @@ import org.junit.runner.RunWith;
import org.kiwix.kiwixmobile.core.CoreApp; import org.kiwix.kiwixmobile.core.CoreApp;
import org.kiwix.kiwixmobile.core.di.components.DaggerTestComponent; import org.kiwix.kiwixmobile.core.di.components.DaggerTestComponent;
import org.kiwix.kiwixmobile.core.di.components.TestComponent; import org.kiwix.kiwixmobile.core.di.components.TestComponent;
import org.kiwix.kiwixmobile.core.reader.ZimContentProvider;
import org.kiwix.kiwixmobile.main.KiwixMainActivity; import org.kiwix.kiwixmobile.main.KiwixMainActivity;
import org.kiwix.kiwixmobile.testutils.TestUtils; import org.kiwix.kiwixmobile.testutils.TestUtils;
import org.kiwix.kiwixmobile.utils.KiwixIdlingResource; import org.kiwix.kiwixmobile.utils.KiwixIdlingResource;
@ -92,8 +91,6 @@ public class NetworkTest {
CoreApp.setCoreComponent(component); CoreApp.setCoreComponent(component);
ZimContentProvider zimContentProvider = new ZimContentProvider();
CoreApp.getCoreComponent().inject(zimContentProvider);
component.inject(this); component.inject(this);
InputStream library = NetworkTest.class.getClassLoader().getResourceAsStream("library.xml"); InputStream library = NetworkTest.class.getClassLoader().getResourceAsStream("library.xml");
InputStream metalinks = InputStream metalinks =

View File

@ -1390,7 +1390,7 @@ public abstract class CoreMainActivity extends BaseActivity
@NotNull @NotNull
private String contentUrl(String articleUrl) { private String contentUrl(String articleUrl) {
return Uri.parse(ZimFileReader.CONTENT_URI + articleUrl).toString(); return Uri.parse(ZimFileReader.CONTENT_PREFIX + articleUrl).toString();
} }
@NotNull @NotNull
@ -1689,7 +1689,7 @@ public abstract class CoreMainActivity extends BaseActivity
@Override @Override
public void webViewLongClick(final String url) { public void webViewLongClick(final String url) {
boolean handleEvent = false; boolean handleEvent = false;
if (url.startsWith(ZimFileReader.CONTENT_URI.toString())) { if (url.startsWith(ZimFileReader.CONTENT_PREFIX)) {
// This is my web site, so do not override; let my WebView load the page // This is my web site, so do not override; let my WebView load the page
handleEvent = true; handleEvent = true;
} else if (url.startsWith("file://")) { } else if (url.startsWith("file://")) {

View File

@ -31,11 +31,12 @@ import androidx.annotation.Nullable;
import java.util.HashMap; import java.util.HashMap;
import org.kiwix.kiwixmobile.core.CoreApp; import org.kiwix.kiwixmobile.core.CoreApp;
import org.kiwix.kiwixmobile.core.R; import org.kiwix.kiwixmobile.core.R;
import org.kiwix.kiwixmobile.core.reader.ZimFileReader;
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer; import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer;
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil; import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil;
import static org.kiwix.kiwixmobile.core.main.CoreMainActivity.HOME_URL; import static org.kiwix.kiwixmobile.core.main.CoreMainActivity.HOME_URL;
import static org.kiwix.kiwixmobile.core.reader.ZimFileReader.CONTENT_PREFIX;
import static org.kiwix.kiwixmobile.core.reader.ZimFileReader.UI_URI;
import static org.kiwix.kiwixmobile.core.utils.ConstantsKt.EXTRA_EXTERNAL_LINK; import static org.kiwix.kiwixmobile.core.utils.ConstantsKt.EXTRA_EXTERNAL_LINK;
import static org.kiwix.kiwixmobile.core.utils.ConstantsKt.TAG_KIWIX; import static org.kiwix.kiwixmobile.core.utils.ConstantsKt.TAG_KIWIX;
@ -67,7 +68,7 @@ public abstract class CoreWebViewClient extends WebViewClient {
view.loadUrl(zimReaderContainer.getRedirect(url)); view.loadUrl(zimReaderContainer.getRedirect(url));
return true; return true;
} }
if (url.startsWith(ZimFileReader.CONTENT_URI.toString())) { if (url.startsWith(CONTENT_PREFIX)) {
return handleEpubAndPdf(url); return handleEpubAndPdf(url);
} }
if (url.startsWith("file://")) { if (url.startsWith("file://")) {
@ -78,7 +79,7 @@ public abstract class CoreWebViewClient extends WebViewClient {
// Allow javascript for HTML functions and code execution (EX: night mode) // Allow javascript for HTML functions and code execution (EX: night mode)
return true; return true;
} }
if (url.startsWith(ZimFileReader.UI_URI.toString())) { if (url.startsWith(UI_URI.toString())) {
Log.e("KiwixWebViewClient", "UI Url " + url + " not supported."); Log.e("KiwixWebViewClient", "UI Url " + url + " not supported.");
//TODO: Document this code - what's a UI_URL? //TODO: Document this code - what's a UI_URL?
return true; return true;
@ -143,7 +144,7 @@ public abstract class CoreWebViewClient extends WebViewClient {
@Nullable @Nullable
@Override @Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) { public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if (url.startsWith("content")) { if (url.startsWith(CONTENT_PREFIX)) {
return zimReaderContainer.load(url); return zimReaderContainer.load(url);
} else { } else {
return super.shouldInterceptRequest(view, url); return super.shouldInterceptRequest(view, url);

View File

@ -33,7 +33,7 @@ import org.kiwix.kiwixlib.Pair
import org.kiwix.kiwixmobile.core.CoreApp import org.kiwix.kiwixmobile.core.CoreApp
import org.kiwix.kiwixmobile.core.NightModeConfig import org.kiwix.kiwixmobile.core.NightModeConfig
import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book
import org.kiwix.kiwixmobile.core.reader.ZimFileReader.Companion.CONTENT_URI import org.kiwix.kiwixmobile.core.reader.ZimFileReader.Companion.CONTENT_PREFIX
import org.kiwix.kiwixmobile.core.search.SearchSuggestion import org.kiwix.kiwixmobile.core.search.SearchSuggestion
import org.kiwix.kiwixmobile.core.utils.files.FileUtils import org.kiwix.kiwixmobile.core.utils.files.FileUtils
import java.io.File import java.io.File
@ -135,10 +135,10 @@ class ZimFileReader constructor(
fun getRedirect(url: String) = "${toRedirect(url)}" fun getRedirect(url: String) = "${toRedirect(url)}"
fun isRedirect(url: String) = fun isRedirect(url: String) =
url.startsWith("$CONTENT_URI") && url != getRedirect(url) url.startsWith(CONTENT_PREFIX) && url != getRedirect(url)
private fun toRedirect(url: String) = private fun toRedirect(url: String) =
"$CONTENT_URI${jniKiwixReader.checkUrl(url.toUri().filePath)}".toUri() "$CONTENT_PREFIX${jniKiwixReader.checkUrl(url.toUri().filePath)}".toUri()
private fun loadContent(uri: String) = private fun loadContent(uri: String) =
try { try {
@ -234,9 +234,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/")
@JvmField const val CONTENT_PREFIX: String = "zim://content/"
val CONTENT_URI: Uri? =
Uri.parse("content://${CoreApp.getInstance().packageName}.zim.base/")
private val INVERT_IMAGES_VIDEO = private val INVERT_IMAGES_VIDEO =
""" """
img, video, div[poster], div#header { img, video, div[poster], div#header {
@ -260,7 +258,7 @@ private fun String.removeArguments() = substringBefore("?")
private val Uri.filePath: String private val Uri.filePath: String
get() = toString().filePath get() = toString().filePath
private val String.filePath: String private val String.filePath: String
get() = substringAfter("$CONTENT_URI").substringBefore("#") get() = substringAfter(CONTENT_PREFIX).substringBefore("#")
private val String.mimeType: String? private val String.mimeType: String?
get() = MimeTypeMap.getSingleton().getMimeTypeFromExtension( get() = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
MimeTypeMap.getFileExtensionFromUrl(this) MimeTypeMap.getFileExtensionFromUrl(this)