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 * The type of {@link GuiReaderBook} (i.e., related to a story or to something else that
22 * can encompass stories).
27 /** A normal story, which can be "read". */
30 * A special, empty story that represents a source/type common to one or
31 * more normal stories.
34 /** A special, empty story that represents an author. */
43 private MetaData meta
;
46 * For private use, see the "fromXXX" constructors instead for public use.
51 * the main id, which must uniquely identify this book and will
52 * be used as a unique ID later on
54 * the main value to show (see
55 * {@link GuiReaderBookInfo#getMainInfo()})
57 private GuiReaderBookInfo(Type type
, String id
, String value
) {
64 * The type of {@link GuiReaderBookInfo}.
68 public Type
getType() {
73 * Get the main info to display for this book (a title, an author, a
74 * source/type name...).
76 * Note that when {@link MetaData} about the book are present, the title
77 * inside is returned instead of the actual value (that way, we can update
78 * the {@link MetaData} and see the changes here).
80 * @return the main info, usually the title
82 public String
getMainInfo() {
84 return meta
.getTitle();
91 * Get the secondary info, of the given type.
94 * TRUE for word/image/story count, FALSE for author name
96 * @return the secondary info
98 public String
getSecondaryInfo(boolean seeCount
) {
99 String author
= meta
== null ?
null : meta
.getAuthor();
100 String secondaryInfo
= seeCount ? count
: author
;
102 if (secondaryInfo
!= null && !secondaryInfo
.trim().isEmpty()) {
103 secondaryInfo
= "(" + secondaryInfo
+ ")";
108 return secondaryInfo
;
112 * A unique ID for this {@link GuiReaderBookInfo}.
114 * @return the unique ID
116 public String
getId() {
121 * The {@link MetaData} associated with this book, if this book is a
124 * Can be NULL for non-story books (authors or sources/types).
126 * @return the {@link MetaData} or NULL
128 public MetaData
getMeta() {
133 * Get the base image to use to represent this book.
135 * The image is <b>NOT</b> resized in any way, this is the original version.
137 * It can be NULL if no image can be found for this book.
140 * the {@link BasicLibrary} to use to fetch the image
142 * @return the base image
144 * @throws IOException
145 * in case of I/O error
147 public Image
getBaseImage(BasicLibrary lib
) throws IOException
{
150 if (meta
.getCover() != null) {
151 return meta
.getCover();
154 if (meta
.getLuid() != null) {
155 return lib
.getCover(meta
.getLuid());
160 return lib
.getSourceCover(value
);
162 return lib
.getAuthorCover(value
);
169 * Create a new book describing the given {@link Story}.
172 * the {@link MetaData} representing the {@link Story}
176 static public GuiReaderBookInfo
fromMeta(MetaData meta
) {
177 String uid
= meta
.getUuid();
178 if (uid
== null || uid
.trim().isEmpty()) {
179 uid
= meta
.getLuid();
181 if (uid
== null || uid
.trim().isEmpty()) {
185 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.STORY
, uid
,
189 info
.count
= StringUtils
.formatNumber(meta
.getWords());
190 if (!info
.count
.isEmpty()) {
191 info
.count
= GuiReader
.trans(
192 meta
.isImageDocument() ? StringIdGui
.BOOK_COUNT_IMAGES
193 : StringIdGui
.BOOK_COUNT_WORDS
, info
.count
);
200 * Create a new book describing the given source/type.
203 * the {@link BasicLibrary} to use to retrieve some more
204 * information about the source
210 static public GuiReaderBookInfo
fromSource(BasicLibrary lib
, String source
) {
211 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.SOURCE
, "source_"
216 size
= lib
.getList().filter(source
, null, null).size();
217 } catch (IOException e
) {
220 info
.count
= StringUtils
.formatNumber(size
);
221 if (!info
.count
.isEmpty()) {
222 info
.count
= GuiReader
.trans(StringIdGui
.BOOK_COUNT_STORIES
,
230 * Create a new book describing the given author.
233 * the {@link BasicLibrary} to use to retrieve some more
234 * information about the author
240 static public GuiReaderBookInfo
fromAuthor(BasicLibrary lib
, String author
) {
241 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.AUTHOR
, "author_"
246 size
= lib
.getList().filter(null, author
, null).size();
247 } catch (IOException e
) {
250 info
.count
= StringUtils
.formatNumber(size
);
251 if (!info
.count
.isEmpty()) {
252 info
.count
= GuiReader
.trans(StringIdGui
.BOOK_COUNT_STORIES
,