1 package be
.nikiroo
.fanfix
.reader
.ui
;
3 import java
.io
.IOException
;
5 import be
.nikiroo
.fanfix
.bundles
.StringIdGui
;
6 import be
.nikiroo
.fanfix
.data
.MetaData
;
7 import be
.nikiroo
.fanfix
.data
.Story
;
8 import be
.nikiroo
.fanfix
.library
.BasicLibrary
;
9 import be
.nikiroo
.utils
.Image
;
10 import be
.nikiroo
.utils
.StringUtils
;
13 * Some meta information related to a "book" (which can either be a
14 * {@link Story}, a fake-story grouping some authors or a fake-story grouping
15 * some sources/types).
19 public class GuiReaderBookInfo
{
21 /** A normal story, which can be "read". */
24 * A special, empty story that represents a source/type common to one or
25 * more normal stories.
28 /** A special, empty story that represents an author. */
37 private MetaData meta
;
40 * For private use, see the "fromXXX" constructors instead for public use.
45 * the main id, which must uniquely identify this book and will
46 * be used as a unique ID later on
48 * the main value to show (see
49 * {@link GuiReaderBookInfo#getMainInfo()})
51 private GuiReaderBookInfo(Type type
, String id
, String value
) {
58 * Get the main info to display for this book (a title, an author, a
59 * source/type name...).
61 * Note that when {@link MetaData} about the book are present, the title
62 * inside is returned instead of the actual value (that way, we can update
63 * the {@link MetaData} and see the changes here).
65 * @return the main info, usually the title
67 public String
getMainInfo() {
69 return meta
.getTitle();
76 * Get the secondary info, of the given type.
79 * TRUE for word/image/story count, FALSE for author name
81 * @return the secondary info
83 public String
getSecondaryInfo(boolean seeCount
) {
84 String author
= meta
== null ?
null : meta
.getAuthor();
85 String secondaryInfo
= seeCount ? count
: author
;
87 if (secondaryInfo
!= null && !secondaryInfo
.trim().isEmpty()) {
88 secondaryInfo
= "(" + secondaryInfo
+ ")";
97 * A unique ID for this {@link GuiReaderBookInfo}.
99 * @return the unique ID
101 public String
getId() {
106 * The {@link MetaData} associated with this book, if this book is a
109 * Can be NULL for non-story books (authors or sources/types).
111 * @return the {@link MetaData} or NULL
113 public MetaData
getMeta() {
118 * Get the base image to use to represent this book.
120 * The image is <b>NOT</b> resized in any way, this is the original version.
122 * It can be NULL if no image can be found for this book.
125 * the {@link BasicLibrary} to use to fetch the image
127 * @return the base image
129 * @throws IOException
130 * in case of I/O error
132 public Image
getBaseImage(BasicLibrary lib
) throws IOException
{
135 if (meta
.getCover() != null) {
136 return meta
.getCover();
139 if (meta
.getLuid() != null) {
140 return lib
.getCover(meta
.getLuid());
145 return lib
.getSourceCover(value
);
147 return lib
.getAuthorCover(value
);
154 * Create a new book describing the given {@link Story}.
157 * the {@link MetaData} representing the {@link Story}
161 static public GuiReaderBookInfo
fromMeta(MetaData meta
) {
162 String uid
= meta
.getUuid();
163 if (uid
== null || uid
.trim().isEmpty()) {
164 uid
= meta
.getLuid();
166 if (uid
== null || uid
.trim().isEmpty()) {
170 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.STORY
, uid
,
174 info
.count
= StringUtils
.formatNumber(meta
.getWords());
175 if (!info
.count
.isEmpty()) {
176 info
.count
= GuiReader
.trans(
177 meta
.isImageDocument() ? StringIdGui
.BOOK_COUNT_IMAGES
178 : StringIdGui
.BOOK_COUNT_WORDS
, info
.count
);
185 * Create a new book describing the given source/type.
188 * the {@link BasicLibrary} to use to retrieve some more
189 * information about the source
195 static public GuiReaderBookInfo
fromSource(BasicLibrary lib
, String source
) {
196 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.SOURCE
, "source_"
201 size
= lib
.getListBySource(source
).size();
202 } catch (IOException e
) {
205 info
.count
= StringUtils
.formatNumber(size
);
206 if (!info
.count
.isEmpty()) {
207 info
.count
= GuiReader
.trans(StringIdGui
.BOOK_COUNT_STORIES
,
215 * Create a new book describing the given author.
218 * the {@link BasicLibrary} to use to retrieve some more
219 * information about the author
225 static public GuiReaderBookInfo
fromAuthor(BasicLibrary lib
, String author
) {
226 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.AUTHOR
, "author_"
231 size
= lib
.getListByAuthor(author
).size();
232 } catch (IOException e
) {
235 info
.count
= StringUtils
.formatNumber(size
);
236 if (!info
.count
.isEmpty()) {
237 info
.count
= GuiReader
.trans(StringIdGui
.BOOK_COUNT_STORIES
,