1 package be
.nikiroo
.fanfix
.reader
.ui
;
3 import be
.nikiroo
.fanfix
.bundles
.StringIdGui
;
4 import be
.nikiroo
.fanfix
.data
.MetaData
;
5 import be
.nikiroo
.fanfix
.data
.Story
;
6 import be
.nikiroo
.fanfix
.library
.BasicLibrary
;
7 import be
.nikiroo
.utils
.Image
;
8 import be
.nikiroo
.utils
.StringUtils
;
11 * Some meta information related to a "book" (which can either be a
12 * {@link Story}, a fake-story grouping some authors or a fake-story grouping
13 * some sources/types).
17 public class GuiReaderBookInfo
{
19 /** A normal story, which can be "read". */
22 * A special, empty story that represents a source/type common to one or
23 * more normal stories.
26 /** A special, empty story that represents an author. */
35 private MetaData meta
;
38 * For private use, see the "fromXXX" constructors instead for public use.
43 * the main id, which must uniquely identify this book and will
44 * be used as a unique ID later on
46 * the main value to show (see
47 * {@link GuiReaderBookInfo#getMainInfo()})
49 private GuiReaderBookInfo(Type type
, String id
, String value
) {
56 * Get the main info to display for this book (a title, an author, a
57 * source/type name...).
59 * Note that when {@link MetaData} about the book are present, the title
60 * inside is returned instead of the actual value (that way, we can update
61 * the {@link MetaData} and see the changes here).
63 * @return the main info, usually the title
65 public String
getMainInfo() {
67 return meta
.getTitle();
74 * Get the secondary info, of the given type.
77 * TRUE for word/image/story count, FALSE for author name
79 * @return the secondary info
81 public String
getSecondaryInfo(boolean seeCount
) {
82 String author
= meta
== null ?
null : meta
.getAuthor();
83 String secondaryInfo
= seeCount ? count
: author
;
85 if (secondaryInfo
!= null && !secondaryInfo
.trim().isEmpty()) {
86 secondaryInfo
= "(" + secondaryInfo
+ ")";
95 * A unique ID for this {@link GuiReaderBookInfo}.
97 * @return the unique ID
99 public String
getId() {
104 * The {@link MetaData} associated with this book, if this book is a
107 * Can be NULL for non-story books (authors or sources/types).
109 * @return the {@link MetaData} or NULL
111 public MetaData
getMeta() {
116 * Get the base image to use to represent this book.
118 * The image is <b>NOT</b> resized in any way, this is the original version.
120 * It can be NULL if no image can be found for this book.
123 * the {@link BasicLibrary} to use to fetch the image
125 * @return the base image
127 public Image
getBaseImage(BasicLibrary lib
) {
130 if (meta
.getCover() != null) {
131 return meta
.getCover();
134 if (meta
.getLuid() != null) {
135 return lib
.getCover(meta
.getLuid());
140 return lib
.getSourceCover(value
);
142 return lib
.getAuthorCover(value
);
149 * Create a new book describing the given {@link Story}.
152 * the {@link MetaData} representing the {@link Story}
156 static public GuiReaderBookInfo
fromMeta(MetaData meta
) {
157 String uid
= meta
.getUuid();
158 if (uid
== null || uid
.trim().isEmpty()) {
159 uid
= meta
.getLuid();
161 if (uid
== null || uid
.trim().isEmpty()) {
165 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.STORY
, uid
,
169 info
.count
= StringUtils
.formatNumber(meta
.getWords());
170 if (!info
.count
.isEmpty()) {
171 info
.count
= GuiReader
.trans(
172 meta
.isImageDocument() ? StringIdGui
.BOOK_COUNT_IMAGES
173 : StringIdGui
.BOOK_COUNT_WORDS
, info
.count
);
180 * Create a new book describing the given source/type.
183 * the {@link BasicLibrary} to use to retrieve some more
184 * information about the source
190 static public GuiReaderBookInfo
fromSource(BasicLibrary lib
, String source
) {
191 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.SOURCE
, "source_"
194 info
.count
= StringUtils
.formatNumber(lib
.getListBySource(source
)
196 if (!info
.count
.isEmpty()) {
197 info
.count
= GuiReader
.trans(StringIdGui
.BOOK_COUNT_STORIES
,
205 * Create a new book describing the given author.
208 * the {@link BasicLibrary} to use to retrieve some more
209 * information about the author
215 static public GuiReaderBookInfo
fromAuthor(BasicLibrary lib
, String author
) {
216 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.AUTHOR
, "author_"
219 info
.count
= StringUtils
.formatNumber(lib
.getListByAuthor(author
)
221 if (!info
.count
.isEmpty()) {
222 info
.count
= GuiReader
.trans(StringIdGui
.BOOK_COUNT_STORIES
,