Skip to content

Commit

Permalink
Merge pull request #1535 from kiwix/release/3.0.4
Browse files Browse the repository at this point in the history
Release/3.0.4
  • Loading branch information
macgills authored Sep 30, 2019
2 parents e0d5bd7 + 66cbafd commit 06dee58
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 126 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
3.0.4
BUGFIX: Some users language was causing a crash due to unstable ISO codes
BUGFIX: Some unstable zim files were crashing when opened
BUGFIX: Long titles were rendering off screen on home page
BUGFIX: Issues when opening a file externally

3.0.0
NEW: Androidx support
NEW: In app error reporting
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dependencies {

// Get kiwixlib online if it is not populated locally
if (!shouldUseLocalVersion()) {
implementation 'org.kiwix.kiwixlib:kiwixlib:8.0.1'
implementation 'org.kiwix.kiwixlib:kiwixlib:8.1.0'
} else {
implementation 'com.getkeepsafe.relinker:relinker:1.3.1'
implementation fileTree(include: ['*.aar'], dir: 'libs')
Expand Down Expand Up @@ -193,7 +193,7 @@ def buildNumber = System.getenv('TRAVIS_BUILD_NUMBER') ?: "dev"
ext {
versionMajor = 3
versionMinor = 0
versionPatch = 3
versionPatch = 4
}

private String generateVersionName() {
Expand Down
17 changes: 4 additions & 13 deletions app/src/kiwix/play/release-notes/en-US/default.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
NEW: Androidx support
NEW: In app error reporting
NEW: Improved bookmarks
NEW: Help screen
NEW: Home page
NEW: Zim history
NEW: Introductory screen
NEW: Improved language selection
NEW: Add note to articles
NEW: Tabs
NEW: Share zim files to other Kiwix users
NEW: Host zim files on your phone
+ Bugfixes & Lots More
BUGFIX: Some users language was causing a crash due to unstable ISO codes
BUGFIX: Some unstable zim files were crashing when opened
BUGFIX: Long titles were rendering off screen on home page
BUGFIX: Issues when opening a file externally
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import dagger.Module;
import dagger.Provides;
import javax.inject.Singleton;
Expand All @@ -38,7 +39,12 @@ public JNIKiwix providesJNIKiwix(@NonNull Context context) {

@Provides
@Singleton
@Nullable
public JNIKiwixSearcher providesJNIKiwixSearcher() {
return new JNIKiwixSearcher();
try {
return new JNIKiwixSearcher();
} catch (UnsatisfiedLinkError ignore) {
return null;
}
}
}
33 changes: 18 additions & 15 deletions app/src/main/java/org/kiwix/kiwixmobile/main/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
import org.kiwix.kiwixmobile.base.BaseActivity;
import org.kiwix.kiwixmobile.bookmark.BookmarkItem;
import org.kiwix.kiwixmobile.bookmark.BookmarksActivity;
import org.kiwix.kiwixmobile.extensions.ContextExtensionsKt;
import org.kiwix.kiwixmobile.help.HelpActivity;
import org.kiwix.kiwixmobile.history.HistoryActivity;
import org.kiwix.kiwixmobile.history.HistoryListItem;
Expand Down Expand Up @@ -1090,24 +1091,26 @@ private void openZimFile(File file, boolean clearHistory) {
&& Build.VERSION.SDK_INT != 23)) {
if (file.exists()) {
zimReaderContainer.setZimFile(file);
if (clearHistory) {
requestClearHistoryAfterLoad = true;
}
if (menu != null) {
initAllMenuItems();
if (zimReaderContainer.getZimFileReader() != null) {
if (clearHistory) {
requestClearHistoryAfterLoad = true;
}
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 {
// Menu may not be initialized yet. In this case
// signal to menu create to show
requestInitAllMenuItems = true;
ContextExtensionsKt.toast(this, R.string.error_file_invalid, Toast.LENGTH_LONG);
showHomePage();
}
openMainPage();
presenter.loadCurrentZimBookmarksUrl();
} else {
Log.w(TAG_KIWIX, "ZIM file doesn't exist at " + file.getAbsolutePath());

Toast.makeText(this, getResources().getString(R.string.error_file_not_found),
Toast.LENGTH_LONG)
.show();
ContextExtensionsKt.toast(this, R.string.error_file_not_found, Toast.LENGTH_LONG);
showHomePage();
}
} else {
Expand Down Expand Up @@ -1661,7 +1664,7 @@ public boolean onPrepareOptionsMenu(Menu menu) {
toggleActionItemsConfig();
this.menu = menu;

if (tabSwitcherRoot.getVisibility() == View.VISIBLE) {
if (tabSwitcherRoot != null && tabSwitcherRoot.getVisibility() == View.VISIBLE) {
menu.findItem(R.id.menu_search).setVisible(false);
menu.findItem(R.id.menu_fullscreen).setVisible(false);
menu.findItem(R.id.menu_random_article).setVisible(false);
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/org/kiwix/kiwixmobile/utils/LanguageUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.kiwix.kiwixmobile.utils.Constants.TAG_KIWIX
import org.kiwix.kiwixmobile.utils.files.FileUtils
import java.text.Collator
import java.util.Locale
import java.util.MissingResourceException

class LanguageUtils(private val context: Context) {
private val localeLanguageCodes: List<String> = languageCodesFromAssets()
Expand Down Expand Up @@ -152,8 +153,14 @@ class LanguageUtils(private val context: Context) {

companion object {

private var localeMap =
Locale.getAvailableLocales().associateBy { it.isO3Language.toUpperCase(Locale.ROOT) }
private var isO3LanguageToLocaleMap: Map<String, Locale> =
Locale.getAvailableLocales().associateBy {
try {
it.isO3Language.toUpperCase(Locale.ROOT)
} catch (ignore: MissingResourceException) {
it.language.toUpperCase(Locale.ROOT)
}
}

private var fontExceptions = mapOf(
"km" to "fonts/KhmerOS.ttf",
Expand Down Expand Up @@ -204,7 +211,7 @@ class LanguageUtils(private val context: Context) {
*/
@JvmStatic
fun iSO3ToLocale(iso3: String?): Locale? =
iso3?.let { localeMap[it.toUpperCase(Locale.ROOT)] }
iso3?.let { isO3LanguageToLocaleMap[it.toUpperCase(Locale.ROOT)] }

@JvmStatic
fun getCurrentLocale(context: Context) = context.locale
Expand Down
63 changes: 38 additions & 25 deletions app/src/main/java/org/kiwix/kiwixmobile/utils/files/FileUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
*/
package org.kiwix.kiwixmobile.utils.files

import android.annotation.TargetApi
import android.content.ContentUris
import android.content.Context
import android.net.Uri
import android.os.Build
import android.os.Build.VERSION_CODES
import android.os.Environment
import android.provider.DocumentsContract
import android.util.Log
Expand All @@ -39,15 +41,15 @@ object FileUtils {
"${Environment.getExternalStorageDirectory()}${File.separator}Android" +
"${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()) {
context.externalCacheDir!!
context.externalCacheDir
} else {
context.cacheDir
}

@JvmStatic @Synchronized fun deleteCachedFiles(context: Context) {
getFileCacheDir(context).deleteRecursively()
getFileCacheDir(context)?.deleteRecursively()
}

@JvmStatic @Synchronized fun deleteZimFile(path: String) {
Expand Down Expand Up @@ -146,12 +148,12 @@ object FileUtils {
}

@JvmStatic fun getLocalFilePathByUri(
ctx: Context,
context: Context,
uri: Uri
): String? {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT &&
DocumentsContract.isDocumentUri(ctx, uri)
DocumentsContract.isDocumentUri(context, uri)
) {
if ("com.android.externalstorage.documents" == uri.authority) {
val documentId = DocumentsContract.getDocumentId(uri)
Expand All @@ -160,38 +162,49 @@ object FileUtils {
if (documentId[0] == "primary") {
return "${Environment.getExternalStorageDirectory()}/${documentId[1]}"
}
} else if ("com.android.providers.downloads.documents" == uri.authority
)
return contentQuery(
ctx,
ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"),
try {
DocumentsContract.getDocumentId(uri).toLong()
} catch (ignore: NumberFormatException) {
0L
}
)
)
} else if ("com.android.providers.downloads.documents" == uri.authority)
return try {
documentProviderContentQuery(context, uri)
} catch (ignore: IllegalArgumentException) {
null
}
} else if ("content".equals(uri.scheme!!, ignoreCase = true)) {
return contentQuery(ctx, uri)
return contentQuery(context, uri)
} else if ("file".equals(uri.scheme!!, ignoreCase = true)) {
return uri.path
}
return null
}

@TargetApi(VERSION_CODES.KITKAT)
private fun documentProviderContentQuery(context: Context, uri: Uri) =
contentQuery(
context,
ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"),
try {
DocumentsContract.getDocumentId(uri).toLong()
} catch (ignore: NumberFormatException) {
0L
}
)
)

private fun contentQuery(
context: Context,
uri: Uri
): String? {
val columnName = "_data"
return context.contentResolver.query(uri, arrayOf(columnName), null, null, null)
?.use {
if (it.moveToFirst() && it.getColumnIndex(columnName) != -1) {
it[columnName]
} else null
}
return try {
context.contentResolver.query(uri, arrayOf(columnName), null, null, null)
?.use {
if (it.moveToFirst() && it.getColumnIndex(columnName) != -1) {
it[columnName]
} else null
}
} catch (ignore: SecurityException) {
null
}
}

@JvmStatic fun readLocalesFromAssets(context: Context) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import android.webkit.MimeTypeMap
import androidx.core.net.toUri
import io.reactivex.Single
import io.reactivex.schedulers.Schedulers
import org.kiwix.kiwixlib.JNIKiwixException
import org.kiwix.kiwixlib.JNIKiwixInt
import org.kiwix.kiwixlib.JNIKiwixReader
import org.kiwix.kiwixlib.JNIKiwixString
Expand All @@ -51,11 +52,15 @@ class ZimFileReader(
private val sharedPreferenceUtil: SharedPreferenceUtil
) {
interface Factory {
fun create(file: File): ZimFileReader
fun create(file: File): ZimFileReader?

class Impl @Inject constructor(val sharedPreferenceUtil: SharedPreferenceUtil) : Factory {
override fun create(file: File) =
ZimFileReader(file, sharedPreferenceUtil = sharedPreferenceUtil)
try {
ZimFileReader(file, sharedPreferenceUtil = sharedPreferenceUtil)
} catch (ignore: JNIKiwixException) {
null
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ import javax.inject.Singleton
@Singleton
class ZimReaderContainer @Inject constructor(
private val zimFileReaderFactory: ZimFileReader.Factory,
private val jniKiwixSearcher: JNIKiwixSearcher
private val jniKiwixSearcher: JNIKiwixSearcher?
) {
private val listOfAddedReaderIds = mutableListOf<String>()
var zimFileReader: ZimFileReader? = null
set(value) {
field = value
if (value != null && !listOfAddedReaderIds.contains(value.id)) {
listOfAddedReaderIds.add(value.id)
jniKiwixSearcher.addKiwixReader(value.jniKiwixReader)
jniKiwixSearcher?.addKiwixReader(value.jniKiwixReader)
}
}

Expand All @@ -60,10 +60,10 @@ class ZimReaderContainer @Inject constructor(

fun getRandomArticleUrl() = zimFileReader?.getRandomArticleUrl()
fun search(query: String, count: Int) {
jniKiwixSearcher.search(query, count)
jniKiwixSearcher?.search(query, count)
}

fun getNextResult() = jniKiwixSearcher.nextResult
fun getNextResult() = jniKiwixSearcher?.nextResult
fun isRedirect(url: String): Boolean = zimFileReader?.isRedirect(url) == true
fun getRedirect(url: String): String = zimFileReader?.getRedirect(url) ?: ""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.kiwix.kiwixmobile.zim_manager.fileselect_view

import io.reactivex.Flowable
import io.reactivex.functions.BiFunction
import io.reactivex.schedulers.Schedulers
import org.kiwix.kiwixmobile.database.newdb.dao.FetchDownloadDao
Expand All @@ -16,10 +17,10 @@ class StorageObserver @Inject constructor(
private val zimReaderFactory: ZimFileReader.Factory
) {

val booksOnFileSystem
val booksOnFileSystem: Flowable<List<BookOnDisk>>
get() = scanFiles()
.withLatestFrom(downloadDao.downloads(), BiFunction(::toFilesThatAreNotDownloading))
.map { it.map(::convertToBookOnDisk) }
.map { it.mapNotNull(::convertToBookOnDisk) }

private fun scanFiles() = fileSearch.scan().subscribeOn(Schedulers.io())

Expand All @@ -29,5 +30,6 @@ class StorageObserver @Inject constructor(
private fun fileHasNoMatchingDownload(downloads: List<DownloadModel>, file: File) =
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

0 comments on commit 06dee58

Please sign in to comment.