diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 09f8bfa3a..29227606d 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,5 +1,5 @@ - + diff --git a/VERSION b/VERSION index e25d8d9f3..0664a8fd2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.5 +1.1.6 diff --git a/src/org/geometerplus/android/fbreader/library/LibraryActivity.java b/src/org/geometerplus/android/fbreader/library/LibraryActivity.java index 80399f630..7e86b40ad 100644 --- a/src/org/geometerplus/android/fbreader/library/LibraryActivity.java +++ b/src/org/geometerplus/android/fbreader/library/LibraryActivity.java @@ -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); diff --git a/src/org/geometerplus/android/fbreader/library/SQLiteBooksDatabase.java b/src/org/geometerplus/android/fbreader/library/SQLiteBooksDatabase.java index fd6107fad..cbb7392bf 100644 --- a/src/org/geometerplus/android/fbreader/library/SQLiteBooksDatabase.java +++ b/src/org/geometerplus/android/fbreader/library/SQLiteBooksDatabase.java @@ -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"); } } diff --git a/src/org/geometerplus/zlibrary/core/tree/ZLTree.java b/src/org/geometerplus/zlibrary/core/tree/ZLTree.java index b3036fe12..677c4356f 100644 --- a/src/org/geometerplus/zlibrary/core/tree/ZLTree.java +++ b/src/org/geometerplus/zlibrary/core/tree/ZLTree.java @@ -25,19 +25,19 @@ public abstract class ZLTree> implements Iterable { private int mySize = 1; public final T Parent; public final int Level; - private ArrayList mySubTrees; + private volatile List 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> implements Iterable { } public final List 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(); + synchronized (this) { + if (mySubTrees == null) { + mySubTrees = Collections.synchronizedList(new ArrayList()); + } } 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> implements Iterable { 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> implements Iterable { 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> implements Iterable { 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()) {