From: Niki Roo Date: Tue, 21 Nov 2017 12:31:59 +0000 (+0100) Subject: Fix source/type reset on redownload, show num img X-Git-Tag: fanfix-1.6.1~1 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=c8faa52a7993d29944e505b517619de44ac58279;p=fanfix.git Fix source/type reset on redownload, show num img --- diff --git a/README.md b/README.md index 1d3badf..5badd83 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,7 @@ Currently missing, but either in progress or planned: - [x] New API on FimFiction.net (faster) - [ ] Others? Any ideas? I'm open for requests - [x] [e-Hentai](https://e-hentai.org/) requested + - [ ] Fix "content warning" access - [x] A GUI library - [x] Make one - [x] Make it run when no args passed @@ -153,4 +154,5 @@ Currently missing, but either in progress or planned: - [x] Use a version number - [x] Show it in UI - [x] A check-update feature +- [x] Fix "redownload also reset the source" bug diff --git a/changelog.md b/changelog.md index a4881a1..4f10eca 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,8 @@ ## Version WIP - New option (disabled by default) to show one item per source type in GUI instead of one item per story when showing ALL sources (which is also the start page) +- Fix source/type reset when redownloading +- Show the number of images instead of the number of words for images documents ## Version 1.6.0 diff --git a/src/be/nikiroo/fanfix/DataLoader.java b/src/be/nikiroo/fanfix/DataLoader.java index ef115c9..0f3cad0 100644 --- a/src/be/nikiroo/fanfix/DataLoader.java +++ b/src/be/nikiroo/fanfix/DataLoader.java @@ -231,6 +231,8 @@ public class DataLoader { ImageIO.write(ImageUtils.fromStream(in), Instance.getConfig() .getString(Config.IMAGE_FORMAT_CONTENT).toLowerCase(), target); + } catch (IOException e) { + throw new IOException("Cannot write image " + url, e); } finally { in.close(); } diff --git a/src/be/nikiroo/fanfix/data/Chapter.java b/src/be/nikiroo/fanfix/data/Chapter.java index 86856b0..832994a 100644 --- a/src/be/nikiroo/fanfix/data/Chapter.java +++ b/src/be/nikiroo/fanfix/data/Chapter.java @@ -103,7 +103,7 @@ public class Chapter implements Iterable { } /** - * The number of words in this {@link Chapter}. + * The number of words (or images) in this {@link Chapter}. * * @return the number of words */ @@ -112,7 +112,7 @@ public class Chapter implements Iterable { } /** - * The number of words in this {@link Chapter}. + * The number of words (or images) in this {@link Chapter}. * * @param words * the number of words to set diff --git a/src/be/nikiroo/fanfix/data/Paragraph.java b/src/be/nikiroo/fanfix/data/Paragraph.java index 1a7429a..273aca3 100644 --- a/src/be/nikiroo/fanfix/data/Paragraph.java +++ b/src/be/nikiroo/fanfix/data/Paragraph.java @@ -45,7 +45,7 @@ public class Paragraph { * the image as an URL */ public Paragraph(URL imageUrl) { - this(ParagraphType.IMAGE, imageUrl.toString(), 0); + this(ParagraphType.IMAGE, imageUrl.toString(), 1); } /** @@ -56,7 +56,7 @@ public class Paragraph { * @param content * the content of this paragraph * @param words - * the number of words + * the number of words (or images) */ public Paragraph(ParagraphType type, String content, long words) { this.type = type; @@ -103,7 +103,7 @@ public class Paragraph { } /** - * The number of words in this {@link Paragraph}. + * The number of words (or images) in this {@link Paragraph}. * * @return the number of words */ @@ -112,7 +112,7 @@ public class Paragraph { } /** - * The number of words in this {@link Paragraph}. + * The number of words (or images) in this {@link Paragraph}. * * @param words * the number of words to set diff --git a/src/be/nikiroo/fanfix/reader/GuiReaderBook.java b/src/be/nikiroo/fanfix/reader/GuiReaderBook.java index 29f4c49..782481c 100644 --- a/src/be/nikiroo/fanfix/reader/GuiReaderBook.java +++ b/src/be/nikiroo/fanfix/reader/GuiReaderBook.java @@ -118,12 +118,20 @@ class GuiReaderBook extends JPanel { String optSecondary = meta.getAuthor(); if (seeWordCount) { if (meta.getWords() >= 4000) { - optSecondary = (meta.getWords() / 1000) + "k words"; + optSecondary = "" + (meta.getWords() / 1000) + "k"; } else if (meta.getWords() > 0) { - optSecondary = meta.getWords() + " words"; + optSecondary = "" + meta.getWords(); } else { optSecondary = ""; } + + if (!optSecondary.isEmpty()) { + if (meta.isImageDocument()) { + optSecondary += " images"; + } else { + optSecondary += " words"; + } + } } if (optSecondary != null && !optSecondary.isEmpty()) { diff --git a/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java b/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java index 3b5fca3..87d7075 100644 --- a/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java +++ b/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java @@ -66,6 +66,21 @@ class GuiReaderFrame extends JFrame { private GuiReaderBook selectedBook; private boolean words; // words or authors (secondary info on books) + /** + * A {@link Runnable} with a {@link Story} parameter. + * + * @author niki + */ + private interface StoryRunnable { + /** + * Run the action. + * + * @param story + * the story + */ + public void run(Story story); + } + /** * Create a new {@link GuiReaderFrame}. * @@ -678,11 +693,16 @@ class GuiReaderFrame extends JFrame { public void actionPerformed(ActionEvent e) { if (selectedBook != null) { final MetaData meta = selectedBook.getMeta(); - imprt(meta.getUrl(), new Runnable() { + imprt(meta.getUrl(), new StoryRunnable() { @Override - public void run() { + public void run(Story story) { reader.delete(meta.getLuid()); GuiReaderFrame.this.selectedBook = null; + MetaData newMeta = story.getMeta(); + if (!newMeta.getSource().equals(meta.getSource())) { + reader.changeType(newMeta.getLuid(), + meta.getSource()); + } } }, "Removing old copy"); } @@ -882,7 +902,7 @@ class GuiReaderFrame extends JFrame { * @param onSuccess * Action to execute on success */ - private void imprt(final String url, final Runnable onSuccess, + private void imprt(final String url, final StoryRunnable onSuccess, String onSuccessPgName) { final Progress pg = new Progress(); final Progress pgImprt = new Progress(); @@ -894,8 +914,10 @@ class GuiReaderFrame extends JFrame { @Override public void run() { Exception ex = null; + Story story = null; try { - reader.getLibrary().imprt(BasicReader.getUrl(url), pgImprt); + story = reader.getLibrary().imprt(BasicReader.getUrl(url), + pgImprt); } catch (IOException e) { ex = e; } @@ -917,7 +939,7 @@ class GuiReaderFrame extends JFrame { }); } else { if (onSuccess != null) { - onSuccess.run(); + onSuccess.run(story); } } pgOnSuccess.done();