From d8562d48a705ea1b59128203f48bf4499f9cf0c0 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Thu, 30 Apr 2020 23:22:14 +0200 Subject: [PATCH] fix importer name --- .../gui/importer/ImporterFrame.java | 26 ++++++++++++++----- .../gui/importer/ImporterItem.java | 25 +++++++++--------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/be/nikiroo/fanfix_swing/gui/importer/ImporterFrame.java b/src/be/nikiroo/fanfix_swing/gui/importer/ImporterFrame.java index 1216d806..329c42a1 100644 --- a/src/be/nikiroo/fanfix_swing/gui/importer/ImporterFrame.java +++ b/src/be/nikiroo/fanfix_swing/gui/importer/ImporterFrame.java @@ -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() { @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; } }); } diff --git a/src/be/nikiroo/fanfix_swing/gui/importer/ImporterItem.java b/src/be/nikiroo/fanfix_swing/gui/importer/ImporterItem.java index ae81355d..bc734662 100644 --- a/src/be/nikiroo/fanfix_swing/gui/importer/ImporterItem.java +++ b/src/be/nikiroo/fanfix_swing/gui/importer/ImporterItem.java @@ -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() { -- 2.27.0