From 42797eff5b7bf96a93bcd79ffa2ce62d256ef35d Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Wed, 8 Apr 2020 17:47:48 +0200 Subject: [PATCH] use filter() instead of list() --- src/be/nikiroo/fanfix_swing/gui/BooksPanel.java | 3 ++- .../nikiroo/fanfix_swing/gui/book/BookInfo.java | 14 +++++--------- .../nikiroo/fanfix_swing/gui/book/BookPopup.java | 16 ++++------------ 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java b/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java index 73de77e..8a88213 100644 --- a/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java +++ b/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java @@ -129,7 +129,7 @@ public class BooksPanel extends ListenerPanel { protected List doInBackground() throws Exception { List bookInfos = new ArrayList(); BasicLibrary lib = Instance.getInstance().getLibrary(); - for (MetaData meta : lib.getList(null).filter(sources, authors, tags)) { + for (MetaData meta : lib.getList().filter(sources, authors, tags)) { bookInfos.add(BookInfo.fromMeta(lib, meta)); } @@ -232,6 +232,7 @@ public class BooksPanel extends ListenerPanel { @Override public void invalidateCache() { + // TODO: also reset the popup menu for sources/author fireActionPerformed(INVALIDATE_CACHE); } }); diff --git a/src/be/nikiroo/fanfix_swing/gui/book/BookInfo.java b/src/be/nikiroo/fanfix_swing/gui/book/BookInfo.java index b7dc509..de57e84 100644 --- a/src/be/nikiroo/fanfix_swing/gui/book/BookInfo.java +++ b/src/be/nikiroo/fanfix_swing/gui/book/BookInfo.java @@ -122,7 +122,7 @@ public class BookInfo { /** * This item library cache state. * - * @return TRUE if it is present in the {@link GuiReader} cache + * @return TRUE if it is present in the {@link CacheLibrary} cache */ public boolean isCached() { return cached; @@ -131,7 +131,7 @@ public class BookInfo { /** * This item library cache state. * - * @param cached TRUE if it is present in the {@link GuiReader} cache + * @param cached TRUE if it is present in the {@link CacheLibrary} cache */ public void setCached(boolean cached) { this.cached = cached; @@ -238,7 +238,7 @@ public class BookInfo { int size = 0; try { - size = lib.getListBySource(source).size(); + size = lib.getList().filter(source, null, null).size(); } catch (IOException e) { } @@ -265,7 +265,7 @@ public class BookInfo { int size = 0; try { - size = lib.getListByAuthor(author).size(); + size = lib.getList().filter(null, author, null).size(); } catch (IOException e) { } @@ -292,11 +292,7 @@ public class BookInfo { int size = 0; try { - for (MetaData meta : lib.getList()) { - if (meta.getTags().contains(tag)) { - size++; - } - } + size = lib.getList().filter(null, null, tag).size(); } catch (IOException e) { } diff --git a/src/be/nikiroo/fanfix_swing/gui/book/BookPopup.java b/src/be/nikiroo/fanfix_swing/gui/book/BookPopup.java index 42f7e3b..c99e273 100644 --- a/src/be/nikiroo/fanfix_swing/gui/book/BookPopup.java +++ b/src/be/nikiroo/fanfix_swing/gui/book/BookPopup.java @@ -69,12 +69,6 @@ public class BookPopup extends JPopupMenu { private Informer informer; - private Object object; - - private Object object2; - - private Object object3; - public BookPopup(BasicLibrary lib, Informer informer) { this.lib = lib; this.informer = informer; @@ -450,9 +444,7 @@ public class BookPopup extends JPopupMenu { // enough, we need to clear the whole cache (for BrowserPanel for instance) informer.invalidateCache(); - // TODO: not enough!! - // after move, item disappears in the list, probably caused by the Library - // itself + // TODO: also refresh the Sources/Authors(/Tags?) list // Even if problems occurred, still invalidate the cache get(); @@ -517,17 +509,17 @@ public class BookPopup extends JPopupMenu { luids.add(book.getMeta().getLuid()); break; case SOURCE: - for (MetaData meta : lib.getListBySource(book.getMainInfo())) { + for (MetaData meta : lib.getList().filter(book.getMainInfo(), null, null)) { luids.add(meta.getLuid()); } break; case AUTHOR: - for (MetaData meta : lib.getListByAuthor(book.getMainInfo())) { + for (MetaData meta : lib.getList().filter(null, book.getMainInfo(), null)) { luids.add(meta.getLuid()); } break; case TAG: - for (MetaData meta : lib.getList(null).filter(null, null, book.getMainInfo())) { + for (MetaData meta : lib.getList().filter(null, null, book.getMainInfo())) { luids.add(meta.getLuid()); } break; -- 2.27.0