Create genStatusButton() for buttons, use item.dim for deleted in history

reviewable/pr10074/r12^2
Melik 1 year ago committed by Frans de Jonge
parent 9e7e68beb6
commit 502bb0ccbf

@ -340,37 +340,27 @@ function FileManager:setupLayout()
if is_file then
local status = filemanagerutil.getStatus(file)
table.insert(buttons, {
{
text = _("Reading"),
id = "mark_as_reading", -- used by covermenu
enabled = status ~= "reading",
callback = function()
filemanagerutil.setStatus(file, "reading")
self:refreshPath()
UIManager:close(self.file_dialog)
end,
},
{
text = _("On hold"),
id = "put_on_hold", -- used by covermenu
enabled = status ~= "abandoned",
callback = function()
filemanagerutil.setStatus(file, "abandoned")
self:refreshPath()
UIManager:close(self.file_dialog)
end,
},
{
text = _("Finished"),
id = "mark_as_read", -- used by covermenu
enabled = status ~= "complete",
local function genStatusButton(to_status)
local status_text = {
reading = _("Reading"),
abandoned = _("On hold"),
complete = _("Finished"),
}
return {
text = status_text[to_status],
id = to_status, -- used by covermenu
enabled = status ~= to_status,
callback = function()
filemanagerutil.setStatus(file, "complete")
filemanagerutil.setStatus(file, to_status)
self:refreshPath()
UIManager:close(self.file_dialog)
end,
},
}
end
table.insert(buttons, {
genStatusButton("reading"),
genStatusButton("abandoned"),
genStatusButton("complete"),
})
table.insert(buttons, {}) -- separator
table.insert(buttons, {

@ -46,38 +46,28 @@ end
function FileManagerCollection:onMenuHold(item)
self.collfile_dialog = nil
local status = filemanagerutil.getStatus(item.file)
local function genStatusButton(to_status)
local status_text = {
reading = _("Reading"),
abandoned = _("On hold"),
complete = _("Finished"),
}
return {
text = status_text[to_status],
id = to_status, -- used by covermenu
enabled = status ~= to_status,
callback = function()
filemanagerutil.setStatus(item.file, to_status)
self._manager:updateItemTable()
UIManager:close(self.collfile_dialog)
end,
}
end
local buttons = {
{
{
text = _("Reading"),
id = "mark_as_reading", -- used by covermenu
enabled = status ~= "reading",
callback = function()
filemanagerutil.setStatus(item.file, "reading")
self._manager:updateItemTable()
UIManager:close(self.collfile_dialog)
end,
},
{
text = _("On hold"),
id = "put_on_hold", -- used by covermenu
enabled = status ~= "abandoned",
callback = function()
filemanagerutil.setStatus(item.file, "abandoned")
self._manager:updateItemTable()
UIManager:close(self.collfile_dialog)
end,
},
{
text = _("Finished"),
id = "mark_as_read", -- used by covermenu
enabled = status ~= "complete",
callback = function()
filemanagerutil.setStatus(item.file, "complete")
self._manager:updateItemTable()
UIManager:close(self.collfile_dialog)
end,
},
genStatusButton("reading"),
genStatusButton("abandoned"),
genStatusButton("complete"),
},
{},
{

@ -89,55 +89,34 @@ function FileManagerHistory:onMenuHold(item)
local readerui_instance = require("apps/reader/readerui"):_getRunningInstance()
local currently_opened_file = readerui_instance and readerui_instance.document and readerui_instance.document.file
self.histfile_dialog = nil
local is_file = lfs.attributes(item.file, "mode") == "file"
local status = filemanagerutil.getStatus(item.file)
local function genStatusButton(to_status)
local status_text = {
reading = _("Reading"),
abandoned = _("On hold"),
complete = _("Finished"),
}
return {
text = status_text[to_status],
id = to_status, -- used by covermenu
enabled = not item.dim and status ~= to_status,
callback = function()
filemanagerutil.setStatus(item.file, to_status)
if self._manager.filter ~= "all" then
self._manager:fetchStatuses(false)
else
self._manager.statuses_fetched = false
end
self._manager:updateItemTable()
UIManager:close(self.histfile_dialog)
end,
}
end
local buttons = {
{
{
text = _("Reading"),
id = "mark_as_reading", -- used by covermenu
enabled = is_file and status ~= "reading",
callback = function()
filemanagerutil.setStatus(item.file, "reading")
if self._manager.filter ~= "all" then
self._manager:fetchStatuses(false)
else
self._manager.statuses_fetched = false
end
self._manager:updateItemTable()
UIManager:close(self.histfile_dialog)
end,
},
{
text = _("On hold"),
id = "put_on_hold", -- used by covermenu
enabled = is_file and status ~= "abandoned",
callback = function()
filemanagerutil.setStatus(item.file, "abandoned")
if self._manager.filter ~= "all" then
self._manager:fetchStatuses(false)
else
self._manager.statuses_fetched = false
end
self._manager:updateItemTable()
UIManager:close(self.histfile_dialog)
end,
},
{
text = _("Finished"),
id = "mark_as_read", -- used by covermenu
enabled = is_file and status ~= "complete",
callback = function()
filemanagerutil.setStatus(item.file, "complete")
if self._manager.filter ~= "all" then
self._manager:fetchStatuses(false)
else
self._manager.statuses_fetched = false
end
self._manager:updateItemTable()
UIManager:close(self.histfile_dialog)
end,
},
genStatusButton("reading"),
genStatusButton("abandoned"),
genStatusButton("complete"),
},
{},
{

@ -342,35 +342,35 @@ function CoverMenu:updateItems(select_number)
end
-- Fudge the status change button callbacks to also update the cover_info_cache
button = self.file_dialog.button_table:getButtonById("mark_as_reading")
local orig_mark_as_reading_callback = button.callback
button = self.file_dialog.button_table:getButtonById("reading")
local orig_reading_callback = button.callback
button.callback = function()
-- Update the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file][3] = "reading"
end
-- And then set the status on file as expected
orig_mark_as_reading_callback()
orig_reading_callback()
end
button = self.file_dialog.button_table:getButtonById("put_on_hold")
local orig_put_on_hold_callback = button.callback
button = self.file_dialog.button_table:getButtonById("abandoned")
local orig_abandoned_callback = button.callback
button.callback = function()
-- Update the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file][3] = "abandoned"
end
-- And then set the status on file as expected
orig_put_on_hold_callback()
orig_abandoned_callback()
end
button = self.file_dialog.button_table:getButtonById("mark_as_read")
local orig_mark_as_read_callback = button.callback
button = self.file_dialog.button_table:getButtonById("complete")
local orig_complete_callback = button.callback
button.callback = function()
-- Update the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file][3] = "complete"
end
-- And then set the status on file as expected
orig_mark_as_read_callback()
orig_complete_callback()
end
-- Replace the "Book information" button callback to use directly our bookinfo
@ -519,35 +519,35 @@ function CoverMenu:onHistoryMenuHold(item)
end
-- Fudge the status change button callbacks to also update the cover_info_cache
button = self.histfile_dialog.button_table:getButtonById("mark_as_reading")
local orig_mark_as_reading_callback = button.callback
button = self.histfile_dialog.button_table:getButtonById("reading")
local orig_reading_callback = button.callback
button.callback = function()
-- Update the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file][3] = "reading"
end
-- And then set the status on file as expected
orig_mark_as_reading_callback()
orig_reading_callback()
end
button = self.histfile_dialog.button_table:getButtonById("put_on_hold")
local orig_put_on_hold_callback = button.callback
button = self.histfile_dialog.button_table:getButtonById("abandoned")
local orig_abandoned_callback = button.callback
button.callback = function()
-- Update the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file][3] = "abandoned"
end
-- And then set the status on file as expected
orig_put_on_hold_callback()
orig_abandoned_callback()
end
button = self.histfile_dialog.button_table:getButtonById("mark_as_read")
local orig_mark_as_read_callback = button.callback
button = self.histfile_dialog.button_table:getButtonById("complete")
local orig_complete_callback = button.callback
button.callback = function()
-- Update the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file][3] = "complete"
end
-- And then set the status on file as expected
orig_mark_as_read_callback()
orig_complete_callback()
end
-- Replace Book information callback to use directly our bookinfo
@ -688,35 +688,35 @@ function CoverMenu:onCollectionsMenuHold(item)
end
-- Fudge the status change button callbacks to also update the cover_info_cache
button = self.collfile_dialog.button_table:getButtonById("mark_as_reading")
local orig_mark_as_reading_callback = button.callback
button = self.collfile_dialog.button_table:getButtonById("reading")
local orig_reading_callback = button.callback
button.callback = function()
-- Update the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file][3] = "reading"
end
-- And then set the status on file as expected
orig_mark_as_reading_callback()
orig_reading_callback()
end
button = self.collfile_dialog.button_table:getButtonById("put_on_hold")
local orig_put_on_hold_callback = button.callback
button = self.collfile_dialog.button_table:getButtonById("abandoned")
local orig_abandoned_callback = button.callback
button.callback = function()
-- Update the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file][3] = "abandoned"
end
-- And then set the status on file as expected
orig_put_on_hold_callback()
orig_abandoned_callback()
end
button = self.collfile_dialog.button_table:getButtonById("mark_as_read")
local orig_mark_as_read_callback = button.callback
button = self.collfile_dialog.button_table:getButtonById("complete")
local orig_complete_callback = button.callback
button.callback = function()
-- Update the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file][3] = "complete"
end
-- And then set the status on file as expected
orig_mark_as_read_callback()
orig_complete_callback()
end
-- Replace Book information callback to use directly our bookinfo

Loading…
Cancel
Save