fix importer name
authorNiki Roo <niki@nikiroo.be>
Thu, 30 Apr 2020 21:22:14 +0000 (23:22 +0200)
committerNiki Roo <niki@nikiroo.be>
Thu, 30 Apr 2020 21:22:14 +0000 (23:22 +0200)
src/be/nikiroo/fanfix_swing/gui/importer/ImporterFrame.java
src/be/nikiroo/fanfix_swing/gui/importer/ImporterItem.java

index 1216d8066d51a0292659425f22d4c6cd24015c9a..329c42a16f9373518428c42c02bea8fc4d378e0d 100644 (file)
@@ -145,7 +145,7 @@ public class ImporterFrame extends JFrame implements ListenerItem {
                        Object url = fc.getSelectedFile().getAbsolutePath();
                        if (url != null && !url.toString().isEmpty()) {
                                Progress pg = new Progress();
-                               add(pg, "File");
+                               add(pg, "File", fc.getSelectedFile().getName());
 
                                Actions.imprt(parent, url.toString(), pg, new Runnable() {
                                        @Override
@@ -184,7 +184,7 @@ public class ImporterFrame extends JFrame implements ListenerItem {
                }
 
                if (url != null && !url.isEmpty()) {
-                       add(pg, basename);
+                       add(pg, basename, null);
 
                        Actions.imprt(parent, url, pg, new Runnable() {
                                @Override
@@ -197,8 +197,8 @@ public class ImporterFrame extends JFrame implements ListenerItem {
                }
        }
 
-       private void add(Progress pg, final String basename) {
-               final ImporterItem item = new ImporterItem(pg, basename);
+       private void add(Progress pg, final String basename, String storyName) {
+               final ImporterItem item = new ImporterItem(pg, basename, storyName);
                item.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
@@ -214,9 +214,21 @@ public class ImporterFrame extends JFrame implements ListenerItem {
                data.filter(new Predicate<ImporterItem>() {
                        @Override
                        public boolean test(ImporterItem item) {
-                               String text = item.getStoryName() + " " + item.getAction();
-                               return filter.isEmpty() || text.isEmpty()
-                                               || text.toLowerCase().contains(filter.toLowerCase());
+                               if (filter.isEmpty())
+                                       return true;
+
+                               if (item.getStoryName().isEmpty() && item.getAction().isEmpty())
+                                       return true;
+
+                               if (item.getStoryName().toLowerCase()
+                                               .contains(filter.toLowerCase()))
+                                       return true;
+
+                               if (item.getAction().toLowerCase()
+                                               .contains(filter.toLowerCase()))
+                                       return true;
+
+                               return false;
                        }
                });
        }
index ae81355db874e189708874b9d846ee8c7a5b90e2..bc734662bd1a168de7e55862ea2ce89a24a70d09 100644 (file)
@@ -9,6 +9,7 @@ import java.awt.Rectangle;
 import javax.swing.JLabel;
 import javax.swing.SwingUtilities;
 
+import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix_swing.gui.utils.CoverImager;
 import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.Progress.ProgressListener;
@@ -30,8 +31,9 @@ public class ImporterItem extends ListenerPanel implements Hoverable {
        private JLabel labelName;
        private JLabel labelAction;
 
-       public ImporterItem(Progress pg, String basename) {
+       public ImporterItem(Progress pg, String basename, String storyName) {
                this.basename = basename == null ? "" : basename;
+               this.storyName = storyName == null ? "" : storyName;
 
                labelName = new JLabel(getStoryName());
                labelAction = new JLabel(getAction());
@@ -115,22 +117,21 @@ public class ImporterItem extends ListenerPanel implements Hoverable {
                pg.addProgressListener(new ProgressListener() {
                        @Override
                        public void progress(Progress notUsed, String currentAction) {
-                               // TODO: get/setSubject on Progress?
                                currentAction = currentAction == null ? "" : currentAction;
-
-                               if (storyName.isEmpty()
-                                               && !currentAction.equals("Initialising")) {
-                                       storyName = currentAction;
-                               }
-
-                               if (storyName.equals(currentAction)) {
-                                       currentAction = "";
+                               String currentStoryName = null;
+                               
+                               MetaData meta = (MetaData)pg.get("meta");
+                               if (meta != null) {
+                                       currentStoryName = meta.getTitle();
                                }
-
+                               
                                if (pg.getRelativeProgress() != progress
-                                               || !action.equals(currentAction)) {
+                                               || !action.equals(currentAction)
+                                               || !storyName.equals(currentStoryName)) {
                                        progress = pg.getRelativeProgress();
                                        action = currentAction;
+                                       storyName = currentStoryName == null ? ""
+                                                       : currentStoryName;
 
                                        // The rest must be done in the UI thread
                                        SwingUtilities.invokeLater(new Runnable() {