X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FBasicLibrary.java;h=78d20d654afee85ec8e1f0826abd156576fe821e;hb=c956ff52ac789f80c9b694a8f74ca8f1f47db67c;hp=6dfacfbf4b8f0d5d19eabdcfe7f21d2315a2ce0e;hpb=3a0605e6a05e6d9dee6b596d5f9b193408470164;p=nikiroo-utils.git
diff --git a/src/be/nikiroo/fanfix/library/BasicLibrary.java b/src/be/nikiroo/fanfix/library/BasicLibrary.java
index 6dfacfb..78d20d6 100644
--- a/src/be/nikiroo/fanfix/library/BasicLibrary.java
+++ b/src/be/nikiroo/fanfix/library/BasicLibrary.java
@@ -4,11 +4,11 @@ import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.UnknownHostException;
-import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.Map.Entry;
+import java.util.Map;
+import java.util.TreeMap;
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.data.MetaData;
@@ -119,6 +119,31 @@ abstract public class BasicLibrary {
return null;
}
+ /**
+ * Return the cover image associated to this author.
+ *
+ * By default, return the custom cover if any, and if not, return the cover
+ * of the first story with this author.
+ *
+ * @param author
+ * the author
+ *
+ * @return the cover image or NULL
+ */
+ public Image getAuthorCover(String author) {
+ Image custom = getCustomAuthorCover(author);
+ if (custom != null) {
+ return custom;
+ }
+
+ List metas = getListByAuthor(author);
+ if (metas.size() > 0) {
+ return getCover(metas.get(0).getLuid());
+ }
+
+ return null;
+ }
+
/**
* Return the custom cover image associated to this source.
*
@@ -134,7 +159,21 @@ abstract public class BasicLibrary {
}
/**
- * Fix the source cover to the given story cover.
+ * Return the custom cover image associated to this author.
+ *
+ * By default, return NULL.
+ *
+ * @param author
+ * the author to look for
+ *
+ * @return the custom cover or NULL if none
+ */
+ public Image getCustomAuthorCover(@SuppressWarnings("unused") String author) {
+ return null;
+ }
+
+ /**
+ * Set the source cover to the given story cover.
*
* @param source
* the source to change
@@ -143,6 +182,16 @@ abstract public class BasicLibrary {
*/
public abstract void setSourceCover(String source, String luid);
+ /**
+ * Set the author cover to the given story cover.
+ *
+ * @param source
+ * the author to change
+ * @param luid
+ * the story LUID
+ */
+ public abstract void setAuthorCover(String author, String luid);
+
/**
* Return the list of stories (represented by their {@link MetaData}, which
* MAY not have the cover included).
@@ -246,6 +295,47 @@ abstract public class BasicLibrary {
return list;
}
+ /**
+ * List all the known types (sources) of stories, grouped by directory
+ * ("Source_1/a" and "Source_1/b" will be grouped into "Source_1").
+ *
+ * Note that an empty item in the list means a non-grouped source (type) --
+ * e.g., you could have for Source_1:
+ *
+ * - : empty, so source is "Source_1"
+ * - a: empty, so source is "Source_1/a"
+ * - b: empty, so source is "Source_1/b"
+ *
+ *
+ * @return the grouped list
+ */
+ public synchronized Map> getSourcesGrouped() {
+ Map> map = new TreeMap>();
+ for (String source : getSources()) {
+ String name;
+ String subname;
+
+ int pos = source.indexOf('/');
+ if (pos > 0 && pos < source.length() - 1) {
+ name = source.substring(0, pos);
+ subname = source.substring(pos + 1);
+
+ } else {
+ name = source;
+ subname = "";
+ }
+
+ List list = map.get(name);
+ if (list == null) {
+ list = new ArrayList();
+ map.put(name, list);
+ }
+ list.add(subname);
+ }
+
+ return map;
+ }
+
/**
* List all the known authors of stories.
*
@@ -283,48 +373,60 @@ abstract public class BasicLibrary {
*
* @return the authors' names, grouped by letter(s)
*/
- public List>> getAuthorsGrouped() {
+ public Map> getAuthorsGrouped() {
int MAX = 20;
- List>> groups = new ArrayList>>();
+ Map> groups = new TreeMap>();
List authors = getAuthors();
+ // If all authors fit the max, just report them as is
if (authors.size() <= MAX) {
- groups.add(new SimpleEntry>("", authors));
+ groups.put("", authors);
return groups;
}
- groups.add(new SimpleEntry>("*", getAuthorsGroup(
- authors, '*')));
- groups.add(new SimpleEntry>("0-9",
- getAuthorsGroup(authors, '0')));
-
+ // Create groups A to Z, which can be empty here
for (char car = 'A'; car <= 'Z'; car++) {
- groups.add(new SimpleEntry>(Character
- .toString(car), getAuthorsGroup(authors, car)));
+ groups.put(Character.toString(car), getAuthorsGroup(authors, car));
}
- // do NOT collapse * and [0-9] with the rest
- for (int i = 2; i + 1 < groups.size(); i++) {
- Entry> now = groups.get(i);
- Entry> next = groups.get(i + 1);
- int currentTotal = now.getValue().size() + next.getValue().size();
+ // Collapse them
+ List keys = new ArrayList(groups.keySet());
+ for (int i = 0; i + 1 < keys.size(); i++) {
+ String keyNow = keys.get(i);
+ String keyNext = keys.get(i + 1);
+
+ List now = groups.get(keyNow);
+ List next = groups.get(keyNext);
+
+ int currentTotal = now.size() + next.size();
if (currentTotal <= MAX) {
- String key = now.getKey().charAt(0) + "-"
- + next.getKey().charAt(next.getKey().length() - 1);
+ String key = keyNow.charAt(0) + "-"
+ + keyNext.charAt(keyNext.length() - 1);
+
List all = new ArrayList();
- all.addAll(now.getValue());
- all.addAll(next.getValue());
- groups.set(i, new SimpleEntry>(key, all));
- groups.remove(i + 1);
- i--;
+ all.addAll(now);
+ all.addAll(next);
+
+ groups.remove(keyNow);
+ groups.remove(keyNext);
+ groups.put(key, all);
+
+ keys.set(i, key); // set the new key instead of key(i)
+ keys.remove(i + 1); // remove the next, consumed key
+ i--; // restart at key(i)
}
}
- for (int i = 0; i < groups.size(); i++) {
- if (groups.get(i).getValue().size() == 0) {
- groups.remove(i);
- i--;
+ // Add "special" groups
+ groups.put("*", getAuthorsGroup(authors, '*'));
+ groups.put("0-9", getAuthorsGroup(authors, '0'));
+
+ // Prune empty groups
+ keys = new ArrayList(groups.keySet());
+ for (String key : keys) {
+ if (groups.get(key).isEmpty()) {
+ groups.remove(key);
}
}