c163834f493f875755ac0e3d15af12263433d7a2
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 * The type of {@link GuiReaderBookInfo}.
62 public Type
getType() {
67 * Get the main info to display for this book (a title, an author, a
68 * source/type name...).
70 * Note that when {@link MetaData} about the book are present, the title
71 * inside is returned instead of the actual value (that way, we can update
72 * the {@link MetaData} and see the changes here).
74 * @return the main info, usually the title
76 public String
getMainInfo() {
78 return meta
.getTitle();
85 * Get the secondary info, of the given type.
88 * TRUE for word/image/story count, FALSE for author name
90 * @return the secondary info
92 public String
getSecondaryInfo(boolean seeCount
) {
93 String author
= meta
== null ?
null : meta
.getAuthor();
94 String secondaryInfo
= seeCount ? count
: author
;
96 if (secondaryInfo
!= null && !secondaryInfo
.trim().isEmpty()) {
97 secondaryInfo
= "(" + secondaryInfo
+ ")";
102 return secondaryInfo
;
106 * A unique ID for this {@link GuiReaderBookInfo}.
108 * @return the unique ID
110 public String
getId() {
115 * The {@link MetaData} associated with this book, if this book is a
118 * Can be NULL for non-story books (authors or sources/types).
120 * @return the {@link MetaData} or NULL
122 public MetaData
getMeta() {
127 * Get the base image to use to represent this book.
129 * The image is <b>NOT</b> resized in any way, this is the original version.
131 * It can be NULL if no image can be found for this book.
134 * the {@link BasicLibrary} to use to fetch the image
136 * @return the base image
138 * @throws IOException
139 * in case of I/O error
141 public Image
getBaseImage(BasicLibrary lib
) throws IOException
{
144 if (meta
.getCover() != null) {
145 return meta
.getCover();
148 if (meta
.getLuid() != null) {
149 return lib
.getCover(meta
.getLuid());
154 return lib
.getSourceCover(value
);
156 return lib
.getAuthorCover(value
);
163 * Create a new book describing the given {@link Story}.
166 * the {@link MetaData} representing the {@link Story}
170 static public GuiReaderBookInfo
fromMeta(MetaData meta
) {
171 String uid
= meta
.getUuid();
172 if (uid
== null || uid
.trim().isEmpty()) {
173 uid
= meta
.getLuid();
175 if (uid
== null || uid
.trim().isEmpty()) {
179 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.STORY
, uid
,
183 info
.count
= StringUtils
.formatNumber(meta
.getWords());
184 if (!info
.count
.isEmpty()) {
185 info
.count
= GuiReader
.trans(
186 meta
.isImageDocument() ? StringIdGui
.BOOK_COUNT_IMAGES
187 : StringIdGui
.BOOK_COUNT_WORDS
, info
.count
);
194 * Create a new book describing the given source/type.
197 * the {@link BasicLibrary} to use to retrieve some more
198 * information about the source
204 static public GuiReaderBookInfo
fromSource(BasicLibrary lib
, String source
) {
205 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.SOURCE
, "source_"
210 size
= lib
.getListBySource(source
).size();
211 } catch (IOException e
) {
214 info
.count
= StringUtils
.formatNumber(size
);
215 if (!info
.count
.isEmpty()) {
216 info
.count
= GuiReader
.trans(StringIdGui
.BOOK_COUNT_STORIES
,
224 * Create a new book describing the given author.
227 * the {@link BasicLibrary} to use to retrieve some more
228 * information about the author
234 static public GuiReaderBookInfo
fromAuthor(BasicLibrary lib
, String author
) {
235 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.AUTHOR
, "author_"
240 size
= lib
.getListByAuthor(author
).size();
241 } catch (IOException e
) {
244 info
.count
= StringUtils
.formatNumber(size
);
245 if (!info
.count
.isEmpty()) {
246 info
.count
= GuiReader
.trans(StringIdGui
.BOOK_COUNT_STORIES
,