Calibre plugin - Series/Tag browser updated to show back button. (#8869)

* Calibre plugin - Series/Tag browser updated to show back button.

* Handling page number

* Few updates to search logic:
- Moved "find books" option from CalibreSearch:find(option)
into CalibreSearch:browse(option) function. This way all search options
are handled in one place only.

- Menu is created only once and it is in CalibreSearch:browse(option)
function. This is where it is also invoked with UIManager:show(w).
Switching between different menu content (tags/series/books) is
done using CalibreSearch:switchResults function which will internally
call Menu:switchItemTable. Previously menu was being instantiated
in 2 places depending on are we searching books or series/tags

- Return arrow navigation: Border around Menu is gone to give space
for back arrow. Navigation seems to be working fine so far but will
give it some time to test in case I find any other bugs
reviewable/pr8918/r1
Emir Taletovic 2 years ago committed by GitHub
parent 8f3e9a5a61
commit f8eca5fa03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,7 +3,6 @@
--]] --]]
local CalibreMetadata = require("metadata") local CalibreMetadata = require("metadata")
local CenterContainer = require("ui/widget/container/centercontainer")
local ConfirmBox = require("ui/widget/confirmbox") local ConfirmBox = require("ui/widget/confirmbox")
local DataStorage = require("datastorage") local DataStorage = require("datastorage")
local Device = require("device") local Device = require("device")
@ -14,7 +13,6 @@ local InputContainer = require("ui/widget/container/inputcontainer")
local Menu = require("ui/widget/menu") local Menu = require("ui/widget/menu")
local Persist = require("persist") local Persist = require("persist")
local Screen = require("device").screen local Screen = require("device").screen
local Size = require("ui/size")
local TimeVal = require("ui/timeval") local TimeVal = require("ui/timeval")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local lfs = require("libs/libkoreader-lfs") local lfs = require("libs/libkoreader-lfs")
@ -328,13 +326,7 @@ function CalibreSearch:find(option)
-- measure time elapsed searching -- measure time elapsed searching
local start = TimeVal:now() local start = TimeVal:now()
if option == "find" then self:browse(option)
local books = self:findBooks(self.search_value)
local result = self:bookCatalog(books)
self:showresults(result)
else
self:browse(option, 1)
end
logger.info(string.format("search done in %.3f milliseconds (%s, %s, %s, %s, %s)", logger.info(string.format("search done in %.3f milliseconds (%s, %s, %s, %s, %s)",
TimeVal:getDurationMs(start), TimeVal:getDurationMs(start),
option == "find" and "books" or option, option == "find" and "books" or option,
@ -383,28 +375,19 @@ function CalibreSearch:findBooks(query)
end end
-- browse tags or series -- browse tags or series
function CalibreSearch:browse(option, run, chosen) function CalibreSearch:browse(option)
local menu_container = CenterContainer:new{ local search_value
dimen = Screen:getSize(), if self.search_value ~= "" then
} search_value = self.search_value
self.search_menu = Menu:new{ end
width = Screen:getWidth() - (Size.margin.fullscreen_popout * 2), local name
height = Screen:getHeight() - (Size.margin.fullscreen_popout * 2), local menu_entries = {}
show_parent = menu_container,
onMenuHold = self.onMenuHold, if option == "find" then
_manager = self, name = _("Books")
} menu_entries = self:bookCatalog(self:findBooks(self.search_value))
table.insert(menu_container, self.search_menu) else
self.search_menu.close_callback = function() local source
UIManager:close(menu_container)
end
if run == 1 then
local menu_entries = {}
local search_value
if self.search_value ~= "" then
search_value = self.search_value
end
local name, source
if option == "tags" then if option == "tags" then
name = _("Browse by tags") name = _("Browse by tags")
source = searchByTag(self.books, search_value, self.case_insensitive) source = searchByTag(self.books, search_value, self.case_insensitive)
@ -416,51 +399,62 @@ function CalibreSearch:browse(option, run, chosen)
local entry = {} local entry = {}
entry.text = string.format("%s (%d)", k, v) entry.text = string.format("%s (%d)", k, v)
entry.callback = function() entry.callback = function()
self:browse(option, 2, k) self:expandTagOrSeries(option,k)
end end
table.insert(menu_entries, entry) table.insert(menu_entries, entry)
end end
table.sort(menu_entries, function(v1,v2) return v1.text < v2.text end) end
self.search_menu:switchItemTable(name, menu_entries)
UIManager:show(menu_container) self.search_menu = self.search_menu or Menu:new{
else width = Screen:getWidth(),
local results height = Screen:getHeight(),
if option == "tags" then parent = nil,
results = getBooksByTag(self.books, chosen) is_borderless = true,
elseif option == "series" then onMenuHold = self.onMenuHold,
results = getBooksBySeries(self.books, chosen) }
end self.search_menu.paths = {}
if results then self.search_menu.onReturn = function ()
local catalog = self:bookCatalog(results, option) local path_entry = table.remove(self.search_menu.paths)
self:showresults(catalog, chosen) local page = path_entry.page or 1
if #self.search_menu.paths < 1 then
-- If nothing is left in paths we switch to original items and title
self.search_menu.paths = {}
self:switchResults(menu_entries, name, false, page)
end end
end end
self:switchResults(menu_entries, name)
UIManager:show(self.search_menu)
end end
-- show search results function CalibreSearch:expandTagOrSeries(option, chosen_item)
function CalibreSearch:showresults(t, title) local results
if option == "tags" then
results = getBooksByTag(self.books, chosen_item)
elseif option == "series" then
results = getBooksBySeries(self.books, chosen_item)
end
if results then
local catalog = self:bookCatalog(results, option)
self:switchResults(catalog, chosen_item, true)
end
end
-- update search results
function CalibreSearch:switchResults(t, title, is_child, page)
if not title then if not title then
title = _("Search results") title = _("Search results")
end end
local menu_container = CenterContainer:new{
dimen = Screen:getSize(),
}
self.search_menu = Menu:new{
width = Screen:getWidth() - (Size.margin.fullscreen_popout * 2),
height = Screen:getHeight() - (Size.margin.fullscreen_popout * 2),
show_parent = menu_container,
onMenuHold = self.onMenuHold,
_manager = self,
}
table.insert(menu_container, self.search_menu)
self.search_menu.close_callback = function()
UIManager:close(menu_container)
end
table.sort(t, function(v1,v2) return v1.text < v2.text end) table.sort(t, function(v1,v2) return v1.text < v2.text end)
self.search_menu:switchItemTable(title, t)
UIManager:show(menu_container) if is_child then
local path_entry = {}
path_entry.page = (self.search_menu.perpage or 1) * (self.search_menu.page or 1)
table.insert(self.search_menu.paths, path_entry)
end
self.search_menu:switchItemTable(title, t, page or 1)
end end
-- prompt the user for a library scan -- prompt the user for a library scan

Loading…
Cancel
Save