1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 02:39:23 +02:00

fixed hyphenations after book info editing; fixed possible NPE in library

This commit is contained in:
Nikolay Pultsin 2011-01-03 13:41:26 +00:00
parent d163878097
commit aac0fc50d1
9 changed files with 53 additions and 20 deletions

View file

@ -113,7 +113,7 @@ public class BookInfoActivity extends Activity {
}); });
setupButton(R.id.book_info_button_reload, "reloadInfo", new View.OnClickListener() { setupButton(R.id.book_info_button_reload, "reloadInfo", new View.OnClickListener() {
public void onClick(View view) { public void onClick(View view) {
book.reloadInfo(); book.reloadInfoFromFile();
setupBookInfo(book); setupBookInfo(book);
} }
}); });

View file

@ -33,9 +33,12 @@ import org.geometerplus.zlibrary.core.application.ZLApplication;
import org.geometerplus.zlibrary.core.filesystem.ZLFile; import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.zlibrary.core.resources.ZLResource; import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.core.view.ZLView; import org.geometerplus.zlibrary.core.view.ZLView;
import org.geometerplus.zlibrary.text.view.ZLTextFixedPosition; import org.geometerplus.zlibrary.text.view.ZLTextFixedPosition;
import org.geometerplus.zlibrary.text.view.ZLTextPosition; import org.geometerplus.zlibrary.text.view.ZLTextPosition;
import org.geometerplus.zlibrary.text.view.ZLTextView; import org.geometerplus.zlibrary.text.view.ZLTextView;
import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator;
import org.geometerplus.zlibrary.ui.android.R; import org.geometerplus.zlibrary.ui.android.R;
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidActivity; import org.geometerplus.zlibrary.ui.android.library.ZLAndroidActivity;
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication; import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication;
@ -43,6 +46,8 @@ import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication;
import org.geometerplus.fbreader.fbreader.ActionCode; import org.geometerplus.fbreader.fbreader.ActionCode;
import org.geometerplus.fbreader.fbreader.FBReaderApp; import org.geometerplus.fbreader.fbreader.FBReaderApp;
import org.geometerplus.fbreader.fbreader.FBView; import org.geometerplus.fbreader.fbreader.FBView;
import org.geometerplus.fbreader.bookmodel.BookModel;
import org.geometerplus.fbreader.library.Book;
import org.geometerplus.android.fbreader.library.KillerCallback; import org.geometerplus.android.fbreader.library.KillerCallback;
@ -228,6 +233,14 @@ public final class FBReader extends ZLAndroidActivity {
case REPAINT_CODE: case REPAINT_CODE:
{ {
final FBReaderApp fbreader = (FBReaderApp)ZLApplication.Instance(); final FBReaderApp fbreader = (FBReaderApp)ZLApplication.Instance();
final BookModel model = fbreader.Model;
if (model != null) {
final Book book = model.Book;
if (book != null) {
book.reloadInfoFromDatabase();
ZLTextHyphenator.Instance().load(book.getLanguage());
}
}
fbreader.clearTextCaches(); fbreader.clearTextCaches();
fbreader.repaintView(); fbreader.repaintView();
break; break;

View file

@ -128,6 +128,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
return new Date(cursor.getLong(index)); return new Date(cursor.getLong(index));
} }
@Override
protected Book loadBook(long bookId) { protected Book loadBook(long bookId) {
Book book = null; Book book = null;
final Cursor cursor = myDatabase.rawQuery("SELECT file_id,title,encoding,language FROM Books WHERE book_id = " + bookId, null); final Cursor cursor = myDatabase.rawQuery("SELECT file_id,title,encoding,language FROM Books WHERE book_id = " + bookId, null);
@ -140,6 +141,17 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
return book; return book;
} }
@Override
protected void reloadBook(Book book) {
final Cursor cursor = myDatabase.rawQuery("SELECT title,encoding,language FROM Books WHERE book_id = " + book.getId(), null);
if (cursor.moveToNext()) {
book.setTitle(cursor.getString(0));
book.setEncoding(cursor.getString(1));
book.setLanguage(cursor.getString(2));
}
cursor.close();
}
protected Book loadBookByFile(long fileId, ZLFile file) { protected Book loadBookByFile(long fileId, ZLFile file) {
if (fileId == -1) { if (fileId == -1) {
return null; return null;

View file

@ -201,28 +201,30 @@ abstract class LibraryBaseActivity extends BaseActivity implements MenuItem.OnMe
} }
protected class OpenTreeRunnable implements Runnable { protected class OpenTreeRunnable implements Runnable {
private final Library myLibrary;
private final Runnable myPostRunnable; private final Runnable myPostRunnable;
public OpenTreeRunnable(String treePath) { public OpenTreeRunnable(Library library, String treePath) {
this(treePath, null); this(library, treePath, null);
} }
public OpenTreeRunnable(String treePath, String parameter) { public OpenTreeRunnable(Library library, String treePath, String parameter) {
this(new StartTreeActivityRunnable(treePath, parameter)); this(library, new StartTreeActivityRunnable(treePath, parameter));
} }
public OpenTreeRunnable(Runnable postRunnable) { public OpenTreeRunnable(Library library, Runnable postRunnable) {
myLibrary = library;
myPostRunnable = postRunnable; myPostRunnable = postRunnable;
} }
public void run() { public void run() {
if (LibraryInstance.hasState(Library.STATE_FULLY_INITIALIZED)) { if (myLibrary.hasState(Library.STATE_FULLY_INITIALIZED)) {
myPostRunnable.run(); myPostRunnable.run();
} else { } else {
UIUtil.runWithMessage(LibraryBaseActivity.this, "loadingBookList", UIUtil.runWithMessage(LibraryBaseActivity.this, "loadingBookList",
new Runnable() { new Runnable() {
public void run() { public void run() {
LibraryInstance.waitForState(Library.STATE_FULLY_INITIALIZED); myLibrary.waitForState(Library.STATE_FULLY_INITIALIZED);
} }
}, },
myPostRunnable); myPostRunnable);

View file

@ -60,7 +60,7 @@ public class LibraryTopLevelActivity extends LibraryBaseActivity {
myItems.add(new TopLevelTree( myItems.add(new TopLevelTree(
myResource.getResource(PATH_FAVORITES), myResource.getResource(PATH_FAVORITES),
R.drawable.ic_list_library_favorites, R.drawable.ic_list_library_favorites,
new OpenTreeRunnable(new StartTreeActivityRunnable(PATH_FAVORITES, null) { new OpenTreeRunnable(LibraryInstance, new StartTreeActivityRunnable(PATH_FAVORITES, null) {
public void run() { public void run() {
if (LibraryInstance.favorites().hasChildren()) { if (LibraryInstance.favorites().hasChildren()) {
super.run(); super.run();
@ -73,17 +73,17 @@ public class LibraryTopLevelActivity extends LibraryBaseActivity {
myItems.add(new TopLevelTree( myItems.add(new TopLevelTree(
myResource.getResource(PATH_RECENT), myResource.getResource(PATH_RECENT),
R.drawable.ic_list_library_recent, R.drawable.ic_list_library_recent,
new OpenTreeRunnable(PATH_RECENT) new OpenTreeRunnable(LibraryInstance, PATH_RECENT)
)); ));
myItems.add(new TopLevelTree( myItems.add(new TopLevelTree(
myResource.getResource(PATH_BY_AUTHOR), myResource.getResource(PATH_BY_AUTHOR),
R.drawable.ic_list_library_authors, R.drawable.ic_list_library_authors,
new OpenTreeRunnable(PATH_BY_AUTHOR) new OpenTreeRunnable(LibraryInstance, PATH_BY_AUTHOR)
)); ));
myItems.add(new TopLevelTree( myItems.add(new TopLevelTree(
myResource.getResource(PATH_BY_TAG), myResource.getResource(PATH_BY_TAG),
R.drawable.ic_list_library_tags, R.drawable.ic_list_library_tags,
new OpenTreeRunnable(PATH_BY_TAG) new OpenTreeRunnable(LibraryInstance, PATH_BY_TAG)
)); ));
myItems.add(new TopLevelTree( myItems.add(new TopLevelTree(
myResource.getResource("fileTree"), myResource.getResource("fileTree"),
@ -123,7 +123,7 @@ public class LibraryTopLevelActivity extends LibraryBaseActivity {
myResource.getResource(PATH_SEARCH_RESULTS), myResource.getResource(PATH_SEARCH_RESULTS),
pattern, pattern,
R.drawable.ic_list_library_books, R.drawable.ic_list_library_books,
new OpenTreeRunnable(PATH_SEARCH_RESULTS, pattern) new OpenTreeRunnable(LibraryInstance, PATH_SEARCH_RESULTS, pattern)
); );
myItems.add(0, mySearchResultsItem); myItems.add(0, mySearchResultsItem);
getListView().invalidateViews(); getListView().invalidateViews();

View file

@ -103,7 +103,7 @@ public class LibraryTreeActivity extends LibraryBaseActivity {
if (tree instanceof BookTree) { if (tree instanceof BookTree) {
showBookInfo(((BookTree)tree).Book); showBookInfo(((BookTree)tree).Book);
} else { } else {
new OpenTreeRunnable(myTreePathString + "\000" + tree.getName()).run(); new OpenTreeRunnable(LibraryInstance, myTreePathString + "\000" + tree.getName()).run();
} }
} }
} }

View file

@ -28,8 +28,6 @@ import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.core.language.ZLLanguageUtil; import org.geometerplus.zlibrary.core.language.ZLLanguageUtil;
import org.geometerplus.zlibrary.core.filesystem.ZLFile; import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator;
import org.geometerplus.fbreader.library.Book; import org.geometerplus.fbreader.library.Book;
import org.geometerplus.android.fbreader.BookInfoActivity; import org.geometerplus.android.fbreader.BookInfoActivity;
@ -108,8 +106,6 @@ public class EditBookInfoActivity extends ZLPreferenceActivity {
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
if (myBook.save()) { myBook.save();
ZLTextHyphenator.Instance().load(myBook.getLanguage());
}
} }
} }

View file

@ -116,12 +116,21 @@ public class Book {
File = file; File = file;
} }
public void reloadInfo() { public void reloadInfoFromFile() {
if (readMetaInfo()) { if (readMetaInfo()) {
save(); save();
} }
} }
public void reloadInfoFromDatabase() {
final BooksDatabase database = BooksDatabase.Instance();
database.reloadBook(this);
myAuthors = database.loadAuthors(myId);
myTags = database.loadTags(myId);
mySeriesInfo = database.loadSeriesInfo(myId);
myIsSaved = true;
}
boolean readMetaInfo() { boolean readMetaInfo() {
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(File); final FormatPlugin plugin = PluginCollection.Instance().getPlugin(File);
if ((plugin == null) || !plugin.readMetaInfo(this)) { if ((plugin == null) || !plugin.readMetaInfo(this)) {

View file

@ -58,6 +58,7 @@ public abstract class BooksDatabase {
// returns map fileId -> book // returns map fileId -> book
protected abstract Map<Long,Book> loadBooks(FileInfoSet infos); protected abstract Map<Long,Book> loadBooks(FileInfoSet infos);
protected abstract Book loadBook(long bookId); protected abstract Book loadBook(long bookId);
protected abstract void reloadBook(Book book);
protected abstract Book loadBookByFile(long fileId, ZLFile file); protected abstract Book loadBookByFile(long fileId, ZLFile file);
protected abstract List<Author> loadAuthors(long bookId); protected abstract List<Author> loadAuthors(long bookId);