Skip to content

Commit 6d6f35b

Browse files
committed
small fixes
2 parents 6708ea4 + 8e441ff commit 6d6f35b

File tree

14 files changed

+81
-33
lines changed

14 files changed

+81
-33
lines changed

android/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
55
package="org.coolreader"
66
android:installLocation="auto"
7-
android:versionName="3.2.32-1" android:versionCode="32320">
7+
android:versionName="3.2.36-1" android:versionCode="32360">
88
<supports-screens
99
android:xlargeScreens="true"
1010
android:largeScreens="true"

android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
multiDexEnabled true
1111
// When new version released, version code must be incremented at least by 8
1212
// for compatibility with ABI versioning of split apk (see below).
13-
versionCode 32320
14-
versionName "3.2.32-1"
13+
versionCode 32360
14+
versionName "3.2.36-1"
1515
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1616
externalNativeBuild {
1717
cmake {

android/jni/cr3engine.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <jni.h>
55
#include <time.h>
66
#include <android/log.h>
7+
#include <android/api-level.h>
78

89

910
#include <stdio.h>
@@ -825,8 +826,9 @@ JNIEXPORT jboolean JNICALL Java_org_coolreader_crengine_Engine_checkFontLanguage
825826
* Signature: (Ljava/io/File;)[Ljava/io/File;
826827
*/
827828
JNIEXPORT jobjectArray JNICALL Java_org_coolreader_crengine_Engine_listFilesInternal
828-
(JNIEnv *env, jclass, jobject jdir)
829+
(JNIEnv *penv, jclass, jobject jdir)
829830
{
831+
CRJNIEnv env(penv);
830832
if (NULL == jdir)
831833
return NULL;
832834
jclass pjcFile = env->FindClass("java/io/File");
@@ -839,10 +841,9 @@ JNIEXPORT jobjectArray JNICALL Java_org_coolreader_crengine_Engine_listFilesInte
839841
if (NULL == pjmFile_Ctor)
840842
return NULL;
841843
jstring jpathname = (jstring)env->CallObjectMethod(jdir, pjmFile_GetAbsolutePath);
842-
jboolean iscopy;
843-
const char * s = env->GetStringUTFChars(jpathname, &iscopy);
844-
lString16 path = (CRJNIEnv::sdk_int >= ANDROID_SDK_M) ? Utf8ToUnicode(s) : Wtf8ToUnicode(s);
845-
env->ReleaseStringUTFChars(jpathname, s);
844+
if (NULL == jpathname)
845+
return NULL;
846+
lString16 path = env.fromJavaString(jpathname);
846847
jobjectArray jarray = NULL;
847848
LVContainerRef dir = LVOpenDirectory(path);
848849
if ( !dir.isNull() ) {
@@ -852,13 +853,22 @@ JNIEXPORT jobjectArray JNICALL Java_org_coolreader_crengine_Engine_listFilesInte
852853
if (NULL != jarray) {
853854
for (int i = 0; i < dir->GetObjectCount(); i++) {
854855
const LVContainerItemInfo *item = dir->GetObjectInfo(i);
855-
lString16 fileName = path + "/" + item->GetName();
856-
jstring jfilename = env->NewStringUTF(
857-
(CRJNIEnv::sdk_int >= ANDROID_SDK_M) ? UnicodeToUtf8(fileName).c_str()
858-
: UnicodeToWtf8(fileName).c_str());
859-
jobject jfile = env->NewObject(pjcFile, pjmFile_Ctor, jfilename);
860-
if (NULL != jfile)
861-
env->SetObjectArrayElement(jarray, i, jfile);
856+
if (item && item->GetName()) {
857+
lString16 fileName = path + "/" + item->GetName();
858+
jstring jfilename = env.toJavaString(fileName);
859+
if (NULL != jfilename) {
860+
env->ExceptionClear();
861+
jobject jfile = env->NewObject(pjcFile, pjmFile_Ctor, jfilename);
862+
if (env->ExceptionCheck() == JNI_TRUE)
863+
env->ExceptionClear();
864+
else {
865+
if (NULL != jfile)
866+
env->SetObjectArrayElement(jarray, i, jfile);
867+
}
868+
env->DeleteLocalRef(jfile);
869+
env->DeleteLocalRef(jfilename);
870+
}
871+
}
862872
}
863873
}
864874
}

android/jni/cr3java.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "../../crengine/include/crlog.h"
33

44
#include <dlfcn.h>
5+
#include <android/api-level.h>
56

67
uint8_t CRJNIEnv::sdk_int = 0;
78

@@ -12,7 +13,7 @@ lString16 CRJNIEnv::fromJavaString( jstring str )
1213
jboolean iscopy;
1314
const char * s = env->GetStringUTFChars(str, &iscopy);
1415
lString16 res;
15-
if (CRJNIEnv::sdk_int >= ANDROID_SDK_M)
16+
if (CRJNIEnv::sdk_int >= __ANDROID_API_M__)
1617
res = Utf8ToUnicode(s);
1718
else
1819
res = Wtf8ToUnicode(s);
@@ -22,7 +23,7 @@ lString16 CRJNIEnv::fromJavaString( jstring str )
2223

2324
jstring CRJNIEnv::toJavaString( const lString16 & str )
2425
{
25-
if (CRJNIEnv::sdk_int >= ANDROID_SDK_M)
26+
if (CRJNIEnv::sdk_int >= __ANDROID_API_M__)
2627
return env->NewStringUTF(UnicodeToUtf8(str).c_str());
2728
// To support 4-byte UTF-8 sequence on Android older that 6.0 (API 23),
2829
// we encode characters with codes >= 0x10000 to WTF-8.

android/jni/cr3java.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
#include "../../crengine/include/props.h"
2121
#include "../../crengine/include/lvtinydom.h"
2222

23-
// M is for Marshmallow!
24-
#define ANDROID_SDK_M 23
25-
2623
//====================================================================
2724
// libjnigraphics replacement for pre-2.2 SDKs
2825
enum AndroidBitmapFormat {

android/src/org/coolreader/CoolReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2433,7 +2433,7 @@ public void run() {
24332433
@Override
24342434
public void run() {
24352435
getDB().removeOPDSCatalog(item.id);
2436-
directoryUpdated(Services.getScanner().createRecentRoot());
2436+
directoryUpdated(Services.getScanner().createOPDSRoot());
24372437
}
24382438
});
24392439
}

android/src/org/coolreader/crengine/FileBrowser.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,6 @@ public void onDownloadEnd(String type, String url, File file) {
12671267
selector.notifyScanner(file.getAbsolutePath());
12681268
}
12691269
mEngine.hideProgress();
1270-
//mActivity.showToast("Download is finished");
12711270
//fileOrDir.parent.pathname // @opds:http://89.179.127.112/opds/search/books/u/0/
12721271
FileInfo fi = new FileInfo(file);
12731272
boolean isArch = isArchive(file);
@@ -1276,7 +1275,9 @@ public void onDownloadEnd(String type, String url, File file) {
12761275
dir = downloadDir;
12771276
String sPath = file.getAbsolutePath();
12781277
String sPathZ = sPath;
1279-
if ((isArch)&&(!sPathZ.toLowerCase().endsWith(".zip"))) {
1278+
log.d("onDownloadEnd: sPath = " + sPath);
1279+
if ((isArch)&&(!sPathZ.toLowerCase().endsWith(".zip"))
1280+
&&(!sPathZ.toLowerCase().endsWith(".epub"))) {
12801281
int i = 0;
12811282
sPathZ = sPath + ".zip";
12821283
File fileZ = new File(sPathZ);
@@ -1290,7 +1291,10 @@ public void onDownloadEnd(String type, String url, File file) {
12901291
file.renameTo(fileZ);
12911292
}
12921293
mScanner.listDirectory(dir);
1293-
final FileInfo item = dir.findItemByPathName(sPathZ);
1294+
FileInfo item1 = dir.findItemByPathName(sPathZ);
1295+
if (item1 == null) item1 = new FileInfo(sPathZ);
1296+
final FileInfo item = item1;
1297+
log.d("onDownloadEnd: sPathZ = " + sPathZ);
12941298
BackgroundThread.ensureGUI();
12951299
item.opdsLink = url;
12961300
fileOrDir.pathnameR = item.pathname;

android/src/org/coolreader/crengine/FileInfo.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ public FileInfo( String pathName )
332332
filename = itemf.getName();
333333
path = itemf.getPath();
334334
format = DocumentFormat.byExtension(name);
335-
//size = (int)entry.getSize();//plotn - guess this is same as compressed...
335+
if (format == null) format = DocumentFormat.NONE;
336+
//size = (int)entry.getSize();//plotn - guess this is same as compressed...
336337
arcsize = (int) entry.getCompressedSize();
337338
createTime = entry.getTime();
338339
break;
@@ -363,6 +364,7 @@ private void fromFile( File f )
363364
path = f.getParent();
364365
pathname = f.getAbsolutePath();
365366
format = fmt;
367+
if (format == null) format = DocumentFormat.NONE;
366368
createTime = f.lastModified();
367369
size = (int)f.length();
368370
} else {

android/src/org/coolreader/crengine/OPDSUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ protected PasswordAuthentication getPasswordAuthentication() {
844844
L.i("opds: "+connection.getResponseMessage());
845845
if (EXTENDED_LOG) L.d("Response: " + response);
846846
if ( response!=200 ) {
847-
onError("Error " + response + ": " + connection.getResponseMessage());
847+
onError(url+" - Error " + response + ": " + connection.getResponseMessage());
848848
return;
849849
}
850850

android/src/org/coolreader/crengine/ReaderView.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,9 +2771,9 @@ public void run() {
27712771
break;
27722772
case DCMD_TOGGLE_DAY_NIGHT_MODE:
27732773
toggleDayNightMode();
2774-
mActivity.geoLastData.lastStation =mActivity.geoLastData.tempStation;
2775-
mActivity.geoLastData.lastStop =mActivity.geoLastData.tempStop;
2776-
mActivity.geoLastData.doSignal(false,false);
2774+
// mActivity.geoLastData.lastStation =mActivity.geoLastData.tempStation;
2775+
// mActivity.geoLastData.lastStop =mActivity.geoLastData.tempStop;
2776+
// mActivity.geoLastData.doSignal(false,false);
27772777
break;
27782778
case DCMD_TOGGLE_DICT_ONCE:
27792779
log.i("Next dictionary will be the 2nd for one time");

0 commit comments

Comments
 (0)