mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-22 12:03:09 -04:00
#735 Fix ZIM redirects
This commit is contained in:
parent
c3f7e6f0ad
commit
4973109bd5
@ -365,6 +365,15 @@ public class ZimContentProvider extends ContentProvider {
|
|||||||
return mimeType;
|
return mimeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getRedirect(String url) {
|
||||||
|
return Uri.parse(CONTENT_URI + currentJNIReader.checkUrl(getFilePath(Uri.parse(url))))
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isRedirect(String url) {
|
||||||
|
return !url.equals(getRedirect(url));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
|
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
|
||||||
|
|
||||||
@ -412,7 +421,7 @@ public class ZimContentProvider extends ContentProvider {
|
|||||||
JNIKiwixString mime = new JNIKiwixString();
|
JNIKiwixString mime = new JNIKiwixString();
|
||||||
JNIKiwixString title = new JNIKiwixString();
|
JNIKiwixString title = new JNIKiwixString();
|
||||||
JNIKiwixInt size = new JNIKiwixInt();
|
JNIKiwixInt size = new JNIKiwixInt();
|
||||||
byte[] data = currentJNIReader.getContent(filePath, title, mime, size);
|
byte[] data = currentJNIReader.getContent(new JNIKiwixString(filePath), title, mime, size);
|
||||||
FileOutputStream out = new FileOutputStream(f);
|
FileOutputStream out = new FileOutputStream(f);
|
||||||
out.write(data, 0, data.length);
|
out.write(data, 0, data.length);
|
||||||
out.flush();
|
out.flush();
|
||||||
@ -476,7 +485,7 @@ public class ZimContentProvider extends ContentProvider {
|
|||||||
JNIKiwixString mime = new JNIKiwixString();
|
JNIKiwixString mime = new JNIKiwixString();
|
||||||
JNIKiwixString title = new JNIKiwixString();
|
JNIKiwixString title = new JNIKiwixString();
|
||||||
JNIKiwixInt size = new JNIKiwixInt();
|
JNIKiwixInt size = new JNIKiwixInt();
|
||||||
byte[] data = currentJNIReader.getContent(articleZimUrl, title, mime, size);
|
byte[] data = currentJNIReader.getContent(new JNIKiwixString(articleZimUrl), title, mime, size);
|
||||||
if (mime.value != null && mime.value.equals("text/css") && MainActivity.nightMode) {
|
if (mime.value != null && mime.value.equals("text/css") && MainActivity.nightMode) {
|
||||||
out.write(("img, video { \n" +
|
out.write(("img, video { \n" +
|
||||||
" -webkit-filter: invert(1); \n" +
|
" -webkit-filter: invert(1); \n" +
|
||||||
|
@ -55,7 +55,10 @@ public class KiwixWebViewClient extends WebViewClient {
|
|||||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||||
callback.webViewUrlLoading();
|
callback.webViewUrlLoading();
|
||||||
|
|
||||||
if (url.startsWith(ZimContentProvider.CONTENT_URI.toString())) {
|
if (ZimContentProvider.isRedirect(url)) {
|
||||||
|
view.loadUrl(ZimContentProvider.getRedirect(url));
|
||||||
|
return true;
|
||||||
|
} else if (url.startsWith(ZimContentProvider.CONTENT_URI.toString())) {
|
||||||
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
|
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
|
||||||
if (DOCUMENT_TYPES.containsKey(extension)) {
|
if (DOCUMENT_TYPES.containsKey(extension)) {
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user