mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
book serialization is now usable
This commit is contained in:
parent
ff3ea90821
commit
59a7c6b697
8 changed files with 60 additions and 23 deletions
|
@ -243,7 +243,7 @@ public class BookInfoActivity extends Activity {
|
|||
setupInfoPair(R.id.book_authors, "authors", buffer, authors.size());
|
||||
|
||||
final SeriesInfo series = book.getSeriesInfo();
|
||||
setupInfoPair(R.id.book_series, "series", series == null ? null : series.Name);
|
||||
setupInfoPair(R.id.book_series, "series", series == null ? null : series.Title);
|
||||
String seriesIndexString = null;
|
||||
if (series != null && series.Index != null) {
|
||||
seriesIndexString = series.Index.toString();
|
||||
|
|
|
@ -496,10 +496,10 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
} else {
|
||||
long seriesId;
|
||||
try {
|
||||
myGetSeriesIdStatement.bindString(1, seriesInfo.Name);
|
||||
myGetSeriesIdStatement.bindString(1, seriesInfo.Title);
|
||||
seriesId = myGetSeriesIdStatement.simpleQueryForLong();
|
||||
} catch (SQLException e) {
|
||||
myInsertSeriesStatement.bindString(1, seriesInfo.Name);
|
||||
myInsertSeriesStatement.bindString(1, seriesInfo.Title);
|
||||
seriesId = myInsertSeriesStatement.executeInsert();
|
||||
}
|
||||
myInsertBookSeriesStatement.bindLong(1, bookId);
|
||||
|
@ -516,7 +516,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
final Cursor cursor = myDatabase.rawQuery("SELECT Series.name,BookSeries.book_index FROM BookSeries INNER JOIN Series ON Series.series_id = BookSeries.series_id WHERE BookSeries.book_id = ?", new String[] { "" + bookId });
|
||||
SeriesInfo info = null;
|
||||
if (cursor.moveToNext()) {
|
||||
info = new SeriesInfo(cursor.getString(0), SeriesInfo.createIndex(cursor.getString(1)));
|
||||
info = SeriesInfo.createSeriesInfo(cursor.getString(0), cursor.getString(1));
|
||||
}
|
||||
cursor.close();
|
||||
return info;
|
||||
|
|
|
@ -284,8 +284,8 @@ public class Book {
|
|||
return mySeriesInfo;
|
||||
}
|
||||
|
||||
void setSeriesInfoWithNoCheck(String name, BigDecimal index) {
|
||||
mySeriesInfo = new SeriesInfo(name, index);
|
||||
void setSeriesInfoWithNoCheck(String name, String index) {
|
||||
mySeriesInfo = SeriesInfo.createSeriesInfo(name, index);
|
||||
}
|
||||
|
||||
public void setSeriesInfo(String name, String index) {
|
||||
|
@ -301,7 +301,7 @@ public class Book {
|
|||
} else if (name == null) {
|
||||
mySeriesInfo = null;
|
||||
myIsSaved = false;
|
||||
} else if (!name.equals(mySeriesInfo.Name) || mySeriesInfo.Index != index) {
|
||||
} else if (!name.equals(mySeriesInfo.Title) || mySeriesInfo.Index != index) {
|
||||
mySeriesInfo = new SeriesInfo(name, index);
|
||||
myIsSaved = false;
|
||||
}
|
||||
|
@ -382,7 +382,7 @@ public class Book {
|
|||
if (myTitle != null && ZLMiscUtil.matchesIgnoreCase(myTitle, pattern)) {
|
||||
return true;
|
||||
}
|
||||
if (mySeriesInfo != null && ZLMiscUtil.matchesIgnoreCase(mySeriesInfo.Name, pattern)) {
|
||||
if (mySeriesInfo != null && ZLMiscUtil.matchesIgnoreCase(mySeriesInfo.Title, pattern)) {
|
||||
return true;
|
||||
}
|
||||
if (myAuthors != null) {
|
||||
|
|
|
@ -34,7 +34,8 @@ public abstract class BookSerializerUtil {
|
|||
final StringBuilder buffer = new StringBuilder();
|
||||
appendTagWithAttributes(
|
||||
buffer, "entry", false,
|
||||
"xmlns:dc", XMLNamespaces.DublinCore
|
||||
"xmlns:dc", XMLNamespaces.DublinCore,
|
||||
"xmlns:calibre", XMLNamespaces.CalibreMetadata
|
||||
);
|
||||
|
||||
appendTagWithContent(buffer, "id", String.valueOf(book.getId()));
|
||||
|
@ -57,7 +58,13 @@ public abstract class BookSerializerUtil {
|
|||
);
|
||||
}
|
||||
|
||||
// TODO: serialize series info
|
||||
final SeriesInfo seriesInfo = book.getSeriesInfo();
|
||||
if (seriesInfo != null) {
|
||||
appendTagWithContent(buffer, "calibre:series", seriesInfo.Title);
|
||||
if (seriesInfo.Index != null) {
|
||||
appendTagWithContent(buffer, "calibre:series_index", String.valueOf(seriesInfo.Index));
|
||||
}
|
||||
}
|
||||
// TODO: serialize description (?)
|
||||
// TODO: serialize cover (?)
|
||||
|
||||
|
@ -131,6 +138,8 @@ public abstract class BookSerializerUtil {
|
|||
READ_AUTHOR,
|
||||
READ_AUTHOR_URI,
|
||||
READ_AUTHOR_NAME,
|
||||
READ_SERIES_TITLE,
|
||||
READ_SERIES_INDEX,
|
||||
}
|
||||
|
||||
private State myState = State.READ_NOTHING;
|
||||
|
@ -141,8 +150,11 @@ public abstract class BookSerializerUtil {
|
|||
private StringBuilder myLanguage = new StringBuilder();
|
||||
private StringBuilder myEncoding = new StringBuilder();
|
||||
private ArrayList<Author> myAuthors = new ArrayList<Author>();
|
||||
private ArrayList<Tag> myTags = new ArrayList<Tag>();
|
||||
private StringBuilder myAuthorSortKey = new StringBuilder();
|
||||
private StringBuilder myAuthorName = new StringBuilder();
|
||||
private StringBuilder mySeriesTitle = new StringBuilder();
|
||||
private StringBuilder mySeriesIndex = new StringBuilder();
|
||||
|
||||
private Book myBook;
|
||||
|
||||
|
@ -167,7 +179,10 @@ public abstract class BookSerializerUtil {
|
|||
clear(myTitle);
|
||||
clear(myLanguage);
|
||||
clear(myEncoding);
|
||||
clear(mySeriesTitle);
|
||||
clear(mySeriesIndex);
|
||||
myAuthors.clear();
|
||||
myTags.clear();
|
||||
|
||||
myState = State.READ_NOTHING;
|
||||
}
|
||||
|
@ -187,8 +202,10 @@ public abstract class BookSerializerUtil {
|
|||
for (Author author : myAuthors) {
|
||||
myBook.addAuthorWithNoCheck(author);
|
||||
}
|
||||
// TODO: add tags
|
||||
// TODO: add series info
|
||||
for (Tag tag : myTags) {
|
||||
myBook.addTagWithNoCheck(tag);
|
||||
}
|
||||
myBook.setSeriesInfoWithNoCheck(string(mySeriesTitle), string(mySeriesIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -214,7 +231,14 @@ public abstract class BookSerializerUtil {
|
|||
clear(myAuthorName);
|
||||
clear(myAuthorSortKey);
|
||||
} else if ("category".equals(tag)) {
|
||||
// TODO: implement
|
||||
final String term = attributes.getValue("term");
|
||||
if (term != null) {
|
||||
myTags.add(Tag.getTag(term.split("/")));
|
||||
}
|
||||
} else if ("calibre:series".equals(tag)) {
|
||||
myState = State.READ_SERIES_TITLE;
|
||||
} else if ("calibre:series_index".equals(tag)) {
|
||||
myState = State.READ_SERIES_INDEX;
|
||||
} else if ("link".equals(tag)) {
|
||||
// TODO: use "rel" attribute
|
||||
myUrl = attributes.getValue("href");
|
||||
|
@ -288,6 +312,12 @@ public abstract class BookSerializerUtil {
|
|||
case READ_AUTHOR_NAME:
|
||||
myAuthorName.append(ch, start, length);
|
||||
break;
|
||||
case READ_SERIES_TITLE:
|
||||
mySeriesTitle.append(ch, start, length);
|
||||
break;
|
||||
case READ_SERIES_INDEX:
|
||||
mySeriesIndex.append(ch, start, length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public abstract class BooksDatabase {
|
|||
book.addTagWithNoCheck(tag);
|
||||
}
|
||||
protected void setSeriesInfo(Book book, String series, String index) {
|
||||
book.setSeriesInfoWithNoCheck(series, SeriesInfo.createIndex(index));
|
||||
book.setSeriesInfoWithNoCheck(series, index);
|
||||
}
|
||||
|
||||
protected abstract void executeAsATransaction(Runnable actions);
|
||||
|
|
|
@ -238,11 +238,11 @@ public final class Library {
|
|||
return;
|
||||
}
|
||||
|
||||
final String xml = BookSerializerUtil.serialize(book);
|
||||
BookSerializerUtil.deserialize(xml);
|
||||
|
||||
myBooks.put(book.File, book);
|
||||
|
||||
final String xml = BookSerializerUtil.serialize(book);
|
||||
book = BookSerializerUtil.deserialize(xml);
|
||||
|
||||
List<Author> authors = book.authors();
|
||||
if (authors.isEmpty()) {
|
||||
authors = (List<Author>)myNullList;
|
||||
|
@ -253,7 +253,7 @@ public final class Library {
|
|||
if (seriesInfo == null) {
|
||||
authorTree.getBookSubTree(book, false);
|
||||
} else {
|
||||
authorTree.getSeriesSubTree(seriesInfo.Name).getBookInSeriesSubTree(book);
|
||||
authorTree.getSeriesSubTree(seriesInfo.Title).getBookInSeriesSubTree(book);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -266,7 +266,7 @@ public final class Library {
|
|||
ROOT_BY_SERIES
|
||||
);
|
||||
}
|
||||
seriesRoot.getSeriesSubTree(seriesInfo.Name).getBookInSeriesSubTree(book);
|
||||
seriesRoot.getSeriesSubTree(seriesInfo.Title).getBookInSeriesSubTree(book);
|
||||
}
|
||||
|
||||
if (myDoGroupTitlesByFirstLetter) {
|
||||
|
|
|
@ -22,6 +22,13 @@ package org.geometerplus.fbreader.library;
|
|||
import java.math.BigDecimal;
|
||||
|
||||
public final class SeriesInfo {
|
||||
public static SeriesInfo createSeriesInfo(String title, String index) {
|
||||
if (title == null) {
|
||||
return null;
|
||||
}
|
||||
return new SeriesInfo(title, createIndex(index));
|
||||
}
|
||||
|
||||
public static BigDecimal createIndex(String index) {
|
||||
try {
|
||||
return index != null ? new BigDecimal(index).stripTrailingZeros() : null;
|
||||
|
@ -30,11 +37,11 @@ public final class SeriesInfo {
|
|||
}
|
||||
}
|
||||
|
||||
public final String Name;
|
||||
public final String Title;
|
||||
public final BigDecimal Index;
|
||||
|
||||
public SeriesInfo(String name, BigDecimal index) {
|
||||
Name = name;
|
||||
public SeriesInfo(String title, BigDecimal index) {
|
||||
Title = title;
|
||||
Index = index;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ public final class SeriesTree extends LibraryTree {
|
|||
return false;
|
||||
}
|
||||
final SeriesInfo info = book.getSeriesInfo();
|
||||
return info != null && Series.equals(info.Name);
|
||||
return info != null && Series.equals(info.Title);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue