mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
fixed several exceptions
This commit is contained in:
parent
334a3a1871
commit
b924f869ce
5 changed files with 51 additions and 36 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.geometerplus.zlibrary.ui.android" android:versionCode="10105" android:versionName="1.1.5" android:installLocation="auto">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.geometerplus.zlibrary.ui.android" android:versionCode="10106" android:versionName="1.1.6" android:installLocation="auto">
|
||||
<uses-sdk android:minSdkVersion="4" android:maxSdkVersion="10"/>
|
||||
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
1.1.5
|
||||
1.1.6
|
||||
|
|
|
@ -127,7 +127,7 @@ public class LibraryActivity extends BaseActivity implements MenuItem.OnMenuItem
|
|||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int returnCode, Intent intent) {
|
||||
if (requestCode == BOOK_INFO_REQUEST) {
|
||||
if (requestCode == BOOK_INFO_REQUEST && intent != null) {
|
||||
final String path = intent.getStringExtra(BookInfoActivity.CURRENT_BOOK_PATH_KEY);
|
||||
final Book book = Book.getByFile(ZLFile.createFileByPath(path));
|
||||
myLibrary.refreshBookInfo(book);
|
||||
|
|
|
@ -50,12 +50,13 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
}
|
||||
|
||||
protected void executeAsATransaction(Runnable actions) {
|
||||
myDatabase.beginTransactionNonExclusive();
|
||||
myDatabase.execSQL("BEGIN IMMEDIATE");
|
||||
try {
|
||||
actions.run();
|
||||
myDatabase.setTransactionSuccessful();
|
||||
} catch (Throwable t) {
|
||||
myDatabase.execSQL("ROLLBACK");
|
||||
} finally {
|
||||
myDatabase.endTransaction();
|
||||
myDatabase.execSQL("END");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,19 +25,19 @@ public abstract class ZLTree<T extends ZLTree<T>> implements Iterable<T> {
|
|||
private int mySize = 1;
|
||||
public final T Parent;
|
||||
public final int Level;
|
||||
private ArrayList<T> mySubTrees;
|
||||
private volatile List<T> mySubTrees;
|
||||
|
||||
protected ZLTree() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
protected ZLTree(T parent) {
|
||||
this(parent, (parent == null) ? 0 : parent.subTrees().size());
|
||||
this(parent, (parent == null) ? 0 : parent.mySubTrees.size());
|
||||
}
|
||||
|
||||
protected ZLTree(T parent, int position) {
|
||||
if (parent != null && (position < 0 || position > parent.subTrees().size())) {
|
||||
throw new IndexOutOfBoundsException("`position` value equals " + position + " but must be in range [0; " + parent.subTrees().size() + "]");
|
||||
if (parent != null && (position < 0 || position > parent.mySubTrees.size())) {
|
||||
throw new IndexOutOfBoundsException("`position` value equals " + position + " but must be in range [0; " + parent.mySubTrees.size() + "]");
|
||||
}
|
||||
Parent = parent;
|
||||
if (parent != null) {
|
||||
|
@ -57,43 +57,51 @@ public abstract class ZLTree<T extends ZLTree<T>> implements Iterable<T> {
|
|||
}
|
||||
|
||||
public final List<T> subTrees() {
|
||||
if (mySubTrees == null) {
|
||||
return Collections.emptyList();
|
||||
synchronized (mySubTrees) {
|
||||
if (mySubTrees == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return new ArrayList(mySubTrees);
|
||||
}
|
||||
return mySubTrees;
|
||||
}
|
||||
|
||||
public final T getTreeByParagraphNumber(int index) {
|
||||
if ((index < 0) || (index >= mySize)) {
|
||||
// TODO: throw exception?
|
||||
if (index < 0 || index >= mySize) {
|
||||
// TODO: throw an exception?
|
||||
return null;
|
||||
}
|
||||
if (index == 0) {
|
||||
return (T)this;
|
||||
}
|
||||
--index;
|
||||
for (T subtree : mySubTrees) {
|
||||
if (subtree.mySize <= index) {
|
||||
index -= subtree.mySize;
|
||||
} else {
|
||||
return (T)subtree.getTreeByParagraphNumber(index);
|
||||
synchronized (mySubTrees) {
|
||||
for (T subtree : mySubTrees) {
|
||||
if (subtree.mySize <= index) {
|
||||
index -= subtree.mySize;
|
||||
} else {
|
||||
return (T)subtree.getTreeByParagraphNumber(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("That's impossible!!!");
|
||||
}
|
||||
|
||||
private void addSubTree(T subtree, int position) {
|
||||
if (mySubTrees == null) {
|
||||
mySubTrees = new ArrayList<T>();
|
||||
synchronized (this) {
|
||||
if (mySubTrees == null) {
|
||||
mySubTrees = Collections.synchronizedList(new ArrayList<T>());
|
||||
}
|
||||
}
|
||||
final int subTreeSize = subtree.getSize();
|
||||
final int thisSubTreesSize = mySubTrees.size();
|
||||
while (position < thisSubTreesSize) {
|
||||
subtree = mySubTrees.set(position++, subtree);
|
||||
}
|
||||
mySubTrees.add(subtree);
|
||||
for (ZLTree<?> parent = this; parent != null; parent = parent.Parent) {
|
||||
parent.mySize += subTreeSize;
|
||||
synchronized (mySubTrees) {
|
||||
final int thisSubTreesSize = mySubTrees.size();
|
||||
while (position < thisSubTreesSize) {
|
||||
subtree = mySubTrees.set(position++, subtree);
|
||||
}
|
||||
mySubTrees.add(subtree);
|
||||
for (ZLTree<?> parent = this; parent != null; parent = parent.Parent) {
|
||||
parent.mySize += subTreeSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,8 +110,10 @@ public abstract class ZLTree<T extends ZLTree<T>> implements Iterable<T> {
|
|||
ZLTree<?> parent = Parent;
|
||||
if (parent != null) {
|
||||
parent.mySubTrees.remove(this);
|
||||
if (parent.mySubTrees.isEmpty()) {
|
||||
parent.mySubTrees = null;
|
||||
synchronized (parent) {
|
||||
if (parent.mySubTrees.isEmpty()) {
|
||||
parent.mySubTrees = null;
|
||||
}
|
||||
}
|
||||
for (; parent != null; parent = parent.Parent) {
|
||||
parent.mySize -= subTreeSize;
|
||||
|
@ -113,7 +123,9 @@ public abstract class ZLTree<T extends ZLTree<T>> implements Iterable<T> {
|
|||
|
||||
public final void clear() {
|
||||
final int subTreesSize = mySize - 1;
|
||||
mySubTrees = null;
|
||||
synchronized (this) {
|
||||
mySubTrees = null;
|
||||
}
|
||||
mySize = 1;
|
||||
if (subTreesSize > 0) {
|
||||
for (ZLTree<?> parent = Parent; parent != null; parent = parent.Parent) {
|
||||
|
@ -157,10 +169,12 @@ public abstract class ZLTree<T extends ZLTree<T>> implements Iterable<T> {
|
|||
while (!myIndexStack.isEmpty()) {
|
||||
final int index = myIndexStack.removeLast() + 1;
|
||||
parent = parent.Parent;
|
||||
if (parent.mySubTrees.size() > index) {
|
||||
myCurrentElement = parent.mySubTrees.get(index);
|
||||
myIndexStack.add(index);
|
||||
break;
|
||||
synchronized (parent.mySubTrees) {
|
||||
if (parent.mySubTrees.size() > index) {
|
||||
myCurrentElement = parent.mySubTrees.get(index);
|
||||
myIndexStack.add(index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (myIndexStack.isEmpty()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue