Merge branch 'subtree'
authorNiki Roo <niki@nikiroo.be>
Sat, 2 May 2020 11:24:58 +0000 (13:24 +0200)
committerNiki Roo <niki@nikiroo.be>
Sat, 2 May 2020 11:24:58 +0000 (13:24 +0200)
1  2 
src/be/nikiroo/fanfix/bundles/UiConfig.java
src/be/nikiroo/fanfix/supported/BasicSupport.java
src/be/nikiroo/fanfix/supported/BasicSupportHelper.java
src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java
src/be/nikiroo/fanfix/supported/E621.java
src/be/nikiroo/fanfix/supported/FimfictionApi.java
src/be/nikiroo/fanfix/supported/InfoReader.java
src/be/nikiroo/fanfix/supported/MangaLel.java
src/be/nikiroo/fanfix/supported/Text.java

index dd7bbc7032b4a1b2dfc4b9e29991fd131aeeafad,0f3142d3f5552833c162c846122061b9a347e9da..0f3142d3f5552833c162c846122061b9a347e9da
@@@ -31,7 -31,26 +31,26 @@@ public enum UiConfig 
        @Meta(description = "The external viewer for non-images documents (or empty to use the system default program for the given file type)",//
        format = Format.STRING)
        NON_IMAGES_DOCUMENT_READER, //
+       //
+       // GUI settings (hidden in config)
+       //
+       @Meta(description = "Show the side panel by default",//
+       hidden = true, format = Format.BOOLEAN, def = "true")
+       SHOW_SIDE_PANEL, //
+       @Meta(description = "Show the details panel by default",//
+       hidden = true, format = Format.BOOLEAN, def = "true")
+       SHOW_DETAILS_PANEL, //
+       @Meta(description = "Show thumbnails by default in the books view",//
+       hidden = true, format = Format.BOOLEAN, def = "false")
+       SHOW_THUMBNAILS, //
+       @Meta(description = "Show a words/images count instead of the author by default in the books view",//
+       hidden = true, format = Format.BOOLEAN, def = "false")
+       SHOW_WORDCOUNT, //
+       //
+       // Deprecated
+       //
        @Meta(description = "The background colour of the library if you don't like the default system one",//
        hidden = true, format = Format.COLOR)
+       @Deprecated
        BACKGROUND_COLOR, //
  }
index 900bcf9d5c2f59cb34b6879416b0e52565db769b,0a5ec3686e1be43c52a328d1a1be86e805ad21fe..0a5ec3686e1be43c52a328d1a1be86e805ad21fe
@@@ -272,8 -272,10 +272,10 @@@ public abstract class BasicSupport 
  
                Story story = new Story();
                MetaData meta = getMeta();
-               if (meta.getCreationDate() == null || meta.getCreationDate().isEmpty()) {
-                       meta.setCreationDate(StringUtils.fromTime(new Date().getTime()));
+               if (meta.getCreationDate() == null
+                               || meta.getCreationDate().trim().isEmpty()) {
+                       meta.setCreationDate(bsHelper
+                                       .formatDate(StringUtils.fromTime(new Date().getTime())));
                }
                story.setMeta(meta);
                pg.put("meta", meta);
index b5c7bb9cdee9ccaf96c1de6c38eeb4aaa76a9537,7768052cafc758094e38c1968f5919f6b853b8bc..7768052cafc758094e38c1968f5919f6b853b8bc
@@@ -5,10 -5,14 +5,14 @@@ import java.io.IOException
  import java.io.InputStream;
  import java.net.MalformedURLException;
  import java.net.URL;
+ import java.text.ParseException;
+ import java.text.SimpleDateFormat;
+ import java.util.Date;
  
  import be.nikiroo.fanfix.Instance;
  import be.nikiroo.fanfix.bundles.Config;
  import be.nikiroo.utils.Image;
+ import be.nikiroo.utils.StringUtils;
  
  /**
   * Helper class for {@link BasicSupport}, mostly dedicated to text formating for
@@@ -220,4 -224,58 +224,58 @@@ public class BasicSupportHelper 
  
                return author;
        }
+       
+       /**
+        * Try to convert the date to a known, fixed format.
+        * <p>
+        * If it fails to do so, it will return the date as-is.
+        * 
+        * @param date
+        *            the date to convert
+        * 
+        * @return the converted date, or the date as-is
+        */
+       public String formatDate(String date) {
+               long ms = 0;
+               if (date != null && !date.isEmpty()) {
+                       // Default Fanfix format:
+                       try {
+                               ms = StringUtils.toTime(date);
+                       } catch (ParseException e) {
+                       }
+                       // Second chance:
+                       if (ms <= 0) {
+                               SimpleDateFormat sdf = new SimpleDateFormat(
+                                               "yyyy-MM-dd'T'HH:mm:ssSSS");
+                               try {
+                                       ms = sdf.parse(date).getTime();
+                               } catch (ParseException e) {
+                               }
+                       }
+                       // Last chance:
+                       if (ms <= 0 && date.length() >= 10) {
+                               SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+                               try {
+                                       ms = sdf.parse(date.substring(0, 10)).getTime();
+                               } catch (ParseException e) {
+                               }
+                       }
+                       // If we found something, use THIS format:
+                       if (ms > 0) {
+                               SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+                               return sdf.format(new Date(ms));
+                       }
+               }
+               if (date == null) {
+                       date = "";
+               }
+               // :(
+               return date;
+       }
  }
index 47cb7a2c94ed2b965e865e398638d683a8967898,bc3738a211bc22b92ac8811e85a549dd17777618..bc3738a211bc22b92ac8811e85a549dd17777618
@@@ -205,8 -205,9 +205,9 @@@ public abstract class BasicSupport_Depr
                        Story story = new Story();
                        MetaData meta = getMeta(url, getInput());
                        if (meta.getCreationDate() == null
-                                       || meta.getCreationDate().isEmpty()) {
-                               meta.setCreationDate(StringUtils.fromTime(new Date().getTime()));
+                                       || meta.getCreationDate().trim().isEmpty()) {
+                               meta.setCreationDate(bsHelper.formatDate(
+                                               StringUtils.fromTime(new Date().getTime())));
                        }
                        story.setMeta(meta);
                        pg.put("meta", meta);
index a019d0ced94881236adb246c517976b75cab737d,dc7cb1b3b8b6e468f0a44ecc091dabf6c5f9a6e7..dc7cb1b3b8b6e468f0a44ecc091dabf6c5f9a6e7
@@@ -61,7 -61,7 +61,7 @@@ class E621 extends BasicSupport 
  
                meta.setTitle(getTitle());
                meta.setAuthor(getAuthor());
-               meta.setDate(getDate());
+               meta.setDate(bsHelper.formatDate(getDate()));
                meta.setTags(getTags());
                meta.setSource(getType().getSourceName());
                meta.setUrl(getSource().toString());
                                // Can be NULL if filtered
                                // When the value is NULL, we get an exception
                                // but the "has" method still returns true
+                               Instance.getInstance().getTraceHandler()
+                                               .error("Cannot get image for chapter " + number + " of "
+                                                               + getSource());
                        }
                }
  
index 6c6d7ba31caf2197356b68168447c7871b257a52,43d01d19494f616c6811e5757da4a6f2e14c83cc..43d01d19494f616c6811e5757da4a6f2e14c83cc
@@@ -124,7 -124,8 +124,8 @@@ class FimfictionApi extends BasicSuppor
  
                meta.setTitle(getKeyJson(json, 0, "type", "story", "title"));
                meta.setAuthor(getKeyJson(json, 0, "type", "user", "name"));
-               meta.setDate(getKeyJson(json, 0, "type", "story", "date_published"));
+               meta.setDate(bsHelper.formatDate(
+                               getKeyJson(json, 0, "type", "story", "date_published")));
                meta.setTags(getTags());
                meta.setSource(getType().getSourceName());
                meta.setUrl(getSource().toString());
index 405b28fb4197be856192e3b8ad31a219f4636cc5,206464f45a0a2e7c989e6fa6719afa22ca61c9cb..206464f45a0a2e7c989e6fa6719afa22ca61c9cb
@@@ -138,7 -138,7 +138,7 @@@ public class InfoReader 
  
                meta.setTitle(getInfoTag(in, "TITLE"));
                meta.setAuthor(getInfoTag(in, "AUTHOR"));
-               meta.setDate(getInfoTag(in, "DATE"));
+               meta.setDate(bsHelper.formatDate(getInfoTag(in, "DATE")));
                meta.setTags(getInfoTagList(in, "TAGS", ","));
                meta.setSource(getInfoTag(in, "SOURCE"));
                meta.setUrl(getInfoTag(in, "URL"));
                } catch (NumberFormatException e) {
                        meta.setWords(0);
                }
-               meta.setCreationDate(getInfoTag(in, "CREATION_DATE"));
+               meta.setCreationDate(
+                               bsHelper.formatDate(getInfoTag(in, "CREATION_DATE")));
                meta.setFakeCover(Boolean.parseBoolean(getInfoTag(in, "FAKE_COVER")));
  
                if (withCover && meta.getCover() == null) {
index 9929699cc43839b93e1b98752d205d562a08a845,de0b871331ef313b6be628c382c9487f281b5c3e..de0b871331ef313b6be628c382c9487f281b5c3e
@@@ -32,7 -32,7 +32,7 @@@ class MangaLel extends BasicSupport 
  
                meta.setTitle(getTitle());
                meta.setAuthor(getAuthor());
-               meta.setDate(getDate());
+               meta.setDate(bsHelper.formatDate(getDate()));
                meta.setTags(getTags());
                meta.setSource(getType().getSourceName());
                meta.setUrl(getSource().toString());
                        }
                }
  
-               if (!value.isEmpty()) {
-                       try {
-                               long time = StringUtils.toTime(value);
-                               value = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
-                                               .format(time);
-                       } catch (ParseException e) {
-                       }
-               }
                return value;
        }
  
index e082a737f2a7be9c11b9fc133bea0c96f108ae55,ade797fbf71ae3182a05ced4a6f0fdbb74b1f118..ade797fbf71ae3182a05ced4a6f0fdbb74b1f118
@@@ -85,7 -85,7 +85,7 @@@ class Text extends BasicSupport 
  
                meta.setTitle(getTitle());
                meta.setAuthor(getAuthor());
-               meta.setDate(getDate());
+               meta.setDate(bsHelper.formatDate(getDate()));
                meta.setTags(new ArrayList<String>());
                meta.setSource(getType().getSourceName());
                meta.setUrl(getSourceFile().toURI().toURL().toString());