Merge pull request #1983 from koreader/houqp-master

fix end of book detection for crengine
pull/1984/head
Frans de Jonge 8 years ago
commit ec1275ca5f

@ -5,7 +5,7 @@ source "${CI_DIR}/common.sh"
set +e set +e
make coverage travis_retry make coverage
pushd koreader-*/koreader pushd koreader-*/koreader
luajit $(which luacov-coveralls) -v luajit $(which luacov-coveralls) -v
popd popd

@ -107,7 +107,10 @@ test:
$(MAKE) testfront $(MAKE) testfront
coverage: $(INSTALL_DIR)/koreader/.luacov coverage: $(INSTALL_DIR)/koreader/.luacov
cd $(INSTALL_DIR)/koreader && ./luajit $(shell which busted) -o verbose_print --coverage --exclude-tags=nocov cd $(INSTALL_DIR)/koreader && \
./luajit $(shell which busted) -o verbose_print \
--no-auto-insulate \
--coverage --exclude-tags=nocov
# coverage report summary # coverage report summary
cd $(INSTALL_DIR)/koreader && tail -n \ cd $(INSTALL_DIR)/koreader && tail -n \
+$$(($$(grep -nm1 Summary luacov.report.out|cut -d: -f1)-1)) \ +$$(($$(grep -nm1 Summary luacov.report.out|cut -d: -f1)-1)) \

@ -1 +1 @@
Subproject commit b5c82144e253844849ab66e55bdff363d4991c66 Subproject commit 02c4e24e732f4d7009b71c763dbaa503c40365a1

@ -295,7 +295,7 @@ function ReaderFooter:updateFooterText()
if #ticks_candidates > 0 then if #ticks_candidates > 0 then
self.progress_bar.ticks = ticks_candidates[1] self.progress_bar.ticks = ticks_candidates[1]
self.progress_bar.last = self.pages self.progress_bar.last = self.pages or self.view.document:getPageCount()
else else
-- we still set ticks here so self.progress_bar.ticks will not be -- we still set ticks here so self.progress_bar.ticks will not be
-- initialized again if ticks_candidates is empty -- initialized again if ticks_candidates is empty

@ -357,11 +357,6 @@ end
function ReaderRolling:onGotoViewRel(diff) function ReaderRolling:onGotoViewRel(diff)
DEBUG("goto relative screen:", diff, ", in mode: ", self.view.view_mode) DEBUG("goto relative screen:", diff, ", in mode: ", self.view.view_mode)
local prev_xp
-- save xpointer to check whether we reach the end of the book
if diff > 0 then
prev_xp = self.xpointer
end
if self.view.view_mode == "scroll" then if self.view.view_mode == "scroll" then
local pan_diff = diff * self.ui.dimen.h local pan_diff = diff * self.ui.dimen.h
if self.show_overlap_enable then if self.show_overlap_enable then
@ -371,15 +366,20 @@ function ReaderRolling:onGotoViewRel(diff)
pan_diff = pan_diff + self.overlap pan_diff = pan_diff + self.overlap
end end
end end
local old_pos = self.current_pos
self:_gotoPos(self.current_pos + pan_diff) self:_gotoPos(self.current_pos + pan_diff)
if diff > 0 and old_pos == self.current_pos then
self.ui:handleEvent(Event:new("EndOfBook"))
end
elseif self.view.view_mode == "page" then elseif self.view.view_mode == "page" then
local page_count = self.ui.document:getVisiblePageCount() local page_count = self.ui.document:getVisiblePageCount()
local old_page = self.current_page
self:_gotoPage(self.current_page + diff*page_count) self:_gotoPage(self.current_page + diff*page_count)
if diff > 0 and old_page == self.current_page then
self.ui:handleEvent(Event:new("EndOfBook"))
end
end end
self.xpointer = self.ui.document:getXPointer() self.xpointer = self.ui.document:getXPointer()
if self.xpointer == prev_xp then
self.ui:handleEvent(Event:new("EndOfBook"))
end
return true return true
end end

@ -57,7 +57,7 @@ function BookStatusWidget:init()
self.stats = { self.stats = {
total_time_in_sec = 0, total_time_in_sec = 0,
performance_in_pages = {}, performance_in_pages = {},
pages = self.document:getPageCount(), total_pages = self.document:getPageCount(),
} }
self:getStatisticsSettings() self:getStatisticsSettings()
if self.settings then if self.settings then
@ -123,8 +123,8 @@ function BookStatusWidget:getStatHours(stats)
end end
function BookStatusWidget:getReadPages(stats) function BookStatusWidget:getReadPages(stats)
if stats and stats.performance_in_pages and stats.pages then if stats and stats.performance_in_pages and stats.total_pages then
return util.tableSize(stats.performance_in_pages) .. "/" .. stats.pages return util.tableSize(stats.performance_in_pages) .. "/" .. stats.total_pages
end end
return "none" return "none"
end end
@ -253,12 +253,14 @@ function BookStatusWidget:genBookInfoGroup()
} }
) )
-- progress bar -- progress bar
local total_pages = self.document:getPageCount() local total_pages = self.stats.total_pages
local read_percentage = self.view.state.page / total_pages local read_percentage = self.view.state.page / total_pages
local progress_bar = ProgressWidget:new{ local progress_bar = ProgressWidget:new{
width = width * 0.7, width = width * 0.7,
height = Screen:scaleBySize(10), height = Screen:scaleBySize(10),
percentage = read_percentage, percentage = read_percentage,
ticks = nil,
last = nil,
} }
table.insert(book_meta_info_group, table.insert(book_meta_info_group,
CenterContainer:new{ CenterContainer:new{

@ -14,7 +14,7 @@ Configurable attributes:
* rectcolor -- infill color * rectcolor -- infill color
* ticks (list) -- default to nil, use this if you want to insert markers * ticks (list) -- default to nil, use this if you want to insert markers
* tick_width * tick_width
* last -- maximum tick * last -- maximum tick, used with ticks
Example: Example:
@ -68,7 +68,7 @@ function ProgressWidget:paintTo(bb, x, y)
bb:paintRect(x+self.margin_h, math.ceil(y+self.margin_v+self.bordersize), bb:paintRect(x+self.margin_h, math.ceil(y+self.margin_v+self.bordersize),
math.ceil((my_size.w-2*self.margin_h)*self.percentage), math.ceil((my_size.w-2*self.margin_h)*self.percentage),
my_size.h-2*(self.margin_v+self.bordersize), self.rectcolor) my_size.h-2*(self.margin_v+self.bordersize), self.rectcolor)
if self.ticks then if self.ticks and self.last then
for i=1, #self.ticks do for i=1, #self.ticks do
bb:paintRect( bb:paintRect(
x + (my_size.w-2*self.margin_h)*(self.ticks[i]/self.last), x + (my_size.w-2*self.margin_h)*(self.ticks[i]/self.last),

@ -20,12 +20,14 @@ describe("Readerrolling module", function()
it("should goto portrait screen mode", function() it("should goto portrait screen mode", function()
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait")) readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
end) end)
it("should goto certain page", function() it("should goto certain page", function()
for i = 1, 10, 5 do for i = 1, 10, 5 do
rolling:onGotoPage(i) rolling:onGotoPage(i)
assert.are.same(i, rolling.current_page) assert.are.same(i, rolling.current_page)
end end
end) end)
it("should goto relative page", function() it("should goto relative page", function()
for i = 20, 40, 5 do for i = 20, 40, 5 do
rolling:onGotoPage(i) rolling:onGotoPage(i)
@ -35,6 +37,7 @@ describe("Readerrolling module", function()
assert.are.same(i, rolling.current_page) assert.are.same(i, rolling.current_page)
end end
end) end)
it("should goto next chapter", function() it("should goto next chapter", function()
local toc = readerui.toc local toc = readerui.toc
for i = 30, 50, 5 do for i = 30, 50, 5 do
@ -43,6 +46,7 @@ describe("Readerrolling module", function()
assert.are.same(toc:getNextChapter(i, 0), rolling.current_page) assert.are.same(toc:getNextChapter(i, 0), rolling.current_page)
end end
end) end)
it("should goto previous chapter", function() it("should goto previous chapter", function()
local toc = readerui.toc local toc = readerui.toc
for i = 60, 80, 5 do for i = 60, 80, 5 do
@ -51,18 +55,58 @@ describe("Readerrolling module", function()
assert.are.same(toc:getPreviousChapter(i, 0), rolling.current_page) assert.are.same(toc:getPreviousChapter(i, 0), rolling.current_page)
end end
end) end)
it("should emit EndOfBook event at the end", function()
rolling:onGotoPage(readerui.document:getPageCount()) it("should emit EndOfBook event at the end of sample epub", function()
local called = false local called = false
readerui.onEndOfBook = function() readerui.onEndOfBook = function()
called = true called = true
end end
-- check beginning of the book
rolling:onGotoPage(1)
assert.is.falsy(called)
rolling:onGotoViewRel(-1)
rolling:onGotoViewRel(-1)
assert.is.falsy(called)
-- check end of the book
rolling:onGotoPage(readerui.document:getPageCount())
assert.is.falsy(called)
rolling:onGotoViewRel(1) rolling:onGotoViewRel(1)
assert.is.truthy(called)
rolling:onGotoViewRel(1) rolling:onGotoViewRel(1)
assert.is.truthy(called) assert.is.truthy(called)
readerui.onEndOfBook = nil readerui.onEndOfBook = nil
end) end)
it("should emit EndOfBook event at the end sample txt", function()
local sample_txt = "spec/front/unit/data/sample.txt"
local txt_readerui = ReaderUI:new{
document = DocumentRegistry:openDocument(sample_txt),
}
local called = false
txt_readerui.onEndOfBook = function()
called = true
end
local txt_rolling = txt_readerui.rolling
-- check beginning of the book
txt_rolling:onGotoPage(1)
assert.is.falsy(called)
txt_rolling:onGotoViewRel(-1)
txt_rolling:onGotoViewRel(-1)
assert.is.falsy(called)
-- not at the end of the book
txt_rolling:onGotoPage(3)
assert.is.falsy(called)
txt_rolling:onGotoViewRel(1)
assert.is.falsy(called)
-- at the end of the book
txt_rolling:onGotoPage(txt_readerui.document:getPageCount())
assert.is.falsy(called)
txt_rolling:onGotoViewRel(1)
assert.is.truthy(called)
readerui.onEndOfBook = nil
end)
end) end)
describe("test in landscape screen mode", function() describe("test in landscape screen mode", function()
it("should go to landscape screen mode", function() it("should go to landscape screen mode", function()
readerui:handleEvent(Event:new("ChangeScreenMode", "landscape")) readerui:handleEvent(Event:new("ChangeScreenMode", "landscape"))
@ -110,6 +154,7 @@ describe("Readerrolling module", function()
readerui.onEndOfBook = nil readerui.onEndOfBook = nil
end) end)
end) end)
describe("switching screen mode should not change current page number", function() describe("switching screen mode should not change current page number", function()
it("for portrait-landscape-portrait switching", function() it("for portrait-landscape-portrait switching", function()
for i = 80, 100, 10 do for i = 80, 100, 10 do

@ -1,8 +1,11 @@
require("commonrequire")
local Menu = require("ui/widget/menu")
local DEBUG = require("dbg")
describe("Menu widget", function() describe("Menu widget", function()
local Menu, dbg
setup(function()
require("commonrequire")
Menu = require("ui/widget/menu")
dbg = require("dbg")
end)
it("should convert item table from touch menu properly", function() it("should convert item table from touch menu properly", function()
local cb1 = function() end local cb1 = function() end
local cb2 = function() end local cb2 = function() end

@ -0,0 +1,18 @@
describe("ProgressWidget widget", function()
local ProgressWidget, Screen
setup(function()
require("commonrequire")
ProgressWidget = require("ui/widget/progresswidget")
Screen = require("device").screen
end)
it("should not crash with nil self.last #ok", function()
local progress = ProgressWidget:new{
width = 100,
height = 50,
percentage = 5/100,
ticks = {1},
}
progress:paintTo(Screen.bb, 0, 0)
end)
end)

@ -0,0 +1,94 @@
Lorem ipsum
Dolor sit amet, foo@bar.com
v0.1, 99 September 7999
Lorem ipsum dolor sit amet, pri id laudem vulputate disputando, ad mea
pericula consetetur. Nusquam detraxit ad sed, tritani mandamus aliquando et
has, porro graeco at pri. Sale denique ut sit, mel suas erroribus repudiare
ea. Vim probo dicit consequuntur te.
______________________________________________________________________
Table of Contents
1. Eos ex eius iusto delicata
2. Illum argumentum sed a
3. In eum magna iusto integre
______________________________________________________________________
1. Eos ex eius iusto delicata
Eos ex eius iusto delicata, ius ne facer invenire electram, cu mel assum
novum efficiendi. Duo enim eleifend te. Elitr nihil vivendo vix ex, ex homero
salutatus sed, ea nec posse commune consetetur. Ea iusto labore docendi his,
at per mollis mentitum. Ex esse recteque eos, ex iudicabit gloriatur mei.
Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue:
1. Maecenas nec odio et ante tincidunt tempus.
2. Donec sodales sagittis magna.
3. Phasellus viverra nulla ut metus varius laoreet.
Li Europan lingues es membres del sam familie. Lor separat existentie es un
myth.
It va esser tam simplic quam Occidental in fact, it va esser Occidental. A un
Angleso it va semblar un simplificat Angles, quam un skeptic Cambridge amico
dit me que Occidental es.Li Europan lingues es membres del sam familie. Lor
separat existentie es un myth. Por scientie, musica, sport etc, litot Europa
usa li sam vocabular. Li lingues differe solmen in li grammatica, li
pronunciation e li plu commun vocabules. Omnicos directe al desirabilite de
un nov lingua franca: On refusa continuar payar custosi traductores. At
solmen va esser necessi far uniform grammatica, pronunciation e plu sommun
paroles.
2. Illum argumentum sed a
Illum argumentum sed ad, vel accumsan noluisse eu. Nam ne minimum consulatu,
vim nullam quidam ut. Ea pro temporibus ullamcorper, at case aeque vix. Est
id consetetur intellegam. Eu cum oratio gubergren, aeque tritani feugiat vel
te.
· Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium
doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore
veritatis et quasi architecto beatae vitae dicta sunt explicabo.
· Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam
nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas
nulla pariatur?
cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod
maxime placeat facere.
To install the tar.gz source, use the commands:
______________________________________________________________________
./configure
make
make install
______________________________________________________________________
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed
quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.
Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur,
adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore
et dolore magnam aliquam quaerat voluptatem.
3. In eum magna iusto integre
In eum magna iusto integre, cu solet commodo constituto pro. Te nec tota
altera, diam periculis ius eu, eum te velit partiendo conclusionemque. Diam
mnesarchum at usu, agam nonumes at nec. Vix aliquip liberavisse ex, nam at
quis choro accusam. Eu his zril graecis, latine legendos inimicus eum at, qui
te adolescens adipiscing.
Loading…
Cancel
Save