Commits

kulti  committed 3af7311

Extracted BookState.tryToSetCurrentContent()

  • Participants
  • Parent commits e66128f

Comments (0)

Files changed (4)

File pdf_book_reader/src/ru/homeless/kulti/pdf_book_reader/BookState.java

 public class BookState
 {
     private IBookView bookView;
+    private PdfParser pdfParser;
     private int currentPageNumber;
 
     public BookState(IBookView bookView)
     {
         this.bookView = bookView;
+        pdfParser = new PdfParser();
     }
     
     public void openFile(String fileName)
     {
         try
         {
-            PdfParser pdfParser = new PdfParser();
             pdfParser.open(fileName);
-            bookView.setPageContent(pdfParser.getPageContent(1));
+            currentPageNumber = 1;
+            tryToSetCurrentContent();
         }
         catch (IOException e)
         {
     public void goToPage(int pageNum)
     {
         currentPageNumber = pageNum;
+        tryToSetCurrentContent();
     }
 
     public int currentPageNumber()
     public void goToNextPage()
     {
         ++currentPageNumber;
-        bookView.setPageContent("test2");
+        tryToSetCurrentContent();
     }
 
     public void goToPreviousPage()
     {
         --currentPageNumber;
-        bookView.setPageContent("test");
+        tryToSetCurrentContent();
+    }
+
+    private void tryToSetCurrentContent()
+    {
+        try
+        {
+            bookView.setPageContent(pdfParser.getPageContent(currentPageNumber));
+        }
+        catch (IOException e)
+        {
+            bookView.setPageContent("IOException occured: " + e.getMessage());
+        }
     }
 }

File pdf_book_reader_test/src/ru/homeless/kulti/pdf_book_reader/test/BookStateTest.java

     
     public void testPageNavigation()
     {
+        bookState.openFile("/sdcard/test.pdf");
         bookState.goToPage(1);
         assertEquals(1, bookState.currentPageNumber());
         bookState.goToNextPage();

File pdf_book_reader_test/src/ru/homeless/kulti/pdf_book_reader/test/PdfParserTest.java

     public void testNumberOfPages() throws Exception
     {
         pdfParser.open("/sdcard/test.pdf");
-        assertEquals(1, pdfParser.getNumberOfPages());
+        assertEquals(2, pdfParser.getNumberOfPages());
     }
     
     public void testPageContent() throws Exception

File test_files/test.pdf

Binary file modified.