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
;
10 * Some meta information related to a "book" (which can either be a
11 * {@link Story}, a fake-story grouping some authors or a fake-story grouping
12 * some sources/types).
16 public class GuiReaderBookInfo
{
18 /** A normal story, which can be "read". */
21 * A special, empty story that represents a source/type common to one or
22 * more normal stories.
25 /** A special, empty story that represents an author. */
34 private MetaData meta
;
37 * For private use, see the "fromXXX" constructors instead for public use.
42 * the main id, which must uniquely identify this book and will
43 * be used as a unique ID later on
45 * the main value to show (see
46 * {@link GuiReaderBookInfo#getMainInfo()})
48 private GuiReaderBookInfo(Type type
, String id
, String value
) {
55 * Get the main info to display for this book (a title, an author, a
56 * source/type name...).
58 * Note that when {@link MetaData} about the book are present, the title
59 * inside is returned instead of the actual value (that way, we can update
60 * the {@link MetaData} and see the changes here).
62 * @return the main info, usually the title
64 public String
getMainInfo() {
66 return meta
.getTitle();
73 * Get the secondary info, of the given type.
76 * TRUE for word/image/story count, FALSE for author name
78 * @return the secondary info
80 public String
getSecondaryInfo(boolean seeCount
) {
81 String author
= meta
== null ?
null : meta
.getAuthor();
82 String secondaryInfo
= seeCount ? count
: author
;
84 if (secondaryInfo
!= null && !secondaryInfo
.trim().isEmpty()) {
85 secondaryInfo
= "(" + secondaryInfo
+ ")";
94 * A unique ID for this {@link GuiReaderBookInfo}.
96 * @return the unique ID
98 public String
getId() {
103 * The {@link MetaData} associated with this book, if this book is a
106 * Can be NULL for non-story books (authors or sources/types).
108 * @return the {@link MetaData} or NULL
110 public MetaData
getMeta() {
115 * Get the base image to use to represent this book.
117 * The image is <b>NOT</b> resized in any way, this is the original version.
119 * It can be NULL if no image can be found for this book.
122 * the {@link BasicLibrary} to use to fetch the image
124 * @return the base image
126 public Image
getBaseImage(BasicLibrary lib
) {
129 return lib
.getCover(meta
.getLuid());
131 return lib
.getSourceCover(value
);
133 return lib
.getAuthorCover(value
);
140 * Create a new book describing the given {@link Story}.
143 * the {@link MetaData} representing the {@link Story}
147 static public GuiReaderBookInfo
fromMeta(MetaData meta
) {
148 String uid
= meta
.getUuid();
149 if (uid
== null || uid
.trim().isEmpty()) {
150 uid
= meta
.getLuid();
153 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.STORY
, uid
,
157 info
.count
= formatNumber(meta
.getWords());
158 if (!info
.count
.isEmpty()) {
159 info
.count
= GuiReader
.trans(
160 meta
.isImageDocument() ? StringIdGui
.BOOK_COUNT_IMAGES
161 : StringIdGui
.BOOK_COUNT_WORDS
, info
.count
);
168 * Create a new book describing the given source/type.
171 * the {@link BasicLibrary} to use to retrieve some more
172 * information about the source
178 static public GuiReaderBookInfo
fromSource(BasicLibrary lib
, String source
) {
179 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.SOURCE
, "source_"
182 info
.count
= formatNumber(lib
.getListBySource(source
).size());
183 if (!info
.count
.isEmpty()) {
184 info
.count
= GuiReader
.trans(StringIdGui
.BOOK_COUNT_STORIES
,
192 * Create a new book describing the given author.
195 * the {@link BasicLibrary} to use to retrieve some more
196 * information about the author
202 static public GuiReaderBookInfo
fromAuthor(BasicLibrary lib
, String author
) {
203 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.AUTHOR
, "author_"
206 info
.count
= formatNumber(lib
.getListByAuthor(author
).size());
207 if (!info
.count
.isEmpty()) {
208 info
.count
= GuiReader
.trans(StringIdGui
.BOOK_COUNT_STORIES
,
216 * Format a number for display (use the "k" notation if higher or equal to
220 * the number to parse
222 * @return the displayable version of the number
224 static private String
formatNumber(long number
) {
225 String displayNumber
;
226 if (number
>= 4000) {
227 displayNumber
= "" + (number
/ 1000) + "k";
228 } else if (number
> 0) {
229 displayNumber
= "" + number
;
234 return displayNumber
;