mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +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"?>
|
<?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"/>
|
<uses-sdk android:minSdkVersion="4" android:maxSdkVersion="10"/>
|
||||||
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true" />
|
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true" />
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<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
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int returnCode, Intent intent) {
|
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 String path = intent.getStringExtra(BookInfoActivity.CURRENT_BOOK_PATH_KEY);
|
||||||
final Book book = Book.getByFile(ZLFile.createFileByPath(path));
|
final Book book = Book.getByFile(ZLFile.createFileByPath(path));
|
||||||
myLibrary.refreshBookInfo(book);
|
myLibrary.refreshBookInfo(book);
|
||||||
|
|
|
@ -50,12 +50,13 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void executeAsATransaction(Runnable actions) {
|
protected void executeAsATransaction(Runnable actions) {
|
||||||
myDatabase.beginTransactionNonExclusive();
|
myDatabase.execSQL("BEGIN IMMEDIATE");
|
||||||
try {
|
try {
|
||||||
actions.run();
|
actions.run();
|
||||||
myDatabase.setTransactionSuccessful();
|
} catch (Throwable t) {
|
||||||
|
myDatabase.execSQL("ROLLBACK");
|
||||||
} finally {
|
} 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;
|
private int mySize = 1;
|
||||||
public final T Parent;
|
public final T Parent;
|
||||||
public final int Level;
|
public final int Level;
|
||||||
private ArrayList<T> mySubTrees;
|
private volatile List<T> mySubTrees;
|
||||||
|
|
||||||
protected ZLTree() {
|
protected ZLTree() {
|
||||||
this(null);
|
this(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ZLTree(T parent) {
|
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) {
|
protected ZLTree(T parent, int position) {
|
||||||
if (parent != null && (position < 0 || position > 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.subTrees().size() + "]");
|
throw new IndexOutOfBoundsException("`position` value equals " + position + " but must be in range [0; " + parent.mySubTrees.size() + "]");
|
||||||
}
|
}
|
||||||
Parent = parent;
|
Parent = parent;
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
|
@ -57,21 +57,24 @@ public abstract class ZLTree<T extends ZLTree<T>> implements Iterable<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final List<T> subTrees() {
|
public final List<T> subTrees() {
|
||||||
|
synchronized (mySubTrees) {
|
||||||
if (mySubTrees == null) {
|
if (mySubTrees == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
return mySubTrees;
|
return new ArrayList(mySubTrees);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final T getTreeByParagraphNumber(int index) {
|
public final T getTreeByParagraphNumber(int index) {
|
||||||
if ((index < 0) || (index >= mySize)) {
|
if (index < 0 || index >= mySize) {
|
||||||
// TODO: throw exception?
|
// TODO: throw an exception?
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
return (T)this;
|
return (T)this;
|
||||||
}
|
}
|
||||||
--index;
|
--index;
|
||||||
|
synchronized (mySubTrees) {
|
||||||
for (T subtree : mySubTrees) {
|
for (T subtree : mySubTrees) {
|
||||||
if (subtree.mySize <= index) {
|
if (subtree.mySize <= index) {
|
||||||
index -= subtree.mySize;
|
index -= subtree.mySize;
|
||||||
|
@ -79,14 +82,18 @@ public abstract class ZLTree<T extends ZLTree<T>> implements Iterable<T> {
|
||||||
return (T)subtree.getTreeByParagraphNumber(index);
|
return (T)subtree.getTreeByParagraphNumber(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
throw new RuntimeException("That's impossible!!!");
|
throw new RuntimeException("That's impossible!!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addSubTree(T subtree, int position) {
|
private void addSubTree(T subtree, int position) {
|
||||||
|
synchronized (this) {
|
||||||
if (mySubTrees == null) {
|
if (mySubTrees == null) {
|
||||||
mySubTrees = new ArrayList<T>();
|
mySubTrees = Collections.synchronizedList(new ArrayList<T>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
final int subTreeSize = subtree.getSize();
|
final int subTreeSize = subtree.getSize();
|
||||||
|
synchronized (mySubTrees) {
|
||||||
final int thisSubTreesSize = mySubTrees.size();
|
final int thisSubTreesSize = mySubTrees.size();
|
||||||
while (position < thisSubTreesSize) {
|
while (position < thisSubTreesSize) {
|
||||||
subtree = mySubTrees.set(position++, subtree);
|
subtree = mySubTrees.set(position++, subtree);
|
||||||
|
@ -96,15 +103,18 @@ public abstract class ZLTree<T extends ZLTree<T>> implements Iterable<T> {
|
||||||
parent.mySize += subTreeSize;
|
parent.mySize += subTreeSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void removeSelf() {
|
public void removeSelf() {
|
||||||
final int subTreeSize = getSize();
|
final int subTreeSize = getSize();
|
||||||
ZLTree<?> parent = Parent;
|
ZLTree<?> parent = Parent;
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
parent.mySubTrees.remove(this);
|
parent.mySubTrees.remove(this);
|
||||||
|
synchronized (parent) {
|
||||||
if (parent.mySubTrees.isEmpty()) {
|
if (parent.mySubTrees.isEmpty()) {
|
||||||
parent.mySubTrees = null;
|
parent.mySubTrees = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for (; parent != null; parent = parent.Parent) {
|
for (; parent != null; parent = parent.Parent) {
|
||||||
parent.mySize -= subTreeSize;
|
parent.mySize -= subTreeSize;
|
||||||
}
|
}
|
||||||
|
@ -113,7 +123,9 @@ public abstract class ZLTree<T extends ZLTree<T>> implements Iterable<T> {
|
||||||
|
|
||||||
public final void clear() {
|
public final void clear() {
|
||||||
final int subTreesSize = mySize - 1;
|
final int subTreesSize = mySize - 1;
|
||||||
|
synchronized (this) {
|
||||||
mySubTrees = null;
|
mySubTrees = null;
|
||||||
|
}
|
||||||
mySize = 1;
|
mySize = 1;
|
||||||
if (subTreesSize > 0) {
|
if (subTreesSize > 0) {
|
||||||
for (ZLTree<?> parent = Parent; parent != null; parent = parent.Parent) {
|
for (ZLTree<?> parent = Parent; parent != null; parent = parent.Parent) {
|
||||||
|
@ -157,12 +169,14 @@ public abstract class ZLTree<T extends ZLTree<T>> implements Iterable<T> {
|
||||||
while (!myIndexStack.isEmpty()) {
|
while (!myIndexStack.isEmpty()) {
|
||||||
final int index = myIndexStack.removeLast() + 1;
|
final int index = myIndexStack.removeLast() + 1;
|
||||||
parent = parent.Parent;
|
parent = parent.Parent;
|
||||||
|
synchronized (parent.mySubTrees) {
|
||||||
if (parent.mySubTrees.size() > index) {
|
if (parent.mySubTrees.size() > index) {
|
||||||
myCurrentElement = parent.mySubTrees.get(index);
|
myCurrentElement = parent.mySubTrees.get(index);
|
||||||
myIndexStack.add(index);
|
myIndexStack.add(index);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (myIndexStack.isEmpty()) {
|
if (myIndexStack.isEmpty()) {
|
||||||
myCurrentElement = null;
|
myCurrentElement = null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue