1 package be
.nikiroo
.fanfix
.reader
.ui
;
3 import be
.nikiroo
.fanfix
.data
.MetaData
;
4 import be
.nikiroo
.fanfix
.library
.BasicLibrary
;
5 import be
.nikiroo
.utils
.Image
;
7 public class GuiReaderBookInfo
{
9 /** A normal story, which can be "read". */
12 * A special, empty story that represents a source/type common to one or
13 * more normal stories.
16 /** A special, empty story that represents an author. */
25 private MetaData meta
;
27 // use the fromXXX methods
28 private GuiReaderBookInfo(Type type
, String id
, String value
) {
34 public String
getMainInfo() {
38 public String
getSecondaryInfo(boolean seeCount
) {
39 String author
= meta
== null ?
null : meta
.getAuthor();
40 String secondaryInfo
= seeCount ? count
: author
;
42 if (secondaryInfo
!= null && !secondaryInfo
.trim().isEmpty()) {
43 secondaryInfo
= "(" + secondaryInfo
+ ")";
52 * A unique ID for this {@link GuiReaderBookInfo}.
54 * @return the unique ID
56 public String
getId() {
60 // can return null for non-books
61 public MetaData
getMeta() {
65 public Image
getBaseImage(BasicLibrary lib
) {
68 return lib
.getCover(meta
.getLuid());
70 return lib
.getSourceCover(value
);
72 return lib
.getAuthorCover(value
);
78 static public GuiReaderBookInfo
fromMeta(MetaData meta
) {
79 String uid
= meta
.getUuid();
80 if (uid
== null || uid
.trim().isEmpty()) {
84 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.STORY
, uid
,
88 info
.count
= formatNumber(meta
.getWords(),
89 meta
.isImageDocument() ?
"images" : "words");
94 static public GuiReaderBookInfo
fromSource(BasicLibrary lib
, String source
) {
95 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.SOURCE
, "source_"
98 info
.count
= formatNumber(lib
.getListBySource(source
).size(), "stories");
103 static public GuiReaderBookInfo
fromAuthor(BasicLibrary lib
, String author
) {
104 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.AUTHOR
, "author_"
107 info
.count
= formatNumber(lib
.getListByAuthor(author
).size(), "stories");
112 static private String
formatNumber(long number
, String ofWhat
) {
113 String displayNumber
;
114 if (number
>= 4000) {
115 displayNumber
= "" + (number
/ 1000) + "k";
116 } else if (number
> 0) {
117 displayNumber
= "" + number
;
122 if (!displayNumber
.isEmpty()) {
123 displayNumber
+= " " + ofWhat
;
126 return displayNumber
;