mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-19 12:26:13 -04:00
Merge pull request #1368 from kiwix/feature/mhutti1/#735
#735 Fix and re-enable Stackoverflow ZIMs
This commit is contained in:
commit
a8912c8230
@ -365,6 +365,15 @@ public class ZimContentProvider extends ContentProvider {
|
||||
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
|
||||
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
|
||||
|
||||
@ -407,7 +416,7 @@ public class ZimContentProvider extends ContentProvider {
|
||||
private ParcelFileDescriptor loadVideoViaCache(Uri uri) throws IOException {
|
||||
String filePath = getFilePath(uri);
|
||||
String fileName = uri.toString();
|
||||
fileName = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length());
|
||||
fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
|
||||
File f = new File(FileUtils.getFileCacheDir(getContext()), fileName);
|
||||
byte[] data = currentJNIReader.getContent(new JNIKiwixString(filePath), new JNIKiwixString(),
|
||||
new JNIKiwixString(), new JNIKiwixInt());
|
||||
@ -473,7 +482,7 @@ public class ZimContentProvider extends ContentProvider {
|
||||
try {
|
||||
final JNIKiwixString mime = new JNIKiwixString();
|
||||
final JNIKiwixInt size = new JNIKiwixInt();
|
||||
final JNIKiwixString url = new JNIKiwixString(this.articleZimUrl);
|
||||
final JNIKiwixString url = new JNIKiwixString(articleZimUrl);
|
||||
byte[] data = currentJNIReader.getContent(url, new JNIKiwixString(), mime, size);
|
||||
if (mime.value != null && mime.value.equals("text/css") && MainActivity.nightMode) {
|
||||
out.write(("img, video { \n" +
|
||||
|
@ -55,7 +55,10 @@ public class KiwixWebViewClient extends WebViewClient {
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
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);
|
||||
if (DOCUMENT_TYPES.containsKey(extension)) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
|
@ -406,8 +406,7 @@ class ZimManageViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
.filterNot { downloadedBooksIds.contains(it.id) }
|
||||
.filterNot { downloadingBookIds.contains(it.id) }
|
||||
.filterNot { it.url.contains("/stack_exchange/") }, // Temp filter see #694, filter)
|
||||
.filterNot { downloadingBookIds.contains(it.id) },
|
||||
filter
|
||||
)
|
||||
|
||||
|
@ -50,8 +50,8 @@ import org.kiwix.kiwixmobile.downloader.model.DownloadState
|
||||
import org.kiwix.kiwixmobile.downloader.model.DownloadStatus
|
||||
import org.kiwix.kiwixmobile.downloader.model.UriToFileConverter
|
||||
import org.kiwix.kiwixmobile.language
|
||||
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity
|
||||
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity.Book
|
||||
import org.kiwix.kiwixmobile.libraryNetworkEntity
|
||||
import org.kiwix.kiwixmobile.resetSchedulers
|
||||
import org.kiwix.kiwixmobile.setScheduler
|
||||
import org.kiwix.kiwixmobile.utils.BookUtils
|
||||
@ -66,7 +66,6 @@ import org.kiwix.kiwixmobile.zim_manager.fileselect_view.adapter.BooksOnDiskList
|
||||
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.adapter.BooksOnDiskListItem.BookOnDisk
|
||||
import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.LibraryListItem
|
||||
import java.io.File
|
||||
import java.util.LinkedList
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.TimeUnit.MILLISECONDS
|
||||
import java.util.concurrent.TimeUnit.SECONDS
|
||||
@ -302,12 +301,13 @@ class ZimManageViewModelTest {
|
||||
)
|
||||
expectNetworkDbAndDefault(
|
||||
listOf(
|
||||
Book().apply { language = "eng" },
|
||||
Book().apply { language = "eng" },
|
||||
Book().apply { language = "fra" }
|
||||
book(language = "eng"),
|
||||
book(language = "eng"),
|
||||
book(language = "fra")
|
||||
),
|
||||
listOf(),
|
||||
defaultLanguage)
|
||||
defaultLanguage
|
||||
)
|
||||
verify {
|
||||
newLanguagesDao.insert(
|
||||
listOf(
|
||||
@ -337,9 +337,9 @@ class ZimManageViewModelTest {
|
||||
)
|
||||
expectNetworkDbAndDefault(
|
||||
listOf(
|
||||
Book().apply { language = "eng" },
|
||||
Book().apply { language = "eng" },
|
||||
Book().apply { language = "fra" }
|
||||
book(language = "eng"),
|
||||
book(language = "eng"),
|
||||
book(language = "fra")
|
||||
),
|
||||
listOf(dbLanguage),
|
||||
language(isActive = true, occurencesOfLanguage = 1)
|
||||
@ -368,10 +368,8 @@ class ZimManageViewModelTest {
|
||||
) {
|
||||
every { application.getString(any()) } returns ""
|
||||
every { kiwixService.library } returns Single.just(
|
||||
LibraryNetworkEntity().apply {
|
||||
book = LinkedList(networkBooks)
|
||||
})
|
||||
val defaultLanguage = defaultLanguage
|
||||
libraryNetworkEntity(networkBooks)
|
||||
)
|
||||
every { defaultLanguageProvider.provide() } returns defaultLanguage
|
||||
languages.onNext(dbBooks)
|
||||
testScheduler.triggerActions()
|
||||
@ -392,41 +390,34 @@ class ZimManageViewModelTest {
|
||||
every { downloader.queryStatus(any()) } returns emptyList()
|
||||
every { application.getString(R.string.your_languages) } returns "1"
|
||||
every { application.getString(R.string.other_languages) } returns "2"
|
||||
val bookAlreadyOnDisk = Book().apply {
|
||||
id = "0"
|
||||
url = ""
|
||||
val bookAlreadyOnDisk = book(
|
||||
id = "0",
|
||||
url = "",
|
||||
language = Locale.ENGLISH.language
|
||||
}
|
||||
val bookDownloading = Book().apply {
|
||||
id = "1"
|
||||
)
|
||||
val bookDownloading = book(
|
||||
id = "1",
|
||||
url = ""
|
||||
}
|
||||
val bookWithStackExchange = Book().apply {
|
||||
id = "2"
|
||||
url = "blahblah/stack_exchange/"
|
||||
}
|
||||
val bookWithActiveLanguage = Book().apply {
|
||||
id = "3"
|
||||
language = "activeLanguage"
|
||||
)
|
||||
val bookWithActiveLanguage = book(
|
||||
id = "3",
|
||||
language = "activeLanguage",
|
||||
url = ""
|
||||
}
|
||||
val bookWithInactiveLanguage = Book().apply {
|
||||
id = "3"
|
||||
language = "inactiveLanguage"
|
||||
)
|
||||
val bookWithInactiveLanguage = book(
|
||||
id = "3",
|
||||
language = "inactiveLanguage",
|
||||
url = ""
|
||||
}
|
||||
)
|
||||
every { kiwixService.library } returns Single.just(
|
||||
LibraryNetworkEntity().apply {
|
||||
book = LinkedList(
|
||||
listOf(
|
||||
bookAlreadyOnDisk,
|
||||
bookDownloading,
|
||||
bookWithStackExchange,
|
||||
bookWithActiveLanguage,
|
||||
bookWithInactiveLanguage
|
||||
)
|
||||
libraryNetworkEntity(
|
||||
listOf(
|
||||
bookAlreadyOnDisk,
|
||||
bookDownloading,
|
||||
bookWithActiveLanguage,
|
||||
bookWithInactiveLanguage
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
networkStates.onNext(CONNECTED)
|
||||
downloads.onNext(listOf(downloadModel(book = bookDownloading)))
|
||||
@ -453,15 +444,15 @@ class ZimManageViewModelTest {
|
||||
|
||||
@Test
|
||||
fun `library filters out files over 4GB if file system state says to`() {
|
||||
val bookOver4Gb = Book().apply {
|
||||
id = "0"
|
||||
url = ""
|
||||
val bookOver4Gb = book(
|
||||
id = "0",
|
||||
url = "",
|
||||
size = "${Fat32Checker.FOUR_GIGABYTES_IN_KILOBYTES + 1}"
|
||||
}
|
||||
)
|
||||
every { kiwixService.library } returns Single.just(
|
||||
LibraryNetworkEntity().apply {
|
||||
book = LinkedList(listOf(bookOver4Gb))
|
||||
}
|
||||
libraryNetworkEntity(
|
||||
listOf(bookOver4Gb)
|
||||
)
|
||||
)
|
||||
networkStates.onNext(CONNECTED)
|
||||
downloads.onNext(listOf())
|
||||
|
Loading…
x
Reference in New Issue
Block a user