X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Fcli%2FCliReader.java;h=9ec37a583d983cee46333f32f793ea1dc04dc3b1;hb=350bc060516184774f8116e61696a8c3c45ba85d;hp=e040a210cb3aaf5e4dbc7ef46721e86b38c5a86b;hpb=89cb07a69f3ee217f9ea6a4284bec0df94ef77fa;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/reader/cli/CliReader.java b/src/be/nikiroo/fanfix/reader/cli/CliReader.java index e040a21..9ec37a5 100644 --- a/src/be/nikiroo/fanfix/reader/cli/CliReader.java +++ b/src/be/nikiroo/fanfix/reader/cli/CliReader.java @@ -9,8 +9,7 @@ import be.nikiroo.fanfix.data.Chapter; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Paragraph; import be.nikiroo.fanfix.data.Story; -import be.nikiroo.fanfix.reader.FanfixReader; -import be.nikiroo.fanfix.supported.BasicSupport.SupportType; +import be.nikiroo.fanfix.reader.BasicReader; /** * Command line {@link Story} reader. @@ -19,33 +18,26 @@ import be.nikiroo.fanfix.supported.BasicSupport.SupportType; * * @author niki */ -public class CliReader extends FanfixReader { - /** - * Start the {@link Story} Reading. - * - * @throws IOException - * in case of I/O error or if the {@link Story} was not - * previously set - */ - public void read() throws IOException { - if (getStory() == null) { +class CliReader extends BasicReader { + @Override + public void read(boolean sync) throws IOException { + MetaData meta = getMeta(); + + if (meta == null) { throw new IOException("No story to read"); } String title = ""; String author = ""; - MetaData meta = getStory().getMeta(); - if (meta != null) { - if (meta.getTitle() != null) { - title = meta.getTitle(); - } + if (meta.getTitle() != null) { + title = meta.getTitle(); + } - if (meta.getAuthor() != null) { - author = "©" + meta.getAuthor(); - if (meta.getDate() != null && !meta.getDate().isEmpty()) { - author = author + " (" + meta.getDate() + ")"; - } + if (meta.getAuthor() != null) { + author = "©" + meta.getAuthor(); + if (meta.getDate() != null && !meta.getDate().isEmpty()) { + author = author + " (" + meta.getDate() + ")"; } } @@ -53,7 +45,8 @@ public class CliReader extends FanfixReader { System.out.println(author); System.out.println(""); - for (Chapter chap : getStory()) { + // TODO: progress? + for (Chapter chap : getStory(null)) { if (chap.getName() != null && !chap.getName().isEmpty()) { System.out.println(Instance.getTrans().getString( StringId.CHAPTER_NAMED, chap.getNumber(), @@ -65,17 +58,18 @@ public class CliReader extends FanfixReader { } } - /** - * Read the selected chapter (starting at 1). - * - * @param chapter - * the chapter - */ - public void read(int chapter) { - if (chapter > getStory().getChapters().size()) { + public void read(int chapter) throws IOException { + MetaData meta = getMeta(); + + if (meta == null) { + throw new IOException("No story to read"); + } + + // TODO: progress? + if (chapter > getStory(null).getChapters().size()) { System.err.println("Chapter " + chapter + ": no such chapter"); } else { - Chapter chap = getStory().getChapters().get(chapter - 1); + Chapter chap = getStory(null).getChapters().get(chapter - 1); System.out.println("Chapter " + chap.getNumber() + ": " + chap.getName()); @@ -87,9 +81,9 @@ public class CliReader extends FanfixReader { } @Override - public void start(SupportType type) { + public void browse(String source) { List stories; - stories = Instance.getLibrary().getList(type); + stories = getLibrary().getListBySource(source); for (MetaData story : stories) { String author = "";