-package be.nikiroo.fanfix.reader.cli;
+package be.nikiroo.fanfix.reader;
import java.io.IOException;
import java.util.List;
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Paragraph;
import be.nikiroo.fanfix.data.Story;
-import be.nikiroo.fanfix.reader.BasicReader;
import be.nikiroo.fanfix.searchable.BasicSearchable;
import be.nikiroo.fanfix.searchable.SearchableTag;
import be.nikiroo.fanfix.supported.SupportType;
+import be.nikiroo.utils.Image;
import be.nikiroo.utils.StringUtils;
/**
*
* @author niki
*/
-class CliReader extends BasicReader {
- @Override
- public void read(boolean sync) throws IOException {
- MetaData meta = getMeta();
+public class CliReader extends BasicReader {
+ public void listBooks(String source) throws IOException {
+ List<MetaData> stories = Instance.getInstance().getLibrary().getList()
+ .filter(source, null, null);
+ for (MetaData story : stories) {
+ String author = "";
+ if (story.getAuthor() != null && !story.getAuthor().isEmpty()) {
+ author = " (" + story.getAuthor() + ")";
+ }
+
+ System.out.println(
+ story.getLuid() + ": " + story.getTitle() + author);
+ }
+ }
+
+ public void listChapters(Story story) throws IOException {
+ if (story == null || story.getMeta() == null) {
+ throw new IOException("No story to read");
+ }
+ MetaData meta = story.getMeta();
if (meta == null) {
throw new IOException("No story to read");
}
System.out.println(author);
System.out.println("");
- // TODO: progress?
- for (Chapter chap : getStory(null)) {
+ for (Chapter chap : story) {
if (chap.getName() != null && !chap.getName().isEmpty()) {
- System.out.println(Instance.getInstance().getTrans().getString(StringId.CHAPTER_NAMED, chap.getNumber(),
+ System.out.println(Instance.getInstance().getTrans().getString(
+ StringId.CHAPTER_NAMED, chap.getNumber(),
chap.getName()));
} else {
- System.out.println(
- Instance.getInstance().getTrans().getString(StringId.CHAPTER_UNNAMED, chap.getNumber()));
+ System.out.println(Instance.getInstance().getTrans()
+ .getString(StringId.CHAPTER_UNNAMED, chap.getNumber()));
}
}
}
- public void read(int chapter) throws IOException {
- MetaData meta = getMeta();
-
+ public void printChapter(Story story, int chapter) throws IOException {
+ if (story == null || story.getMeta() == null) {
+ throw new IOException("No story to read");
+ }
+ MetaData meta = story.getMeta();
if (meta == null) {
throw new IOException("No story to read");
}
- // TODO: progress?
- if (chapter > getStory(null).getChapters().size()) {
+ if (chapter <= 0 || chapter > story.getChapters().size()) {
System.err.println("Chapter " + chapter + ": no such chapter");
} else {
- Chapter chap = getStory(null).getChapters().get(chapter - 1);
- System.out.println("Chapter " + chap.getNumber() + ": "
- + chap.getName());
-
+ Chapter chap = story.getChapters().get(chapter - 1);
+ System.out.println(
+ "Chapter " + chap.getNumber() + ": " + chap.getName());
+ System.out.println();
+
for (Paragraph para : chap) {
- System.out.println(para.getContent());
+ Image img = para.getContentImage();
+ if (img != null) {
+ String sz = StringUtils.formatNumber(img.getSize(), 1);
+ System.out.println("[Image: " + sz + "]");
+ } else {
+ System.out.println(
+ para.getContent() == null ? "" : para.getContent());
+ }
System.out.println("");
}
}
}
- @Override
- public void browse(String source) throws IOException {
- List<MetaData> stories = getLibrary().getList().filter(source, null, null);
-
- for (MetaData story : stories) {
- String author = "";
- if (story.getAuthor() != null && !story.getAuthor().isEmpty()) {
- author = " (" + story.getAuthor() + ")";
- }
-
- System.out.println(story.getLuid() + ": " + story.getTitle()
- + author);
- }
- }
-
- @Override
- public void search(boolean sync) throws IOException {
+ public void listSearchables() throws IOException {
for (SupportType type : SupportType.values()) {
if (BasicSearchable.getSearchable(type) != null) {
System.out.println(type);
}
}
- @Override
- public void search(SupportType searchOn, String keywords, int page,
- int item, boolean sync) throws IOException {
+ public void searchBooksByKeyword(SupportType searchOn, String keywords,
+ int page, int item) throws IOException {
BasicSearchable search = BasicSearchable.getSearchable(searchOn);
if (page == 0) {
List<MetaData> metas = search.search(keywords, page);
if (item == 0) {
- System.out.println("Page " + page + " of stories for: "
- + keywords);
+ System.out.println(
+ "Page " + page + " of stories for: " + keywords);
displayStories(metas);
} else {
// ! 1-based index !
}
}
- @Override
- public void searchTag(SupportType searchOn, int page, int item,
- boolean sync, Integer... tags) throws IOException {
+ public void searchBooksByTag(SupportType searchOn, int page, int item,
+ Integer... tags) throws IOException {
BasicSearchable search = BasicSearchable.getSearchable(searchOn);
SearchableTag stag = search.getTag(tags);
displayTag(subtag);
}
} else {
- System.out.println("Invalid item: only " + count
- + " items found");
+ System.out.println(
+ "Invalid item: only " + count + " items found");
}
} else {
if (metas != null) {