From 68782c3f894a3c3a94eb3b39934df91991e4c6c0 Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Fri, 27 Aug 2021 22:21:14 +0300 Subject: [PATCH] Checkbutton: optimize callback (#8134) --- .../apps/filemanager/filemanagerfilesearcher.lua | 14 +------------- frontend/apps/reader/modules/readersearch.lua | 12 ++---------- frontend/ui/elements/menu_keyboard_layout.lua | 12 ++---------- frontend/ui/widget/checkbutton.lua | 11 ++--------- frontend/ui/widget/inputdialog.lua | 9 ++------- frontend/ui/widget/inputtext.lua | 9 ++------- frontend/ui/widget/openwithdialog.lua | 12 ++---------- 7 files changed, 13 insertions(+), 66 deletions(-) diff --git a/frontend/apps/filemanager/filemanagerfilesearcher.lua b/frontend/apps/filemanager/filemanagerfilesearcher.lua index a8a0d8abd..81638e95f 100644 --- a/frontend/apps/filemanager/filemanagerfilesearcher.lua +++ b/frontend/apps/filemanager/filemanagerfilesearcher.lua @@ -21,15 +21,9 @@ local _ = require("gettext") local Screen = require("device").screen local FileSearcher = InputContainer:new{ - search_dialog = nil, - - --filesearcher - -- state buffer dirs = {}, files = {}, results = {}, - items = 0, - commands = nil, } function FileSearcher:readDir() @@ -109,8 +103,6 @@ function FileSearcher:setSearchResults() end end end - self.keywords = keywords - self.items = #self.results end function FileSearcher:close() @@ -172,11 +164,7 @@ function FileSearcher:onShowFileSearch(search_string) parent = self.search_dialog, max_width = self.search_dialog._input_widget.width, callback = function() - if self.check_button_case.checked then - self.check_button_case:unCheck() - else - self.check_button_case:check() - end + self.check_button_case:toggleCheck() self.case_sensitive = self.check_button_case.checked end, } diff --git a/frontend/apps/reader/modules/readersearch.lua b/frontend/apps/reader/modules/readersearch.lua index e0e490b14..d7e8a036d 100644 --- a/frontend/apps/reader/modules/readersearch.lua +++ b/frontend/apps/reader/modules/readersearch.lua @@ -142,11 +142,7 @@ function ReaderSearch:onShowFulltextSearchInput() parent = self.input_dialog, max_width = self.input_dialog._input_widget.width, callback = function() - if not self.check_button_case.checked then - self.check_button_case:check() - else - self.check_button_case:unCheck() - end + self.check_button_case:toggleCheck() end, } self.check_button_regex = CheckButton:new{ @@ -155,11 +151,7 @@ function ReaderSearch:onShowFulltextSearchInput() parent = self.input_dialog, max_width = self.input_dialog._input_widget.width, callback = function() - if not self.check_button_regex.checked then - self.check_button_regex:check() - else - self.check_button_regex:unCheck() - end + self.check_button_regex:toggleCheck() end, hold_callback = function() UIManager:show(InfoMessage:new{ text = help_text }) diff --git a/frontend/ui/elements/menu_keyboard_layout.lua b/frontend/ui/elements/menu_keyboard_layout.lua index 5934ee1dc..3b5394e37 100644 --- a/frontend/ui/elements/menu_keyboard_layout.lua +++ b/frontend/ui/elements/menu_keyboard_layout.lua @@ -57,11 +57,7 @@ local sub_item_table = { parent = input_dialog, max_width = input_dialog._input_widget.width, callback = function() - if check_button_bold.checked then - check_button_bold:unCheck() - else - check_button_bold:check() - end + check_button_bold:toggleCheck() end, } check_button_border = CheckButton:new{ @@ -70,11 +66,7 @@ local sub_item_table = { parent = input_dialog, max_width = input_dialog._input_widget.width, callback = function() - if check_button_border.checked then - check_button_border:unCheck() - else - check_button_border:check() - end + check_button_border:toggleCheck() end, } diff --git a/frontend/ui/widget/checkbutton.lua b/frontend/ui/widget/checkbutton.lua index 62eac65f9..2c6e87a5d 100644 --- a/frontend/ui/widget/checkbutton.lua +++ b/frontend/ui/widget/checkbutton.lua @@ -174,15 +174,8 @@ function CheckButton:onHoldReleaseCheckButton() return false end -function CheckButton:check() - self:initCheckButton(true) - UIManager:setDirty(self.parent, function() - return "ui", self.dimen - end) -end - -function CheckButton:unCheck() - self:initCheckButton(false) +function CheckButton:toggleCheck() + self:initCheckButton(not self.checked) UIManager:setDirty(self.parent, function() return "ui", self.dimen end) diff --git a/frontend/ui/widget/inputdialog.lua b/frontend/ui/widget/inputdialog.lua index fad3d4d31..71e9b1e42 100644 --- a/frontend/ui/widget/inputdialog.lua +++ b/frontend/ui/widget/inputdialog.lua @@ -820,13 +820,8 @@ function InputDialog:_addScrollButtons(nav_bar) parent = input_dialog, max_width = input_dialog._input_widget.width, callback = function() - if not self.check_button_case.checked then - self.check_button_case:check() - self.case_sensitive = true - else - self.check_button_case:unCheck() - self.case_sensitive = false - end + self.check_button_case:toggleCheck() + self.case_sensitive = self.check_button_case.checked end, } diff --git a/frontend/ui/widget/inputtext.lua b/frontend/ui/widget/inputtext.lua index 3194590ae..5602f967e 100644 --- a/frontend/ui/widget/inputtext.lua +++ b/frontend/ui/widget/inputtext.lua @@ -394,13 +394,8 @@ function InputText:initTextBox(text, char_added) parent = self, max_width = self.width, callback = function() - if self.text_type == "text" then - self.text_type = "password" - self._check_button:unCheck() - else - self.text_type = "text" - self._check_button:check() - end + self._check_button:toggleCheck() + self.text_type = self._check_button.checked and "text" or "password" self:setText(self:getText(), true) end, } diff --git a/frontend/ui/widget/openwithdialog.lua b/frontend/ui/widget/openwithdialog.lua index a71077c56..e7be0edf3 100644 --- a/frontend/ui/widget/openwithdialog.lua +++ b/frontend/ui/widget/openwithdialog.lua @@ -64,11 +64,7 @@ function OpenWithDialog:init() self._check_file_button = self._check_file_button or CheckButton:new{ text = _("Always use this engine for this file"), callback = function() - if self._check_file_button.checked then - self._check_file_button:unCheck() - else - self._check_file_button:check() - end + self._check_file_button:toggleCheck() end, max_width = self.element_width, @@ -88,11 +84,7 @@ function OpenWithDialog:init() self._check_global_button = self._check_global_button or CheckButton:new{ text = _("Always use this engine for file type"), callback = function() - if self._check_global_button.checked then - self._check_global_button:unCheck() - else - self._check_global_button:check() - end + self._check_global_button:toggleCheck() end, max_width = self.element_width,