From d84984521bb3a1fffe534d90a7ff716a5e68e979 Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Sat, 23 Aug 2014 15:33:00 +0100 Subject: [PATCH 1/4] Making image size in search info dynamic based on screen size --- frontend/apps/filemanager/filemanagersearch.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/apps/filemanager/filemanagersearch.lua b/frontend/apps/filemanager/filemanagersearch.lua index 8565a5c21..375d29e96 100644 --- a/frontend/apps/filemanager/filemanagersearch.lua +++ b/frontend/apps/filemanager/filemanagersearch.lua @@ -542,7 +542,12 @@ function Search:onMenuHold(item) end item.notchecked = false end - UIManager:show(InfoMessage:new{text = item.info,image = UIToolbox:getPicture(item.path), image_width=240,image_height = 400}) + if Screen:getWidth()/3 < 240 then + thumbwidth = Screen:getWidth()/3 + else + thumbwidth = 240 + end + UIManager:show(InfoMessage:new{text = item.info,image = UIToolbox:getPicture(item.path), image_width=thumbwidth,image_height = 400}) end end From 8e57adadb20b521adc31c0641a29ffed0e625ad5 Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Sat, 23 Aug 2014 15:35:55 +0100 Subject: [PATCH 2/4] 2nd change to make image dynamic in search --- frontend/apps/filemanager/filemanagersearch.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/apps/filemanager/filemanagersearch.lua b/frontend/apps/filemanager/filemanagersearch.lua index 375d29e96..1fa28d312 100644 --- a/frontend/apps/filemanager/filemanagersearch.lua +++ b/frontend/apps/filemanager/filemanagersearch.lua @@ -547,7 +547,8 @@ function Search:onMenuHold(item) else thumbwidth = 240 end - UIManager:show(InfoMessage:new{text = item.info,image = UIToolbox:getPicture(item.path), image_width=thumbwidth,image_height = 400}) + thumbheight = thumbwidth/2*3 + UIManager:show(InfoMessage:new{text = item.info,image = UIToolbox:getPicture(item.path), image_width = thumbwidth,image_height = thumbheight}) end end From 8d9eb30886e15d494abb3f8c802261a03b4c354b Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Sat, 23 Aug 2014 16:01:47 +0100 Subject: [PATCH 3/4] Switch to local variables --- frontend/apps/filemanager/filemanagersearch.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/apps/filemanager/filemanagersearch.lua b/frontend/apps/filemanager/filemanagersearch.lua index 1fa28d312..9f21bd527 100644 --- a/frontend/apps/filemanager/filemanagersearch.lua +++ b/frontend/apps/filemanager/filemanagersearch.lua @@ -543,9 +543,9 @@ function Search:onMenuHold(item) item.notchecked = false end if Screen:getWidth()/3 < 240 then - thumbwidth = Screen:getWidth()/3 + local thumbwidth = Screen:getWidth()/3 else - thumbwidth = 240 + local thumbwidth = 240 end thumbheight = thumbwidth/2*3 UIManager:show(InfoMessage:new{text = item.info,image = UIToolbox:getPicture(item.path), image_width = thumbwidth,image_height = thumbheight}) From 4c68e091f9b86ade527e1625c3b5d937eab38d15 Mon Sep 17 00:00:00 2001 From: chrox Date: Sat, 23 Aug 2014 23:19:02 +0800 Subject: [PATCH 4/4] refactoring: better logic and indentation --- .../apps/filemanager/filemanagersearch.lua | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/frontend/apps/filemanager/filemanagersearch.lua b/frontend/apps/filemanager/filemanagersearch.lua index 9f21bd527..5bac4154e 100644 --- a/frontend/apps/filemanager/filemanagersearch.lua +++ b/frontend/apps/filemanager/filemanagersearch.lua @@ -35,7 +35,7 @@ local Search = InputContainer:new{ lastsearch = nil, use_own_metadata_file = false, metafile_1 = nil, - metafile_2 = nil, + metafile_2 = nil, } local function __genOrderedIndex( t ) @@ -163,7 +163,7 @@ function Search:getCalibre() end -- check 2nd file local dummy - + if string.sub(SEARCH_LIBRARY_PATH2,string.len(SEARCH_LIBRARY_PATH2)) ~= "/" then SEARCH_LIBRARY_PATH2 = SEARCH_LIBRARY_PATH2 .. "/" end @@ -272,7 +272,7 @@ function Search:ShowSearch() UIManager:show(InfoMessage:new{text = self.error .. _( " A search for a " .. calibre .. " file was not successful!"),}) end end - + end function Search:init() @@ -373,13 +373,13 @@ function Search:find(option) end self.libraries[i] = tonumber(line) line = g:read() - + local dummy = "" if option == "find" and SEARCH_AUTHORS then dummy = dummy .. self.data[i][self.authors] .. "\n" end if option == "find" and SEARCH_TITLE then dummy = dummy .. self.data[i][self.title] .. "\n" end if option == "find" and SEARCH_PATH then dummy = dummy .. self.data[i][self.path] .. "\n" end if (option == "series" or SEARCH_SERIES) and self.data[i][self.series] ~= "-" then - dummy = dummy .. self.data[i][self.series] .. "\n" + dummy = dummy .. self.data[i][self.series] .. "\n" self.browse_series[self.data[i][self.series]] = (self.browse_series[self.data[i][self.series]] or 0) + 1 end if option == "tags" or SEARCH_TAGS then dummy = dummy .. self.data[i][self.tags] .. "\n" end @@ -429,7 +429,7 @@ function Search:find(option) if option == "find" and SEARCH_TITLE then dummy = dummy .. self.data[i][self.title] .. "\n" end if option == "find" and SEARCH_PATH then dummy = dummy .. self.data[i][self.path] .. "\n" end if (option == "series" or SEARCH_SERIES) and self.data[i][self.series] ~= "-" then - dummy = dummy .. self.data[i][self.series] .. "\n" + dummy = dummy .. self.data[i][self.series] .. "\n" self.browse_series[self.data[i][self.series]] = (self.browse_series[self.data[i][self.series]] or 0) + 1 end if option == "tags" or SEARCH_TAGS then dummy = dummy .. self.data[i][self.tags] .. "\n" end @@ -488,7 +488,7 @@ function Search:find(option) if not line and firstrun then if f ~= nil then f:close() end firstrun = false - + if self.metafile_2 then f = io.open(self.metafile_2) line = f:read() @@ -514,7 +514,7 @@ function Search:find(option) self:showresults() else self:browse(option,1) - end + end else if option == "find" then dummy = _("No match for") .. " " .. self.search_value @@ -524,7 +524,7 @@ function Search:find(option) dummy = dummy .. " " .. _("matching") .. " " .. self.search_value end dummy = dummy .. "!" - end + end UIManager:show(InfoMessage:new{text = dummy}) end end @@ -542,12 +542,8 @@ function Search:onMenuHold(item) end item.notchecked = false end - if Screen:getWidth()/3 < 240 then - local thumbwidth = Screen:getWidth()/3 - else - local thumbwidth = 240 - end - thumbheight = thumbwidth/2*3 + local thumbwidth = math.min(240, Screen:getWidth()/3) + local thumbheight = thumbwidth/2*3 UIManager:show(InfoMessage:new{text = item.info,image = UIToolbox:getPicture(item.path), image_width = thumbwidth,image_height = thumbheight}) end @@ -629,7 +625,7 @@ function Search:browse(option,run,chosen) self:find(self.lastsearch) end end - + end local upsearch local dummy @@ -641,7 +637,7 @@ function Search:browse(option,run,chosen) if run == 1 then self.results = {} - if option == "series" then + if option == "series" then for v,n in orderedPairs(self.browse_series) do dummy = v if not SEARCH_CASESENSITIVE then dummy = string.upper(dummy) end @@ -667,7 +663,7 @@ function Search:browse(option,run,chosen) }) end end - end + end else restart_me = true self.results = {} @@ -713,7 +709,7 @@ function Search:browse(option,run,chosen) end end local dummy = "" - + if run == 1 then dummy = _("Browse") .. " " .. option else