use filter() instead of list()
authorNiki Roo <niki@nikiroo.be>
Wed, 8 Apr 2020 15:47:48 +0000 (17:47 +0200)
committerNiki Roo <niki@nikiroo.be>
Wed, 8 Apr 2020 15:47:48 +0000 (17:47 +0200)
src/be/nikiroo/fanfix_swing/gui/BooksPanel.java
src/be/nikiroo/fanfix_swing/gui/book/BookInfo.java
src/be/nikiroo/fanfix_swing/gui/book/BookPopup.java

index 73de77e974d7e6e313489ffb3b17ba969c1540b5..8a882136e3803e856ea0bd9cc36f862dc9118a04 100644 (file)
@@ -129,7 +129,7 @@ public class BooksPanel extends ListenerPanel {
                        protected List<BookInfo> doInBackground() throws Exception {
                                List<BookInfo> bookInfos = new ArrayList<BookInfo>();
                                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);
                        }
                });
index b7dc509f0c423791dd2693774a61aff9021d675a..de57e848fce3569004134880aa4ad2ba5f5d265f 100644 (file)
@@ -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) {
                }
 
index 42f7e3b7205ef1f6cc43af65eb96d5775cd2bef1..c99e2730c45917359cd8e01043772414d6a08035 100644 (file)
@@ -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;