Fix source/type reset on redownload, show num img
authorNiki Roo <niki@nikiroo.be>
Tue, 21 Nov 2017 12:31:59 +0000 (13:31 +0100)
committerNiki Roo <niki@nikiroo.be>
Tue, 21 Nov 2017 12:31:59 +0000 (13:31 +0100)
README.md
changelog.md
src/be/nikiroo/fanfix/DataLoader.java
src/be/nikiroo/fanfix/data/Chapter.java
src/be/nikiroo/fanfix/data/Paragraph.java
src/be/nikiroo/fanfix/reader/GuiReaderBook.java
src/be/nikiroo/fanfix/reader/GuiReaderFrame.java

index 1d3badff6a91d742945f4b2657b6595d27bcb117..5badd83963befccadf026c4ff9578066817bccfb 100644 (file)
--- 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
 
index a4881a1cbe84efc7d49c2f7f71810deb606ef1b0..4f10eca6c627c57a37001f4974e5428a1610f60f 100644 (file)
@@ -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
 
index ef115c9d60a9b647147fe3dff06c9bf5d95a6283..0f3cad00de0b7a19d11e9ffd95b6421202f7b64a 100644 (file)
@@ -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();
                }
index 86856b0e2c09f5fa6ee1c4faf0f7586c1079dbf7..832994a937d4379d8c3d2105344d8ed2f67eb241 100644 (file)
@@ -103,7 +103,7 @@ public class Chapter implements Iterable<Paragraph> {
        }
 
        /**
-        * 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<Paragraph> {
        }
 
        /**
-        * 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
index 1a7429a403a8a6f0bc0742fb29f14ad2d7811da5..273aca3af7884f4ed3de556b84837465b151015f 100644 (file)
@@ -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
index 29f4c49783a0a727d7c9f08011ee5c8408617c9c..782481c81a8a34104d50db0fd799b08c0bedf74a 100644 (file)
@@ -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()) {
index 3b5fca34bc9de09aeb2dadea9d67a3889dad9838..87d7075ab0a744d13fce7faa512d4312a62de7d4 100644 (file)
@@ -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();