mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
do not clean text cache on progress update
This commit is contained in:
parent
74de3398cc
commit
b512d3505f
6 changed files with 88 additions and 38 deletions
|
@ -50,14 +50,19 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
||||||
|
|
||||||
public volatile boolean HasBookmark;
|
public volatile boolean HasBookmark;
|
||||||
|
|
||||||
protected volatile boolean myIsSaved;
|
protected enum SaveState {
|
||||||
|
Saved,
|
||||||
|
ProgressNotSaved,
|
||||||
|
NotSaved;
|
||||||
|
};
|
||||||
|
protected volatile SaveState mySaveState = SaveState.NotSaved;
|
||||||
|
|
||||||
AbstractBook(long id, String title, String encoding, String language) {
|
AbstractBook(long id, String title, String encoding, String language) {
|
||||||
super(title);
|
super(title);
|
||||||
myId = id;
|
myId = id;
|
||||||
myEncoding = encoding;
|
myEncoding = encoding;
|
||||||
myLanguage = language;
|
myLanguage = language;
|
||||||
myIsSaved = true;
|
mySaveState = SaveState.Saved;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getPath();
|
public abstract String getPath();
|
||||||
|
@ -71,28 +76,28 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
||||||
setLanguage(book.myLanguage);
|
setLanguage(book.myLanguage);
|
||||||
if (!ComparisonUtil.equal(myAuthors, book.myAuthors)) {
|
if (!ComparisonUtil.equal(myAuthors, book.myAuthors)) {
|
||||||
myAuthors = book.myAuthors != null ? new ArrayList<Author>(book.myAuthors) : null;
|
myAuthors = book.myAuthors != null ? new ArrayList<Author>(book.myAuthors) : null;
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
if (!ComparisonUtil.equal(myTags, book.myTags)) {
|
if (!ComparisonUtil.equal(myTags, book.myTags)) {
|
||||||
myTags = book.myTags != null ? new ArrayList<Tag>(book.myTags) : null;
|
myTags = book.myTags != null ? new ArrayList<Tag>(book.myTags) : null;
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
if (!MiscUtil.listsEquals(myLabels, book.myLabels)) {
|
if (!MiscUtil.listsEquals(myLabels, book.myLabels)) {
|
||||||
myLabels = book.myLabels != null ? new ArrayList<Label>(book.myLabels) : null;
|
myLabels = book.myLabels != null ? new ArrayList<Label>(book.myLabels) : null;
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
if (!ComparisonUtil.equal(mySeriesInfo, book.mySeriesInfo)) {
|
if (!ComparisonUtil.equal(mySeriesInfo, book.mySeriesInfo)) {
|
||||||
mySeriesInfo = book.mySeriesInfo;
|
mySeriesInfo = book.mySeriesInfo;
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
if (!MiscUtil.listsEquals(myUids, book.myUids)) {
|
if (!MiscUtil.listsEquals(myUids, book.myUids)) {
|
||||||
myUids = book.myUids != null ? new ArrayList<UID>(book.myUids) : null;
|
myUids = book.myUids != null ? new ArrayList<UID>(book.myUids) : null;
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
setProgress(book.myProgress);
|
setProgress(book.myProgress);
|
||||||
if (HasBookmark != book.HasBookmark) {
|
if (HasBookmark != book.HasBookmark) {
|
||||||
HasBookmark = book.HasBookmark;
|
HasBookmark = book.HasBookmark;
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +135,7 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
||||||
public void removeAllAuthors() {
|
public void removeAllAuthors() {
|
||||||
if (myAuthors != null) {
|
if (myAuthors != null) {
|
||||||
myAuthors = null;
|
myAuthors = null;
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,10 +146,10 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
||||||
if (myAuthors == null) {
|
if (myAuthors == null) {
|
||||||
myAuthors = new ArrayList<Author>();
|
myAuthors = new ArrayList<Author>();
|
||||||
myAuthors.add(author);
|
myAuthors.add(author);
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
} else if (!myAuthors.contains(author)) {
|
} else if (!myAuthors.contains(author)) {
|
||||||
myAuthors.add(author);
|
myAuthors.add(author);
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +176,7 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
||||||
}
|
}
|
||||||
if (!getTitle().equals(title)) {
|
if (!getTitle().equals(title)) {
|
||||||
super.setTitle(title);
|
super.setTitle(title);
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,14 +196,14 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
||||||
if (mySeriesInfo == null) {
|
if (mySeriesInfo == null) {
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
mySeriesInfo = new SeriesInfo(name, index);
|
mySeriesInfo = new SeriesInfo(name, index);
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
} else if (name == null) {
|
} else if (name == null) {
|
||||||
mySeriesInfo = null;
|
mySeriesInfo = null;
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
} else if (!name.equals(mySeriesInfo.Series.getTitle()) || mySeriesInfo.Index != index) {
|
} else if (!name.equals(mySeriesInfo.Series.getTitle()) || mySeriesInfo.Index != index) {
|
||||||
mySeriesInfo = new SeriesInfo(name, index);
|
mySeriesInfo = new SeriesInfo(name, index);
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +216,7 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
||||||
if (!ComparisonUtil.equal(myLanguage, language)) {
|
if (!ComparisonUtil.equal(myLanguage, language)) {
|
||||||
myLanguage = language;
|
myLanguage = language;
|
||||||
resetSortKey();
|
resetSortKey();
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,7 +227,7 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
||||||
public void setEncoding(String encoding) {
|
public void setEncoding(String encoding) {
|
||||||
if (!ComparisonUtil.equal(myEncoding, encoding)) {
|
if (!ComparisonUtil.equal(myEncoding, encoding)) {
|
||||||
myEncoding = encoding;
|
myEncoding = encoding;
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,7 +269,7 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
||||||
public void removeAllTags() {
|
public void removeAllTags() {
|
||||||
if (myTags != null) {
|
if (myTags != null) {
|
||||||
myTags = null;
|
myTags = null;
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +280,7 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
||||||
}
|
}
|
||||||
if (!myTags.contains(tag)) {
|
if (!myTags.contains(tag)) {
|
||||||
myTags.add(tag);
|
myTags.add(tag);
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -314,13 +319,13 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
||||||
}
|
}
|
||||||
if (!myLabels.contains(label)) {
|
if (!myLabels.contains(label)) {
|
||||||
myLabels.add(label);
|
myLabels.add(label);
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeLabel(String label) {
|
public void removeLabel(String label) {
|
||||||
if (myLabels != null && myLabels.remove(new Label(label))) {
|
if (myLabels != null && myLabels.remove(new Label(label))) {
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,7 +356,7 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
||||||
}
|
}
|
||||||
if (!myUids.contains(uid)) {
|
if (!myUids.contains(uid)) {
|
||||||
myUids.add(uid);
|
myUids.add(uid);
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,7 +371,9 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
||||||
public void setProgress(RationalNumber progress) {
|
public void setProgress(RationalNumber progress) {
|
||||||
if (!ComparisonUtil.equal(myProgress, progress)) {
|
if (!ComparisonUtil.equal(myProgress, progress)) {
|
||||||
myProgress = progress;
|
myProgress = progress;
|
||||||
myIsSaved = false;
|
if (mySaveState == SaveState.Saved) {
|
||||||
|
mySaveState = SaveState.ProgressNotSaved;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -211,7 +211,7 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
||||||
synchronized (myBooksByFile) {
|
synchronized (myBooksByFile) {
|
||||||
final DbBook existing = myBooksByFile.get(book.File);
|
final DbBook existing = myBooksByFile.get(book.File);
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
if (book.getId() == -1 && !book.save(myDatabase, true)) {
|
if (book.getId() == -1 && book.save(myDatabase, true) == DbBook.WhatIsSaved.Nothing) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,9 +230,13 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
||||||
return true;
|
return true;
|
||||||
} else if (force) {
|
} else if (force) {
|
||||||
existing.updateFrom(book);
|
existing.updateFrom(book);
|
||||||
if (existing.save(myDatabase, false)) {
|
switch (existing.save(myDatabase, false)) {
|
||||||
fireBookEvent(BookEvent.Updated, existing);
|
case Everything:
|
||||||
return true;
|
fireBookEvent(BookEvent.Updated, existing);
|
||||||
|
return true;
|
||||||
|
case Progress:
|
||||||
|
fireBookEvent(BookEvent.ProgressUpdated, existing);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -24,6 +24,7 @@ public enum BookEvent {
|
||||||
Updated,
|
Updated,
|
||||||
Removed,
|
Removed,
|
||||||
Opened,
|
Opened,
|
||||||
|
ProgressUpdated,
|
||||||
BookmarksUpdated,
|
BookmarksUpdated,
|
||||||
BookmarkStyleChanged
|
BookmarkStyleChanged
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ public abstract class BookUtil {
|
||||||
book.mySeriesInfo = null;
|
book.mySeriesInfo = null;
|
||||||
book.myUids = null;
|
book.myUids = null;
|
||||||
|
|
||||||
book.myIsSaved = false;
|
book.mySaveState = AbstractBook.SaveState.NotSaved;
|
||||||
|
|
||||||
plugin.readMetainfo(book);
|
plugin.readMetainfo(book);
|
||||||
if (book.myUids == null || book.myUids.isEmpty()) {
|
if (book.myUids == null || book.myUids.isEmpty()) {
|
||||||
|
|
|
@ -44,7 +44,7 @@ public final class DbBook extends AbstractBook {
|
||||||
DbBook(ZLFile file, FormatPlugin plugin) throws BookReadingException {
|
DbBook(ZLFile file, FormatPlugin plugin) throws BookReadingException {
|
||||||
this(-1, plugin.realBookFile(file), null, null, null);
|
this(-1, plugin.realBookFile(file), null, null, null);
|
||||||
BookUtil.readMetainfo(this, plugin);
|
BookUtil.readMetainfo(this, plugin);
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,7 +60,7 @@ public final class DbBook extends AbstractBook {
|
||||||
myUids = database.listUids(myId);
|
myUids = database.listUids(myId);
|
||||||
myProgress = database.getProgress(myId);
|
myProgress = database.getProgress(myId);
|
||||||
HasBookmark = database.hasVisibleBookmark(myId);
|
HasBookmark = database.hasVisibleBookmark(myId);
|
||||||
myIsSaved = true;
|
mySaveState = SaveState.Saved;
|
||||||
if (myUids == null || myUids.isEmpty()) {
|
if (myUids == null || myUids.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
BookUtil.getPlugin(pluginCollection, this).readUids(this);
|
BookUtil.getPlugin(pluginCollection, this).readUids(this);
|
||||||
|
@ -70,11 +70,48 @@ public final class DbBook extends AbstractBook {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean save(final BooksDatabase database, boolean force) {
|
enum WhatIsSaved {
|
||||||
if (!force && myId != -1 && myIsSaved) {
|
Nothing,
|
||||||
return false;
|
Progress,
|
||||||
|
Everything;
|
||||||
|
}
|
||||||
|
|
||||||
|
WhatIsSaved save(BooksDatabase database, boolean force) {
|
||||||
|
if (force || myId == -1) {
|
||||||
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (mySaveState) {
|
||||||
|
case Saved:
|
||||||
|
return WhatIsSaved.Nothing;
|
||||||
|
case ProgressNotSaved:
|
||||||
|
return saveProgress(database) ? WhatIsSaved.Progress : WhatIsSaved.Nothing;
|
||||||
|
default:
|
||||||
|
case NotSaved:
|
||||||
|
return saveFull(database) ? WhatIsSaved.Everything : WhatIsSaved.Nothing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean saveProgress(final BooksDatabase database) {
|
||||||
|
final boolean[] result = new boolean[] { false };
|
||||||
|
database.executeAsTransaction(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
if (myId != -1 && myProgress != null) {
|
||||||
|
database.saveBookProgress(myId, myProgress);
|
||||||
|
result[0] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result[0]) {
|
||||||
|
mySaveState = SaveState.Saved;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean saveFull(final BooksDatabase database) {
|
||||||
final boolean[] result = new boolean[] { true };
|
final boolean[] result = new boolean[] { true };
|
||||||
database.executeAsTransaction(new Runnable() {
|
database.executeAsTransaction(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -127,7 +164,7 @@ public final class DbBook extends AbstractBook {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result[0]) {
|
if (result[0]) {
|
||||||
myIsSaved = true;
|
mySaveState = SaveState.Saved;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -185,17 +222,17 @@ public final class DbBook extends AbstractBook {
|
||||||
if (!MiscUtil.listsEquals(myTags, other.myTags) &&
|
if (!MiscUtil.listsEquals(myTags, other.myTags) &&
|
||||||
MiscUtil.listsEquals(myTags, base.myTags)) {
|
MiscUtil.listsEquals(myTags, base.myTags)) {
|
||||||
myTags = other.myTags != null ? new ArrayList<Tag>(other.myTags) : null;
|
myTags = other.myTags != null ? new ArrayList<Tag>(other.myTags) : null;
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
if (!ComparisonUtil.equal(mySeriesInfo, other.mySeriesInfo) &&
|
if (!ComparisonUtil.equal(mySeriesInfo, other.mySeriesInfo) &&
|
||||||
ComparisonUtil.equal(mySeriesInfo, base.mySeriesInfo)) {
|
ComparisonUtil.equal(mySeriesInfo, base.mySeriesInfo)) {
|
||||||
mySeriesInfo = other.mySeriesInfo;
|
mySeriesInfo = other.mySeriesInfo;
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
if (!MiscUtil.listsEquals(myUids, other.myUids) &&
|
if (!MiscUtil.listsEquals(myUids, other.myUids) &&
|
||||||
MiscUtil.listsEquals(myUids, base.myUids)) {
|
MiscUtil.listsEquals(myUids, base.myUids)) {
|
||||||
myUids = other.myUids != null ? new ArrayList<UID>(other.myUids) : null;
|
myUids = other.myUids != null ? new ArrayList<UID>(other.myUids) : null;
|
||||||
myIsSaved = false;
|
mySaveState = SaveState.NotSaved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,6 @@ public class TitleListTree extends FirstLevelTree {
|
||||||
} else {
|
} else {
|
||||||
return super.onBookEvent(event, book);
|
return super.onBookEvent(event, book);
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
case Updated:
|
case Updated:
|
||||||
if (myGroupByFirstLetter) {
|
if (myGroupByFirstLetter) {
|
||||||
// TODO: remove old tree (?)
|
// TODO: remove old tree (?)
|
||||||
|
@ -93,6 +92,8 @@ public class TitleListTree extends FirstLevelTree {
|
||||||
changed |= createBookWithAuthorsSubtree(book);
|
changed |= createBookWithAuthorsSubtree(book);
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
return super.onBookEvent(event, book);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue