From fdcd44597ad28b23f46b5c302fbea261f174e82d Mon Sep 17 00:00:00 2001 From: Nikolay Pultsin Date: Sun, 20 Mar 2011 03:57:55 +0000 Subject: [PATCH] float series book index --- .../android/fbreader/BookInfoActivity.java | 5 ++--- .../android/fbreader/SQLiteBooksDatabase.java | 19 ++++++++++++++++--- .../network/NetworkBookInfoActivity.java | 2 +- .../formats/oeb/OEBMetaInfoReader.java | 6 +++--- .../geometerplus/fbreader/library/Book.java | 6 +++--- .../fbreader/library/BookInSeriesTree.java | 4 ++-- .../fbreader/library/BooksDatabase.java | 2 +- .../fbreader/library/SeriesInfo.java | 4 ++-- .../fbreader/network/NetworkBookItem.java | 4 ++-- .../network/NetworkBookItemComparator.java | 4 ++-- .../litres/LitResBookshelfItem.java | 12 ++++++++---- .../fbreader/network/opds/OPDSEntry.java | 2 +- .../fbreader/network/opds/OPDSXMLReader.java | 2 +- 13 files changed, 44 insertions(+), 28 deletions(-) diff --git a/src/org/geometerplus/android/fbreader/BookInfoActivity.java b/src/org/geometerplus/android/fbreader/BookInfoActivity.java index 3e00616e5..8ecc3df41 100644 --- a/src/org/geometerplus/android/fbreader/BookInfoActivity.java +++ b/src/org/geometerplus/android/fbreader/BookInfoActivity.java @@ -21,8 +21,7 @@ package org.geometerplus.android.fbreader; import java.io.File; import java.text.DateFormat; -import java.util.Date; -import java.util.HashSet; +import java.util.*; import android.app.Activity; import android.content.Intent; @@ -216,7 +215,7 @@ public class BookInfoActivity extends Activity { setupInfoPair(R.id.book_series, "series", (series == null) ? null : series.Name); setupInfoPair(R.id.book_series_index, "indexInSeries", - (series == null || series.Index <= 0) ? null : String.valueOf(series.Index)); + (series == null || series.Index <= 0) ? null : String.format("%.1f", series.Index)); buffer.delete(0, buffer.length()); final HashSet tagNames = new HashSet(); diff --git a/src/org/geometerplus/android/fbreader/SQLiteBooksDatabase.java b/src/org/geometerplus/android/fbreader/SQLiteBooksDatabase.java index 036dc517f..a89da5329 100644 --- a/src/org/geometerplus/android/fbreader/SQLiteBooksDatabase.java +++ b/src/org/geometerplus/android/fbreader/SQLiteBooksDatabase.java @@ -61,7 +61,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase { private void migrate(Context context) { final int version = myDatabase.getVersion(); - final int currentVersion = 14; + final int currentVersion = 15; if (version >= currentVersion) { return; } @@ -98,6 +98,8 @@ public final class SQLiteBooksDatabase extends BooksDatabase { updateTables12(); case 13: updateTables13(); + case 14: + updateTables14(); } myDatabase.setTransactionSuccessful(); myDatabase.endTransaction(); @@ -240,7 +242,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase { if (book != null) { String series = seriesById.get(cursor.getLong(1)); if (series != null) { - setSeriesInfo(book, series, cursor.getLong(2)); + setSeriesInfo(book, series, cursor.getFloat(2)); } } } @@ -461,7 +463,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase { } myInsertBookSeriesStatement.bindLong(1, bookId); myInsertBookSeriesStatement.bindLong(2, seriesId); - myInsertBookSeriesStatement.bindLong(3, seriesInfo.Index); + myInsertBookSeriesStatement.bindDouble(3, seriesInfo.Index); myInsertBookSeriesStatement.execute(); } } @@ -1127,4 +1129,15 @@ public final class SQLiteBooksDatabase extends BooksDatabase { "ALTER TABLE Bookmarks ADD COLUMN visible INTEGER DEFAULT 1" ); } + + private void updateTables14() { + myDatabase.execSQL("ALTER TABLE BookSeries RENAME TO BookSeries_Obsolete"); + myDatabase.execSQL( + "CREATE TABLE BookSeries(" + + "series_id INTEGER NOT NULL REFERENCES Series(series_id)," + + "book_id INTEGER NOT NULL UNIQUE REFERENCES Books(book_id)," + + "book_index REAL)"); + myDatabase.execSQL("INSERT INTO BookSeries (series_id,book_id,book_index) SELECT series_id,book_id,book_index FROM BookSeries_Obsolete"); + myDatabase.execSQL("DROP TABLE BookSeries_Obsolete"); + } } diff --git a/src/org/geometerplus/android/fbreader/network/NetworkBookInfoActivity.java b/src/org/geometerplus/android/fbreader/network/NetworkBookInfoActivity.java index 1727d97d4..1c4a5c539 100644 --- a/src/org/geometerplus/android/fbreader/network/NetworkBookInfoActivity.java +++ b/src/org/geometerplus/android/fbreader/network/NetworkBookInfoActivity.java @@ -186,7 +186,7 @@ public class NetworkBookInfoActivity extends Activity implements NetworkView.Eve findViewById(R.id.network_book_series_title).setVisibility(View.VISIBLE); setPairValueText(R.id.network_book_series_title, myBook.SeriesTitle); if (myBook.IndexInSeries > 0) { - setPairValueText(R.id.network_book_series_index, String.valueOf(myBook.IndexInSeries)); + setPairValueText(R.id.network_book_series_index, String.format("%.1f", myBook.IndexInSeries)); findViewById(R.id.network_book_series_index).setVisibility(View.VISIBLE); } else { findViewById(R.id.network_book_series_index).setVisibility(View.GONE); diff --git a/src/org/geometerplus/fbreader/formats/oeb/OEBMetaInfoReader.java b/src/org/geometerplus/fbreader/formats/oeb/OEBMetaInfoReader.java index a3d8d4fa9..7bf369fbe 100644 --- a/src/org/geometerplus/fbreader/formats/oeb/OEBMetaInfoReader.java +++ b/src/org/geometerplus/fbreader/formats/oeb/OEBMetaInfoReader.java @@ -41,7 +41,7 @@ class OEBMetaInfoReader extends ZLXMLReaderAdapter implements XMLNamespaces { private String myMetaTag = "meta"; private String mySeriesTitle = ""; - private int mySeriesIndex = 0; + private float mySeriesIndex = 0; private final ArrayList myAuthorList = new ArrayList(); private final ArrayList myAuthorList2 = new ArrayList(); @@ -138,7 +138,7 @@ class OEBMetaInfoReader extends ZLXMLReaderAdapter implements XMLNamespaces { } else if (attributes.getValue("name").equals("calibre:series_index")) { final String strIndex = attributes.getValue("content"); try { - mySeriesIndex = Integer.parseInt(strIndex); + mySeriesIndex = Float.parseFloat(strIndex); } catch (NumberFormatException e) { } } @@ -200,7 +200,7 @@ class OEBMetaInfoReader extends ZLXMLReaderAdapter implements XMLNamespaces { } } else { if (tag.equals(myMetaTag)) { - if (!mySeriesTitle.equals("") && mySeriesIndex > 0) { + if (!"".equals(mySeriesTitle) && mySeriesIndex > 0) { myBook.setSeriesInfo(mySeriesTitle, mySeriesIndex); } } diff --git a/src/org/geometerplus/fbreader/library/Book.java b/src/org/geometerplus/fbreader/library/Book.java index 9bafe1d83..3e584f99f 100644 --- a/src/org/geometerplus/fbreader/library/Book.java +++ b/src/org/geometerplus/fbreader/library/Book.java @@ -231,11 +231,11 @@ public class Book { return mySeriesInfo; } - void setSeriesInfoWithNoCheck(String name, long index) { + void setSeriesInfoWithNoCheck(String name, float index) { mySeriesInfo = new SeriesInfo(name, index); } - public void setSeriesInfo(String name, long index) { + public void setSeriesInfo(String name, float index) { if (mySeriesInfo == null) { if (name != null) { mySeriesInfo = new SeriesInfo(name, index); @@ -244,7 +244,7 @@ public class Book { } else if (name == null) { mySeriesInfo = null; myIsSaved = false; - } else if (!mySeriesInfo.Name.equals(name) || (mySeriesInfo.Index != index)) { + } else if (!name.equals(mySeriesInfo.Name) || mySeriesInfo.Index != index) { mySeriesInfo = new SeriesInfo(name, index); myIsSaved = false; } diff --git a/src/org/geometerplus/fbreader/library/BookInSeriesTree.java b/src/org/geometerplus/fbreader/library/BookInSeriesTree.java index 0c844cf51..975ed48fd 100644 --- a/src/org/geometerplus/fbreader/library/BookInSeriesTree.java +++ b/src/org/geometerplus/fbreader/library/BookInSeriesTree.java @@ -29,10 +29,10 @@ public final class BookInSeriesTree extends BookTree { @Override public int compareTo(FBTree tree) { if (tree instanceof BookInSeriesTree) { - final long difference = + final float difference = Book.getSeriesInfo().Index - ((BookTree)tree).Book.getSeriesInfo().Index; if (difference != 0) { - return (int)difference; + return difference > 0 ? 1 : -1; } } return super.compareTo(tree); diff --git a/src/org/geometerplus/fbreader/library/BooksDatabase.java b/src/org/geometerplus/fbreader/library/BooksDatabase.java index e8882bc86..cc330ceae 100644 --- a/src/org/geometerplus/fbreader/library/BooksDatabase.java +++ b/src/org/geometerplus/fbreader/library/BooksDatabase.java @@ -49,7 +49,7 @@ public abstract class BooksDatabase { protected void addTag(Book book, Tag tag) { book.addTagWithNoCheck(tag); } - protected void setSeriesInfo(Book book, String series, long index) { + protected void setSeriesInfo(Book book, String series, float index) { book.setSeriesInfoWithNoCheck(series, index); } diff --git a/src/org/geometerplus/fbreader/library/SeriesInfo.java b/src/org/geometerplus/fbreader/library/SeriesInfo.java index cf79f2d33..dae7fba6c 100644 --- a/src/org/geometerplus/fbreader/library/SeriesInfo.java +++ b/src/org/geometerplus/fbreader/library/SeriesInfo.java @@ -21,9 +21,9 @@ package org.geometerplus.fbreader.library; public final class SeriesInfo { public final String Name; - public final long Index; + public final float Index; - public SeriesInfo(String name, long index) { + public SeriesInfo(String name, float index) { Name = name; Index = index; } diff --git a/src/org/geometerplus/fbreader/network/NetworkBookItem.java b/src/org/geometerplus/fbreader/network/NetworkBookItem.java index dc93eefcb..24a7e13ce 100644 --- a/src/org/geometerplus/fbreader/network/NetworkBookItem.java +++ b/src/org/geometerplus/fbreader/network/NetworkBookItem.java @@ -75,7 +75,7 @@ public final class NetworkBookItem extends NetworkItem { public final LinkedList Authors; public final LinkedList Tags; public final String SeriesTitle; - public final int IndexInSeries; + public final float IndexInSeries; private final LinkedList myReferences; @@ -98,7 +98,7 @@ public final class NetworkBookItem extends NetworkItem { */ public NetworkBookItem(INetworkLink link, String id, int index, String title, String summary, /*String language, String date,*/ - List authors, List tags, String seriesTitle, int indexInSeries, + List authors, List tags, String seriesTitle, float indexInSeries, String cover, List references) { super(link, title, summary, cover); diff --git a/src/org/geometerplus/fbreader/network/NetworkBookItemComparator.java b/src/org/geometerplus/fbreader/network/NetworkBookItemComparator.java index faf44f04b..e5d314e3a 100644 --- a/src/org/geometerplus/fbreader/network/NetworkBookItemComparator.java +++ b/src/org/geometerplus/fbreader/network/NetworkBookItemComparator.java @@ -68,9 +68,9 @@ public final class NetworkBookItemComparator implements Comparator if (comp != 0) { return comp; } else { - final int diff = book0.IndexInSeries - book1.IndexInSeries; + final float diff = book0.IndexInSeries - book1.IndexInSeries; if (diff != 0) { - return diff; + return diff > 0 ? 1 : -1; } } return book0.Title.compareTo(book1.Title); diff --git a/src/org/geometerplus/fbreader/network/authentication/litres/LitResBookshelfItem.java b/src/org/geometerplus/fbreader/network/authentication/litres/LitResBookshelfItem.java index c1b0e19cd..fee08657d 100644 --- a/src/org/geometerplus/fbreader/network/authentication/litres/LitResBookshelfItem.java +++ b/src/org/geometerplus/fbreader/network/authentication/litres/LitResBookshelfItem.java @@ -135,11 +135,15 @@ class BySeriesCatalogItem extends SortedCatalogItem { public int compare(NetworkItem item0, NetworkItem item1) { final NetworkBookItem book0 = (NetworkBookItem)item0; final NetworkBookItem book1 = (NetworkBookItem)item1; - int diff = book0.SeriesTitle.compareTo(book1.SeriesTitle); - if (diff == 0) { - diff = book0.IndexInSeries - book1.IndexInSeries; + final int diff = book0.SeriesTitle.compareTo(book1.SeriesTitle); + if (diff != 0) { + return diff; } - return diff != 0 ? diff : book0.Title.compareTo(book1.Title); + final float fdiff = book0.IndexInSeries - book1.IndexInSeries; + if (fdiff != 0) { + return fdiff > 0 ? 1 : -1; + } + return book0.Title.compareTo(book1.Title); } }; } diff --git a/src/org/geometerplus/fbreader/network/opds/OPDSEntry.java b/src/org/geometerplus/fbreader/network/opds/OPDSEntry.java index 0ad9ed360..f6c639b50 100644 --- a/src/org/geometerplus/fbreader/network/opds/OPDSEntry.java +++ b/src/org/geometerplus/fbreader/network/opds/OPDSEntry.java @@ -28,7 +28,7 @@ class OPDSEntry extends ATOMEntry { public DCDate DCIssued; public String SeriesTitle; - public int SeriesIndex; + public float SeriesIndex; @Override public String toString() { diff --git a/src/org/geometerplus/fbreader/network/opds/OPDSXMLReader.java b/src/org/geometerplus/fbreader/network/opds/OPDSXMLReader.java index 631266477..960ebebb6 100644 --- a/src/org/geometerplus/fbreader/network/opds/OPDSXMLReader.java +++ b/src/org/geometerplus/fbreader/network/opds/OPDSXMLReader.java @@ -681,7 +681,7 @@ class OPDSXMLReader extends ZLXMLReaderAdapter { if (tagPrefix == myCalibreNamespaceId && tag == CALIBRE_TAG_SERIES_INDEX) { if (bufferContent != null) { try { - myEntry.SeriesIndex = Integer.parseInt(bufferContent); + myEntry.SeriesIndex = Float.parseFloat(bufferContent); } catch (NumberFormatException ex) { } }