Statistics: fix number of highlights (#6173)

This number might have been leaking from a previously opened
book, and can be innacurate.
Reset it from the number of highlights stored in settings.
Note that the number of "Notes" shown does not mean much.
reviewable/pr6179/r1
poire-z 4 years ago committed by GitHub
parent 8ab3bf2792
commit 39345704ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -639,4 +639,22 @@ function ReaderBookmark:hasBookmarks()
return self.bookmarks and #self.bookmarks > 0
end
function ReaderBookmark:getNumberOfHighlightsAndNotes()
local highlights = 0
local notes = 0
for i = 1, #self.bookmarks do
if self.bookmarks[i].highlighted then
highlights = highlights + 1
-- No real way currently to know which highlights
-- have been edited and became "notes". Editing them
-- adds this 'text' field, but just showing bookmarks
-- do that as well...
if self.bookmarks[i].text then
notes = notes + 1
end
end
end
return highlights, notes
end
return ReaderBookmark

@ -203,6 +203,9 @@ function ReaderStatistics:initData()
if not self.data.md5 then
self.data.md5 = self:partialMd5(self.document.file)
end
-- Update these numbers to what's actually stored in the settings
-- (not that "notes" is invalid and does not represent edited highlights)
self.data.highlights, self.data.notes = self.ui.bookmark:getNumberOfHighlightsAndNotes()
self.curr_total_time = 0
self.curr_total_pages = 0
self.id_curr_book = self:getIdBookDB()

Loading…
Cancel
Save