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() {
36 return meta
.getTitle();
42 public String
getSecondaryInfo(boolean seeCount
) {
43 String author
= meta
== null ?
null : meta
.getAuthor();
44 String secondaryInfo
= seeCount ? count
: author
;
46 if (secondaryInfo
!= null && !secondaryInfo
.trim().isEmpty()) {
47 secondaryInfo
= "(" + secondaryInfo
+ ")";
56 * A unique ID for this {@link GuiReaderBookInfo}.
58 * @return the unique ID
60 public String
getId() {
64 // can return null for non-books
65 public MetaData
getMeta() {
69 public Image
getBaseImage(BasicLibrary lib
) {
72 return lib
.getCover(meta
.getLuid());
74 return lib
.getSourceCover(value
);
76 return lib
.getAuthorCover(value
);
82 static public GuiReaderBookInfo
fromMeta(MetaData meta
) {
83 String uid
= meta
.getUuid();
84 if (uid
== null || uid
.trim().isEmpty()) {
88 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.STORY
, uid
,
92 info
.count
= formatNumber(meta
.getWords(),
93 meta
.isImageDocument() ?
"images" : "words");
98 static public GuiReaderBookInfo
fromSource(BasicLibrary lib
, String source
) {
99 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.SOURCE
, "source_"
102 info
.count
= formatNumber(lib
.getListBySource(source
).size(), "stories");
107 static public GuiReaderBookInfo
fromAuthor(BasicLibrary lib
, String author
) {
108 GuiReaderBookInfo info
= new GuiReaderBookInfo(Type
.AUTHOR
, "author_"
111 info
.count
= formatNumber(lib
.getListByAuthor(author
).size(), "stories");
116 static private String
formatNumber(long number
, String ofWhat
) {
117 String displayNumber
;
118 if (number
>= 4000) {
119 displayNumber
= "" + (number
/ 1000) + "k";
120 } else if (number
> 0) {
121 displayNumber
= "" + number
;
126 if (!displayNumber
.isEmpty()) {
127 displayNumber
+= " " + ofWhat
;
130 return displayNumber
;