From 39345704ecac2cf2210c6cca9e8d182d95a120c8 Mon Sep 17 00:00:00 2001 From: poire-z Date: Wed, 20 May 2020 21:40:49 +0200 Subject: [PATCH] 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. --- .../apps/reader/modules/readerbookmark.lua | 18 ++++++++++++++++++ plugins/statistics.koplugin/main.lua | 3 +++ 2 files changed, 21 insertions(+) diff --git a/frontend/apps/reader/modules/readerbookmark.lua b/frontend/apps/reader/modules/readerbookmark.lua index d0d7ca326..fe42e9c78 100644 --- a/frontend/apps/reader/modules/readerbookmark.lua +++ b/frontend/apps/reader/modules/readerbookmark.lua @@ -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 diff --git a/plugins/statistics.koplugin/main.lua b/plugins/statistics.koplugin/main.lua index f7622f544..ede4a081d 100644 --- a/plugins/statistics.koplugin/main.lua +++ b/plugins/statistics.koplugin/main.lua @@ -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()