mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-09 07:16:04 -04:00
Merge remote-tracking branch 'origin/develop' into release/3.0.4
This commit is contained in:
commit
d7d46ec163
@ -99,6 +99,7 @@ import org.kiwix.kiwixmobile.R;
|
|||||||
import org.kiwix.kiwixmobile.base.BaseActivity;
|
import org.kiwix.kiwixmobile.base.BaseActivity;
|
||||||
import org.kiwix.kiwixmobile.bookmark.BookmarkItem;
|
import org.kiwix.kiwixmobile.bookmark.BookmarkItem;
|
||||||
import org.kiwix.kiwixmobile.bookmark.BookmarksActivity;
|
import org.kiwix.kiwixmobile.bookmark.BookmarksActivity;
|
||||||
|
import org.kiwix.kiwixmobile.extensions.ContextExtensionsKt;
|
||||||
import org.kiwix.kiwixmobile.help.HelpActivity;
|
import org.kiwix.kiwixmobile.help.HelpActivity;
|
||||||
import org.kiwix.kiwixmobile.history.HistoryActivity;
|
import org.kiwix.kiwixmobile.history.HistoryActivity;
|
||||||
import org.kiwix.kiwixmobile.history.HistoryListItem;
|
import org.kiwix.kiwixmobile.history.HistoryListItem;
|
||||||
@ -1090,24 +1091,26 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
&& Build.VERSION.SDK_INT != 23)) {
|
&& Build.VERSION.SDK_INT != 23)) {
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
zimReaderContainer.setZimFile(file);
|
zimReaderContainer.setZimFile(file);
|
||||||
if (clearHistory) {
|
if (zimReaderContainer.getZimFileReader() != null) {
|
||||||
requestClearHistoryAfterLoad = true;
|
if (clearHistory) {
|
||||||
}
|
requestClearHistoryAfterLoad = true;
|
||||||
if (menu != null) {
|
}
|
||||||
initAllMenuItems();
|
if (menu != null) {
|
||||||
|
initAllMenuItems();
|
||||||
|
} else {
|
||||||
|
// Menu may not be initialized yet. In this case
|
||||||
|
// signal to menu create to show
|
||||||
|
requestInitAllMenuItems = true;
|
||||||
|
}
|
||||||
|
openMainPage();
|
||||||
|
presenter.loadCurrentZimBookmarksUrl();
|
||||||
} else {
|
} else {
|
||||||
// Menu may not be initialized yet. In this case
|
ContextExtensionsKt.toast(this, R.string.error_file_invalid, Toast.LENGTH_LONG);
|
||||||
// signal to menu create to show
|
showHomePage();
|
||||||
requestInitAllMenuItems = true;
|
|
||||||
}
|
}
|
||||||
openMainPage();
|
|
||||||
presenter.loadCurrentZimBookmarksUrl();
|
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG_KIWIX, "ZIM file doesn't exist at " + file.getAbsolutePath());
|
Log.w(TAG_KIWIX, "ZIM file doesn't exist at " + file.getAbsolutePath());
|
||||||
|
ContextExtensionsKt.toast(this, R.string.error_file_not_found, Toast.LENGTH_LONG);
|
||||||
Toast.makeText(this, getResources().getString(R.string.error_file_not_found),
|
|
||||||
Toast.LENGTH_LONG)
|
|
||||||
.show();
|
|
||||||
showHomePage();
|
showHomePage();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -41,15 +41,15 @@ object FileUtils {
|
|||||||
"${Environment.getExternalStorageDirectory()}${File.separator}Android" +
|
"${Environment.getExternalStorageDirectory()}${File.separator}Android" +
|
||||||
"${File.separator}obb${File.separator}${BuildConfig.APPLICATION_ID}"
|
"${File.separator}obb${File.separator}${BuildConfig.APPLICATION_ID}"
|
||||||
|
|
||||||
@JvmStatic fun getFileCacheDir(context: Context): File =
|
@JvmStatic fun getFileCacheDir(context: Context): File? =
|
||||||
if (Environment.MEDIA_MOUNTED == Environment.getExternalStorageState()) {
|
if (Environment.MEDIA_MOUNTED == Environment.getExternalStorageState()) {
|
||||||
context.externalCacheDir!!
|
context.externalCacheDir
|
||||||
} else {
|
} else {
|
||||||
context.cacheDir
|
context.cacheDir
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic @Synchronized fun deleteCachedFiles(context: Context) {
|
@JvmStatic @Synchronized fun deleteCachedFiles(context: Context) {
|
||||||
getFileCacheDir(context).deleteRecursively()
|
getFileCacheDir(context)?.deleteRecursively()
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic @Synchronized fun deleteZimFile(path: String) {
|
@JvmStatic @Synchronized fun deleteZimFile(path: String) {
|
||||||
@ -195,12 +195,16 @@ object FileUtils {
|
|||||||
uri: Uri
|
uri: Uri
|
||||||
): String? {
|
): String? {
|
||||||
val columnName = "_data"
|
val columnName = "_data"
|
||||||
return context.contentResolver.query(uri, arrayOf(columnName), null, null, null)
|
return try {
|
||||||
?.use {
|
context.contentResolver.query(uri, arrayOf(columnName), null, null, null)
|
||||||
if (it.moveToFirst() && it.getColumnIndex(columnName) != -1) {
|
?.use {
|
||||||
it[columnName]
|
if (it.moveToFirst() && it.getColumnIndex(columnName) != -1) {
|
||||||
} else null
|
it[columnName]
|
||||||
}
|
} else null
|
||||||
|
}
|
||||||
|
} catch (ignore: SecurityException) {
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic fun readLocalesFromAssets(context: Context) =
|
@JvmStatic fun readLocalesFromAssets(context: Context) =
|
||||||
|
@ -26,6 +26,7 @@ import android.webkit.MimeTypeMap
|
|||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
|
import org.kiwix.kiwixlib.JNIKiwixException
|
||||||
import org.kiwix.kiwixlib.JNIKiwixInt
|
import org.kiwix.kiwixlib.JNIKiwixInt
|
||||||
import org.kiwix.kiwixlib.JNIKiwixReader
|
import org.kiwix.kiwixlib.JNIKiwixReader
|
||||||
import org.kiwix.kiwixlib.JNIKiwixString
|
import org.kiwix.kiwixlib.JNIKiwixString
|
||||||
@ -51,11 +52,15 @@ class ZimFileReader(
|
|||||||
private val sharedPreferenceUtil: SharedPreferenceUtil
|
private val sharedPreferenceUtil: SharedPreferenceUtil
|
||||||
) {
|
) {
|
||||||
interface Factory {
|
interface Factory {
|
||||||
fun create(file: File): ZimFileReader
|
fun create(file: File): ZimFileReader?
|
||||||
|
|
||||||
class Impl @Inject constructor(val sharedPreferenceUtil: SharedPreferenceUtil) : Factory {
|
class Impl @Inject constructor(val sharedPreferenceUtil: SharedPreferenceUtil) : Factory {
|
||||||
override fun create(file: File) =
|
override fun create(file: File) =
|
||||||
ZimFileReader(file, sharedPreferenceUtil = sharedPreferenceUtil)
|
try {
|
||||||
|
ZimFileReader(file, sharedPreferenceUtil = sharedPreferenceUtil)
|
||||||
|
} catch (ignore: JNIKiwixException) {
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.kiwix.kiwixmobile.zim_manager.fileselect_view
|
package org.kiwix.kiwixmobile.zim_manager.fileselect_view
|
||||||
|
|
||||||
|
import io.reactivex.Flowable
|
||||||
import io.reactivex.functions.BiFunction
|
import io.reactivex.functions.BiFunction
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
import org.kiwix.kiwixmobile.database.newdb.dao.FetchDownloadDao
|
import org.kiwix.kiwixmobile.database.newdb.dao.FetchDownloadDao
|
||||||
@ -16,10 +17,10 @@ class StorageObserver @Inject constructor(
|
|||||||
private val zimReaderFactory: ZimFileReader.Factory
|
private val zimReaderFactory: ZimFileReader.Factory
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val booksOnFileSystem
|
val booksOnFileSystem: Flowable<List<BookOnDisk>>
|
||||||
get() = scanFiles()
|
get() = scanFiles()
|
||||||
.withLatestFrom(downloadDao.downloads(), BiFunction(::toFilesThatAreNotDownloading))
|
.withLatestFrom(downloadDao.downloads(), BiFunction(::toFilesThatAreNotDownloading))
|
||||||
.map { it.map(::convertToBookOnDisk) }
|
.map { it.mapNotNull(::convertToBookOnDisk) }
|
||||||
|
|
||||||
private fun scanFiles() = fileSearch.scan().subscribeOn(Schedulers.io())
|
private fun scanFiles() = fileSearch.scan().subscribeOn(Schedulers.io())
|
||||||
|
|
||||||
@ -29,5 +30,6 @@ class StorageObserver @Inject constructor(
|
|||||||
private fun fileHasNoMatchingDownload(downloads: List<DownloadModel>, file: File) =
|
private fun fileHasNoMatchingDownload(downloads: List<DownloadModel>, file: File) =
|
||||||
downloads.firstOrNull { file.absolutePath.endsWith(it.fileNameFromUrl) } == null
|
downloads.firstOrNull { file.absolutePath.endsWith(it.fileNameFromUrl) } == null
|
||||||
|
|
||||||
private fun convertToBookOnDisk(file: File) = BookOnDisk(file, zimReaderFactory.create(file))
|
private fun convertToBookOnDisk(file: File) =
|
||||||
|
zimReaderFactory.create(file)?.let { BookOnDisk(file, it) }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user