mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 01:39:18 +02:00
Merge branch 'positions' of github.com:geometer/FBReaderJ into positions
This commit is contained in:
commit
8cfe8fc76e
4 changed files with 46 additions and 15 deletions
|
@ -1047,29 +1047,31 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
|
||||
private SQLiteStatement myPositionStatement;
|
||||
@Override
|
||||
protected void savePosition(long bookId, long numerator, long denominator) {
|
||||
protected void savePosition(long bookId, RationalNumber progress) {
|
||||
if (myPositionStatement == null) {
|
||||
myPositionStatement = myDatabase.compileStatement(
|
||||
"INSERT OR REPLACE INTO Positions (book_id,numerator,denominator) VALUES (?,?,?)"
|
||||
"INSERT OR REPLACE INTO BookReadingProgress (book_id,numerator,denominator) VALUES (?,?,?)"
|
||||
);
|
||||
}
|
||||
myStorePositionStatement.bindLong(1, bookId);
|
||||
myStorePositionStatement.bindLong(2, numerator);
|
||||
myStorePositionStatement.bindLong(3, denominator);
|
||||
myStorePositionStatement.bindLong(2, progress.getNumerator());
|
||||
myStorePositionStatement.bindLong(3, progress.getDenominator());
|
||||
myStorePositionStatement.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float loadPosition(long bookId) {
|
||||
float position = 0;
|
||||
protected RationalNumber loadPosition(long bookId) {
|
||||
RationalNumber progress;
|
||||
Cursor cursor = myDatabase.rawQuery(
|
||||
"SELECT numerator,denominator FROM Positions WHERE book_id = " + bookId, null
|
||||
"SELECT numerator,denominator FROM BookReadingProgress WHERE book_id = " + bookId, null
|
||||
);
|
||||
if (cursor.moveToNext()) {
|
||||
position = cursor.getLong(0)/cursor.getLong(1);
|
||||
progress = new RationalNumber(cursor.getLong(0), cursor.getLong(1));
|
||||
} else {
|
||||
progress = new RationalNumber(0, 1);
|
||||
}
|
||||
cursor.close();
|
||||
return position;
|
||||
return progress;
|
||||
}
|
||||
|
||||
private void createTables() {
|
||||
|
@ -1472,9 +1474,9 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
|
||||
private void updateTables25() {
|
||||
myDatabase.execSQL(
|
||||
"CREATE TABLE IF NOT EXISTS Positions(" +
|
||||
"book_id INTEGER PRIMARY KEY NOT NULL UNIQUE REFERENCES Books(book_id)," +
|
||||
"numerator INTEGER NOT NULL," +
|
||||
"denominator INTEGER NOT NULL)");
|
||||
"CREATE TABLE IF NOT EXISTS BookReadingProgress(" +
|
||||
"book_id INTEGER PRIMARY KEY NOT NULL UNIQUE REFERENCES Books(book_id)," +
|
||||
"numerator INTEGER NOT NULL," +
|
||||
"denominator INTEGER NOT NULL)");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,8 @@ public class Book extends TitledEntity {
|
|||
private static final WeakReference<ZLImage> NULL_IMAGE = new WeakReference<ZLImage>(null);
|
||||
private WeakReference<ZLImage> myCover;
|
||||
|
||||
private RationalNumber myProgress;
|
||||
|
||||
Book(long id, ZLFile file, String title, String encoding, String language) {
|
||||
super(title);
|
||||
myId = id;
|
||||
|
@ -541,4 +543,12 @@ public class Book extends TitledEntity {
|
|||
.append("]")
|
||||
.toString();
|
||||
}
|
||||
|
||||
public void setProgress(long numerator, long denominator) {
|
||||
myProgress = new RationalNumber(numerator, denominator);
|
||||
}
|
||||
|
||||
public RationalNumber getProgress() {
|
||||
return myProgress;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,6 +123,6 @@ public abstract class BooksDatabase {
|
|||
protected abstract Collection<String> loadVisitedHyperlinks(long bookId);
|
||||
protected abstract void addVisitedHyperlink(long bookId, String hyperlinkId);
|
||||
|
||||
protected abstract void savePosition(long bookId, long numerator, long denominator);
|
||||
protected abstract float loadPosition(long bookId);
|
||||
protected abstract void savePosition(long bookId, RationalNumber progress);
|
||||
protected abstract RationalNumber loadPosition(long bookId);
|
||||
}
|
||||
|
|
19
src/org/geometerplus/fbreader/book/RationalNumber.java
Normal file
19
src/org/geometerplus/fbreader/book/RationalNumber.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package org.geometerplus.fbreader.book;
|
||||
|
||||
public class RationalNumber {
|
||||
private long myNumerator;
|
||||
private long myDenominator;
|
||||
|
||||
public RationalNumber(long numerator, long denominator) {
|
||||
myNumerator = numerator;
|
||||
myDenominator = denominator;
|
||||
}
|
||||
|
||||
public long getNumerator() {
|
||||
return myNumerator;
|
||||
}
|
||||
|
||||
public long getDenominator() {
|
||||
return myDenominator;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue