diff --git a/src/org/geometerplus/android/fbreader/NavigationPopup.java b/src/org/geometerplus/android/fbreader/NavigationPopup.java index 62e0b175d..9bb3b0f6b 100644 --- a/src/org/geometerplus/android/fbreader/NavigationPopup.java +++ b/src/org/geometerplus/android/fbreader/NavigationPopup.java @@ -144,13 +144,12 @@ final class NavigationPopup extends PopupPanel { final TextView text = (TextView)panel.findViewById(R.id.book_position_text); final ZLTextView textView = getReader().getTextView(); - final int page = textView.computeCurrentPage(); - final int pagesNumber = textView.computePageNumber(); + final ZLTextView.PagePosition pagePosition = textView.pagePosition(); - if (slider.getMax() != pagesNumber - 1 || slider.getProgress() != page - 1) { - slider.setMax(pagesNumber - 1); - slider.setProgress(page - 1); - text.setText(makeProgressText(page, pagesNumber)); + if (slider.getMax() != pagePosition.Total - 1 || slider.getProgress() != pagePosition.Current - 1) { + slider.setMax(pagePosition.Total - 1); + slider.setProgress(pagePosition.Current - 1); + text.setText(makeProgressText(pagePosition.Current, pagePosition.Total)); } } diff --git a/src/org/geometerplus/fbreader/fbreader/FBView.java b/src/org/geometerplus/fbreader/fbreader/FBView.java index 968b3f47b..e686fe9c6 100644 --- a/src/org/geometerplus/fbreader/fbreader/FBView.java +++ b/src/org/geometerplus/fbreader/fbreader/FBView.java @@ -489,14 +489,13 @@ public final class FBView extends ZLTextView { height > 10, false, false ); - final int pagesProgress = computeCurrentPage(); - final int bookLength = computePageNumber(); + final PagePosition pagePosition = FBView.this.pagePosition(); final StringBuilder info = new StringBuilder(); if (reader.FooterShowProgressOption.getValue()) { - info.append(pagesProgress); + info.append(pagePosition.Current); info.append("/"); - info.append(bookLength); + info.append(pagePosition.Total); } if (reader.FooterShowBatteryOption.getValue()) { if (info.length() > 0) { @@ -537,7 +536,7 @@ public final class FBView extends ZLTextView { context.drawLine(gaugeRight, lineWidth, left, lineWidth); final int gaugeInternalRight = - left + lineWidth + (int)(1.0 * myGaugeWidth * pagesProgress / bookLength); + left + lineWidth + (int)(1.0 * myGaugeWidth * pagePosition.Current / pagePosition.Total); context.setFillColor(fillColor); context.fillRectangle(left + 1, height - 2 * lineWidth, gaugeInternalRight, lineWidth + 1); diff --git a/src/org/geometerplus/zlibrary/text/view/ZLTextView.java b/src/org/geometerplus/zlibrary/text/view/ZLTextView.java index 569fdbe24..d2edde94e 100644 --- a/src/org/geometerplus/zlibrary/text/view/ZLTextView.java +++ b/src/org/geometerplus/zlibrary/text/view/ZLTextView.java @@ -483,7 +483,7 @@ public abstract class ZLTextView extends ZLTextViewBase { if (myModel == null || myModel.getParagraphsNumber() == 0) { return 0; } - ZLTextPage page = getPage(pageIndex); + final ZLTextPage page = getPage(pageIndex); preparePaintInfo(page); if (startNotEndOfPage) { return Math.max(0, sizeOfTextBeforeCursor(page.StartCursor)); @@ -613,12 +613,60 @@ public abstract class ZLTextView extends ZLTextViewBase { return myContext.getStringWidth(pattern, 0, length) / ((float)length); } - public final synchronized int computePageNumber() { - return computeTextPageNumber(sizeOfFullText()); + public static class PagePosition { + public final int Current; + public final int Total; + + PagePosition(int current, int total) { + Current = current; + Total = total; + } } - public final synchronized int computeCurrentPage() { - return computeTextPageNumber(getCurrentCharNumber(PageIndex.current, false)); + public final synchronized PagePosition pagePosition() { + final int currentCharIndex = getCurrentCharNumber(PageIndex.current, false); + final int lastCharIndex = sizeOfFullText(); + int current = computeTextPageNumber(currentCharIndex); + int total = computeTextPageNumber(lastCharIndex); + + if (current == total) { + if (currentCharIndex < lastCharIndex) { + if (total <= 2) { + total += 1; + } else { + current -= 1; + } + } else { + if (total == 1) { + ZLTextWordCursor cursor = myCurrentPage.StartCursor; + if (cursor == null || cursor.isNull()) { + preparePaintInfo(myCurrentPage); + cursor = myCurrentPage.StartCursor; + } + if (cursor != null && !cursor.isNull() && + (!cursor.isStartOfParagraph() || !cursor.getParagraphCursor().isFirst())) { + total = 2; + current = 2; + } + } + if (total == 2) { + ZLTextWordCursor cursor = myPreviousPage.StartCursor; + if (cursor == null || cursor.isNull()) { + preparePaintInfo(myPreviousPage); + cursor = myPreviousPage.StartCursor; + } + if (cursor != null && !cursor.isNull() && + (!cursor.isStartOfParagraph() || !cursor.getParagraphCursor().isFirst())) { + total = 3; + current = 3; + } + } + } + } else if (total == 2 && getCurrentCharNumber(PageIndex.next, false) < lastCharIndex) { + total = 3; + } + + return new PagePosition(current, total); } public final synchronized void gotoPage(int page) {