From 7d6da81233ab58fd2b80d71a84f0c4351d7ff856 Mon Sep 17 00:00:00 2001 From: Melik <10296053+melyux@users.noreply.github.com> Date: Wed, 8 Feb 2023 19:55:13 -0800 Subject: [PATCH] Compact covermenu addn. to for loop, fix collections bug, further gimp genStatusButton to use upvalues --- .../filemanager/filemanagercollection.lua | 4 +- frontend/apps/filemanager/filemanagerutil.lua | 6 +- plugins/coverbrowser.koplugin/covermenu.lua | 120 +++++------------- 3 files changed, 36 insertions(+), 94 deletions(-) diff --git a/frontend/apps/filemanager/filemanagercollection.lua b/frontend/apps/filemanager/filemanagercollection.lua index dc0f18f74..6227577e8 100644 --- a/frontend/apps/filemanager/filemanagercollection.lua +++ b/frontend/apps/filemanager/filemanagercollection.lua @@ -50,10 +50,10 @@ function FileManagerCollection:onMenuHold(item) UIManager:close(self.collfile_dialog) end local buttons = { - filemanagerutil.getStatusButtonsRow(item.file, currently_opened_file, status_button_callback), + filemanagerutil.getStatusButtonsRow(item.file, status_button_callback), {}, { - filemanagerutil.genResetSettingsButton(item.file, nil, status_button_callback), + filemanagerutil.genResetSettingsButton(item.file, currently_opened_file, status_button_callback), { text = _("Remove from collection"), callback = function() diff --git a/frontend/apps/filemanager/filemanagerutil.lua b/frontend/apps/filemanager/filemanagerutil.lua index 20e1afac7..7f112e165 100644 --- a/frontend/apps/filemanager/filemanagerutil.lua +++ b/frontend/apps/filemanager/filemanagerutil.lua @@ -132,9 +132,9 @@ function filemanagerutil.getStatusButtonsRow(file, caller_callback) } end return { - genStatusButton("reading", status, file, caller_callback), - genStatusButton("abandoned", status, file, caller_callback), - genStatusButton("complete", status, file, caller_callback), + genStatusButton("reading"), + genStatusButton("abandoned"), + genStatusButton("complete"), } end diff --git a/plugins/coverbrowser.koplugin/covermenu.lua b/plugins/coverbrowser.koplugin/covermenu.lua index 0cfdf716b..0c4ea7892 100644 --- a/plugins/coverbrowser.koplugin/covermenu.lua +++ b/plugins/coverbrowser.koplugin/covermenu.lua @@ -342,35 +342,17 @@ 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("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_reading_callback() - end - 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_abandoned_callback() - end - 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" + for _, status in ipairs({"reading", "abandoned", "complete"}) do + button = self.file_dialog.button_table:getButtonById(status) + local orig_status_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] = status + end + -- And then set the status on file as expected + orig_status_callback() end - -- And then set the status on file as expected - orig_complete_callback() end -- Replace the "Book information" button callback to use directly our bookinfo @@ -519,40 +501,18 @@ 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("reading") - if button then - 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_reading_callback() - end - end - button = self.histfile_dialog.button_table:getButtonById("abandoned") - if button then - 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_abandoned_callback() - end - end - button = self.histfile_dialog.button_table:getButtonById("complete") - if button then - 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" + for _, status in ipairs({"reading", "abandoned", "complete"}) do + button = self.histfile_dialog.button_table:getButtonById(status) + if button then + local orig_status_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] = status + end + -- And then set the status on file as expected + orig_status_callback() end - -- And then set the status on file as expected - orig_complete_callback() end end @@ -694,35 +654,17 @@ 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("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_reading_callback() - end - 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_abandoned_callback() - end - 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" + for _, status in ipairs({"reading", "abandoned", "complete"}) do + button = self.collfile_dialog.button_table:getButtonById(status) + local orig_status_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] = status + end + -- And then set the status on file as expected + orig_status_callback() end - -- And then set the status on file as expected - orig_complete_callback() end -- Replace Book information callback to use directly our bookinfo