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;
|
||||
|
||||
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) {
|
||||
super(title);
|
||||
myId = id;
|
||||
myEncoding = encoding;
|
||||
myLanguage = language;
|
||||
myIsSaved = true;
|
||||
mySaveState = SaveState.Saved;
|
||||
}
|
||||
|
||||
public abstract String getPath();
|
||||
|
@ -71,28 +76,28 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
|||
setLanguage(book.myLanguage);
|
||||
if (!ComparisonUtil.equal(myAuthors, book.myAuthors)) {
|
||||
myAuthors = book.myAuthors != null ? new ArrayList<Author>(book.myAuthors) : null;
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
}
|
||||
if (!ComparisonUtil.equal(myTags, book.myTags)) {
|
||||
myTags = book.myTags != null ? new ArrayList<Tag>(book.myTags) : null;
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
}
|
||||
if (!MiscUtil.listsEquals(myLabels, book.myLabels)) {
|
||||
myLabels = book.myLabels != null ? new ArrayList<Label>(book.myLabels) : null;
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
}
|
||||
if (!ComparisonUtil.equal(mySeriesInfo, book.mySeriesInfo)) {
|
||||
mySeriesInfo = book.mySeriesInfo;
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
}
|
||||
if (!MiscUtil.listsEquals(myUids, book.myUids)) {
|
||||
myUids = book.myUids != null ? new ArrayList<UID>(book.myUids) : null;
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
}
|
||||
setProgress(book.myProgress);
|
||||
if (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() {
|
||||
if (myAuthors != null) {
|
||||
myAuthors = null;
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,10 +146,10 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
|||
if (myAuthors == null) {
|
||||
myAuthors = new ArrayList<Author>();
|
||||
myAuthors.add(author);
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
} else if (!myAuthors.contains(author)) {
|
||||
myAuthors.add(author);
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,7 +176,7 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
|||
}
|
||||
if (!getTitle().equals(title)) {
|
||||
super.setTitle(title);
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,14 +196,14 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
|||
if (mySeriesInfo == null) {
|
||||
if (name != null) {
|
||||
mySeriesInfo = new SeriesInfo(name, index);
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
}
|
||||
} else if (name == null) {
|
||||
mySeriesInfo = null;
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
} else if (!name.equals(mySeriesInfo.Series.getTitle()) || mySeriesInfo.Index != 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)) {
|
||||
myLanguage = language;
|
||||
resetSortKey();
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -222,7 +227,7 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
|||
public void setEncoding(String encoding) {
|
||||
if (!ComparisonUtil.equal(myEncoding, encoding)) {
|
||||
myEncoding = encoding;
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -264,7 +269,7 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
|||
public void removeAllTags() {
|
||||
if (myTags != null) {
|
||||
myTags = null;
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -275,7 +280,7 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
|||
}
|
||||
if (!myTags.contains(tag)) {
|
||||
myTags.add(tag);
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -314,13 +319,13 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
|||
}
|
||||
if (!myLabels.contains(label)) {
|
||||
myLabels.add(label);
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeLabel(String 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)) {
|
||||
myUids.add(uid);
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -366,7 +371,9 @@ public abstract class AbstractBook extends TitledEntity<AbstractBook> {
|
|||
public void setProgress(RationalNumber progress) {
|
||||
if (!ComparisonUtil.equal(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) {
|
||||
final DbBook existing = myBooksByFile.get(book.File);
|
||||
if (existing == null) {
|
||||
if (book.getId() == -1 && !book.save(myDatabase, true)) {
|
||||
if (book.getId() == -1 && book.save(myDatabase, true) == DbBook.WhatIsSaved.Nothing) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -230,9 +230,13 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
|||
return true;
|
||||
} else if (force) {
|
||||
existing.updateFrom(book);
|
||||
if (existing.save(myDatabase, false)) {
|
||||
switch (existing.save(myDatabase, false)) {
|
||||
case Everything:
|
||||
fireBookEvent(BookEvent.Updated, existing);
|
||||
return true;
|
||||
case Progress:
|
||||
fireBookEvent(BookEvent.ProgressUpdated, existing);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -24,6 +24,7 @@ public enum BookEvent {
|
|||
Updated,
|
||||
Removed,
|
||||
Opened,
|
||||
ProgressUpdated,
|
||||
BookmarksUpdated,
|
||||
BookmarkStyleChanged
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ public abstract class BookUtil {
|
|||
book.mySeriesInfo = null;
|
||||
book.myUids = null;
|
||||
|
||||
book.myIsSaved = false;
|
||||
book.mySaveState = AbstractBook.SaveState.NotSaved;
|
||||
|
||||
plugin.readMetainfo(book);
|
||||
if (book.myUids == null || book.myUids.isEmpty()) {
|
||||
|
|
|
@ -44,7 +44,7 @@ public final class DbBook extends AbstractBook {
|
|||
DbBook(ZLFile file, FormatPlugin plugin) throws BookReadingException {
|
||||
this(-1, plugin.realBookFile(file), null, null, null);
|
||||
BookUtil.readMetainfo(this, plugin);
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,7 +60,7 @@ public final class DbBook extends AbstractBook {
|
|||
myUids = database.listUids(myId);
|
||||
myProgress = database.getProgress(myId);
|
||||
HasBookmark = database.hasVisibleBookmark(myId);
|
||||
myIsSaved = true;
|
||||
mySaveState = SaveState.Saved;
|
||||
if (myUids == null || myUids.isEmpty()) {
|
||||
try {
|
||||
BookUtil.getPlugin(pluginCollection, this).readUids(this);
|
||||
|
@ -70,11 +70,48 @@ public final class DbBook extends AbstractBook {
|
|||
}
|
||||
}
|
||||
|
||||
boolean save(final BooksDatabase database, boolean force) {
|
||||
if (!force && myId != -1 && myIsSaved) {
|
||||
return false;
|
||||
enum WhatIsSaved {
|
||||
Nothing,
|
||||
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 };
|
||||
database.executeAsTransaction(new Runnable() {
|
||||
public void run() {
|
||||
|
@ -127,7 +164,7 @@ public final class DbBook extends AbstractBook {
|
|||
});
|
||||
|
||||
if (result[0]) {
|
||||
myIsSaved = true;
|
||||
mySaveState = SaveState.Saved;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -185,17 +222,17 @@ public final class DbBook extends AbstractBook {
|
|||
if (!MiscUtil.listsEquals(myTags, other.myTags) &&
|
||||
MiscUtil.listsEquals(myTags, base.myTags)) {
|
||||
myTags = other.myTags != null ? new ArrayList<Tag>(other.myTags) : null;
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
}
|
||||
if (!ComparisonUtil.equal(mySeriesInfo, other.mySeriesInfo) &&
|
||||
ComparisonUtil.equal(mySeriesInfo, base.mySeriesInfo)) {
|
||||
mySeriesInfo = other.mySeriesInfo;
|
||||
myIsSaved = false;
|
||||
mySaveState = SaveState.NotSaved;
|
||||
}
|
||||
if (!MiscUtil.listsEquals(myUids, other.myUids) &&
|
||||
MiscUtil.listsEquals(myUids, base.myUids)) {
|
||||
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 {
|
||||
return super.onBookEvent(event, book);
|
||||
}
|
||||
default:
|
||||
case Updated:
|
||||
if (myGroupByFirstLetter) {
|
||||
// TODO: remove old tree (?)
|
||||
|
@ -93,6 +92,8 @@ public class TitleListTree extends FirstLevelTree {
|
|||
changed |= createBookWithAuthorsSubtree(book);
|
||||
return changed;
|
||||
}
|
||||
default:
|
||||
return super.onBookEvent(event, book);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue