mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
float series book index
This commit is contained in:
parent
76baa5f9e9
commit
fdcd44597a
13 changed files with 44 additions and 28 deletions
|
@ -21,8 +21,7 @@ package org.geometerplus.android.fbreader;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -216,7 +215,7 @@ public class BookInfoActivity extends Activity {
|
||||||
setupInfoPair(R.id.book_series, "series",
|
setupInfoPair(R.id.book_series, "series",
|
||||||
(series == null) ? null : series.Name);
|
(series == null) ? null : series.Name);
|
||||||
setupInfoPair(R.id.book_series_index, "indexInSeries",
|
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());
|
buffer.delete(0, buffer.length());
|
||||||
final HashSet<String> tagNames = new HashSet<String>();
|
final HashSet<String> tagNames = new HashSet<String>();
|
||||||
|
|
|
@ -61,7 +61,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
|
|
||||||
private void migrate(Context context) {
|
private void migrate(Context context) {
|
||||||
final int version = myDatabase.getVersion();
|
final int version = myDatabase.getVersion();
|
||||||
final int currentVersion = 14;
|
final int currentVersion = 15;
|
||||||
if (version >= currentVersion) {
|
if (version >= currentVersion) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -98,6 +98,8 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
updateTables12();
|
updateTables12();
|
||||||
case 13:
|
case 13:
|
||||||
updateTables13();
|
updateTables13();
|
||||||
|
case 14:
|
||||||
|
updateTables14();
|
||||||
}
|
}
|
||||||
myDatabase.setTransactionSuccessful();
|
myDatabase.setTransactionSuccessful();
|
||||||
myDatabase.endTransaction();
|
myDatabase.endTransaction();
|
||||||
|
@ -240,7 +242,7 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
if (book != null) {
|
if (book != null) {
|
||||||
String series = seriesById.get(cursor.getLong(1));
|
String series = seriesById.get(cursor.getLong(1));
|
||||||
if (series != null) {
|
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(1, bookId);
|
||||||
myInsertBookSeriesStatement.bindLong(2, seriesId);
|
myInsertBookSeriesStatement.bindLong(2, seriesId);
|
||||||
myInsertBookSeriesStatement.bindLong(3, seriesInfo.Index);
|
myInsertBookSeriesStatement.bindDouble(3, seriesInfo.Index);
|
||||||
myInsertBookSeriesStatement.execute();
|
myInsertBookSeriesStatement.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1127,4 +1129,15 @@ public final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
"ALTER TABLE Bookmarks ADD COLUMN visible INTEGER DEFAULT 1"
|
"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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,7 +186,7 @@ public class NetworkBookInfoActivity extends Activity implements NetworkView.Eve
|
||||||
findViewById(R.id.network_book_series_title).setVisibility(View.VISIBLE);
|
findViewById(R.id.network_book_series_title).setVisibility(View.VISIBLE);
|
||||||
setPairValueText(R.id.network_book_series_title, myBook.SeriesTitle);
|
setPairValueText(R.id.network_book_series_title, myBook.SeriesTitle);
|
||||||
if (myBook.IndexInSeries > 0) {
|
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);
|
findViewById(R.id.network_book_series_index).setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
findViewById(R.id.network_book_series_index).setVisibility(View.GONE);
|
findViewById(R.id.network_book_series_index).setVisibility(View.GONE);
|
||||||
|
|
|
@ -41,7 +41,7 @@ class OEBMetaInfoReader extends ZLXMLReaderAdapter implements XMLNamespaces {
|
||||||
private String myMetaTag = "meta";
|
private String myMetaTag = "meta";
|
||||||
|
|
||||||
private String mySeriesTitle = "";
|
private String mySeriesTitle = "";
|
||||||
private int mySeriesIndex = 0;
|
private float mySeriesIndex = 0;
|
||||||
|
|
||||||
private final ArrayList<String> myAuthorList = new ArrayList<String>();
|
private final ArrayList<String> myAuthorList = new ArrayList<String>();
|
||||||
private final ArrayList<String> myAuthorList2 = new ArrayList<String>();
|
private final ArrayList<String> myAuthorList2 = new ArrayList<String>();
|
||||||
|
@ -138,7 +138,7 @@ class OEBMetaInfoReader extends ZLXMLReaderAdapter implements XMLNamespaces {
|
||||||
} else if (attributes.getValue("name").equals("calibre:series_index")) {
|
} else if (attributes.getValue("name").equals("calibre:series_index")) {
|
||||||
final String strIndex = attributes.getValue("content");
|
final String strIndex = attributes.getValue("content");
|
||||||
try {
|
try {
|
||||||
mySeriesIndex = Integer.parseInt(strIndex);
|
mySeriesIndex = Float.parseFloat(strIndex);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ class OEBMetaInfoReader extends ZLXMLReaderAdapter implements XMLNamespaces {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (tag.equals(myMetaTag)) {
|
if (tag.equals(myMetaTag)) {
|
||||||
if (!mySeriesTitle.equals("") && mySeriesIndex > 0) {
|
if (!"".equals(mySeriesTitle) && mySeriesIndex > 0) {
|
||||||
myBook.setSeriesInfo(mySeriesTitle, mySeriesIndex);
|
myBook.setSeriesInfo(mySeriesTitle, mySeriesIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,11 +231,11 @@ public class Book {
|
||||||
return mySeriesInfo;
|
return mySeriesInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSeriesInfoWithNoCheck(String name, long index) {
|
void setSeriesInfoWithNoCheck(String name, float index) {
|
||||||
mySeriesInfo = new SeriesInfo(name, index);
|
mySeriesInfo = new SeriesInfo(name, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSeriesInfo(String name, long index) {
|
public void setSeriesInfo(String name, float index) {
|
||||||
if (mySeriesInfo == null) {
|
if (mySeriesInfo == null) {
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
mySeriesInfo = new SeriesInfo(name, index);
|
mySeriesInfo = new SeriesInfo(name, index);
|
||||||
|
@ -244,7 +244,7 @@ public class Book {
|
||||||
} else if (name == null) {
|
} else if (name == null) {
|
||||||
mySeriesInfo = null;
|
mySeriesInfo = null;
|
||||||
myIsSaved = false;
|
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);
|
mySeriesInfo = new SeriesInfo(name, index);
|
||||||
myIsSaved = false;
|
myIsSaved = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,10 +29,10 @@ public final class BookInSeriesTree extends BookTree {
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(FBTree tree) {
|
public int compareTo(FBTree tree) {
|
||||||
if (tree instanceof BookInSeriesTree) {
|
if (tree instanceof BookInSeriesTree) {
|
||||||
final long difference =
|
final float difference =
|
||||||
Book.getSeriesInfo().Index - ((BookTree)tree).Book.getSeriesInfo().Index;
|
Book.getSeriesInfo().Index - ((BookTree)tree).Book.getSeriesInfo().Index;
|
||||||
if (difference != 0) {
|
if (difference != 0) {
|
||||||
return (int)difference;
|
return difference > 0 ? 1 : -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.compareTo(tree);
|
return super.compareTo(tree);
|
||||||
|
|
|
@ -49,7 +49,7 @@ public abstract class BooksDatabase {
|
||||||
protected void addTag(Book book, Tag tag) {
|
protected void addTag(Book book, Tag tag) {
|
||||||
book.addTagWithNoCheck(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);
|
book.setSeriesInfoWithNoCheck(series, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,9 @@ package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
public final class SeriesInfo {
|
public final class SeriesInfo {
|
||||||
public final String Name;
|
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;
|
Name = name;
|
||||||
Index = index;
|
Index = index;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ public final class NetworkBookItem extends NetworkItem {
|
||||||
public final LinkedList<AuthorData> Authors;
|
public final LinkedList<AuthorData> Authors;
|
||||||
public final LinkedList<String> Tags;
|
public final LinkedList<String> Tags;
|
||||||
public final String SeriesTitle;
|
public final String SeriesTitle;
|
||||||
public final int IndexInSeries;
|
public final float IndexInSeries;
|
||||||
|
|
||||||
private final LinkedList<BookReference> myReferences;
|
private final LinkedList<BookReference> myReferences;
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ public final class NetworkBookItem extends NetworkItem {
|
||||||
*/
|
*/
|
||||||
public NetworkBookItem(INetworkLink link, String id, int index,
|
public NetworkBookItem(INetworkLink link, String id, int index,
|
||||||
String title, String summary, /*String language, String date,*/
|
String title, String summary, /*String language, String date,*/
|
||||||
List<AuthorData> authors, List<String> tags, String seriesTitle, int indexInSeries,
|
List<AuthorData> authors, List<String> tags, String seriesTitle, float indexInSeries,
|
||||||
String cover,
|
String cover,
|
||||||
List<BookReference> references) {
|
List<BookReference> references) {
|
||||||
super(link, title, summary, cover);
|
super(link, title, summary, cover);
|
||||||
|
|
|
@ -68,9 +68,9 @@ public final class NetworkBookItemComparator implements Comparator<NetworkItem>
|
||||||
if (comp != 0) {
|
if (comp != 0) {
|
||||||
return comp;
|
return comp;
|
||||||
} else {
|
} else {
|
||||||
final int diff = book0.IndexInSeries - book1.IndexInSeries;
|
final float diff = book0.IndexInSeries - book1.IndexInSeries;
|
||||||
if (diff != 0) {
|
if (diff != 0) {
|
||||||
return diff;
|
return diff > 0 ? 1 : -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return book0.Title.compareTo(book1.Title);
|
return book0.Title.compareTo(book1.Title);
|
||||||
|
|
|
@ -135,11 +135,15 @@ class BySeriesCatalogItem extends SortedCatalogItem {
|
||||||
public int compare(NetworkItem item0, NetworkItem item1) {
|
public int compare(NetworkItem item0, NetworkItem item1) {
|
||||||
final NetworkBookItem book0 = (NetworkBookItem)item0;
|
final NetworkBookItem book0 = (NetworkBookItem)item0;
|
||||||
final NetworkBookItem book1 = (NetworkBookItem)item1;
|
final NetworkBookItem book1 = (NetworkBookItem)item1;
|
||||||
int diff = book0.SeriesTitle.compareTo(book1.SeriesTitle);
|
final int diff = book0.SeriesTitle.compareTo(book1.SeriesTitle);
|
||||||
if (diff == 0) {
|
if (diff != 0) {
|
||||||
diff = book0.IndexInSeries - book1.IndexInSeries;
|
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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ class OPDSEntry extends ATOMEntry {
|
||||||
public DCDate DCIssued;
|
public DCDate DCIssued;
|
||||||
|
|
||||||
public String SeriesTitle;
|
public String SeriesTitle;
|
||||||
public int SeriesIndex;
|
public float SeriesIndex;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
@ -681,7 +681,7 @@ class OPDSXMLReader extends ZLXMLReaderAdapter {
|
||||||
if (tagPrefix == myCalibreNamespaceId && tag == CALIBRE_TAG_SERIES_INDEX) {
|
if (tagPrefix == myCalibreNamespaceId && tag == CALIBRE_TAG_SERIES_INDEX) {
|
||||||
if (bufferContent != null) {
|
if (bufferContent != null) {
|
||||||
try {
|
try {
|
||||||
myEntry.SeriesIndex = Integer.parseInt(bufferContent);
|
myEntry.SeriesIndex = Float.parseFloat(bufferContent);
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue