ReaderDictionary: tweak timings if interrupted quickly

Rework b66d0be3 and 6205f260 by making that simpler
to comprehend:
- If interruption or search result window is shown in
less than 3 secondes: no specific tweak, a tap outside
will dismiss everything instantaneously.
- If done after 3 seconds: show the interruption or result
window, and discard input for a few 100ms.
- UIManager:discardEvents(): increase a bit default delays.
reviewable/pr7119/r1
poire-z 3 years ago
parent 02ac2c4ce6
commit 6c23d29a8a

@ -101,6 +101,13 @@ function ReaderDictionary:init()
os.getenv("STARDICT_DATA_DIR") or
DataStorage:getDataDir() .. "/data/dict"
-- Show the "Seaching..." InfoMessage after this delay
self.lookup_msg_delay = 0.5
-- Allow quick interruption or dismiss of search result window
-- with tap if done before this delay. After this delay, the
-- result window is shown and dismiss prevented for a few 100ms
self.quick_dismiss_before_delay = 3
-- Gather info about available dictionaries
if not available_ifos then
available_ifos = {}
@ -797,12 +804,17 @@ function ReaderDictionary:startSdcv(word, dict_names, fuzzy_search)
{
dict = "",
word = word,
definition = lookup_cancelled and _("Dictionary lookup canceled.") or _("No definition found."),
definition = lookup_cancelled and _("Dictionary lookup interrupted.") or _("No definition found."),
no_result = true,
lookup_cancelled = lookup_cancelled,
}
}
end
if lookup_cancelled then
-- Also put this as a k/v into the results array: when using dict_ext,
-- we may get results from the 1st lookup, and have interrupted the 2nd.
final_results.lookup_cancelled = true
end
return final_results
end
@ -839,11 +851,11 @@ function ReaderDictionary:stardictLookup(word, dict_names, fuzzy_search, box, li
return
end
self:showLookupInfo(word, 0.5)
self:showLookupInfo(word, self.lookup_msg_delay)
local lookup_start_ts = ffiUtil.getTimestamp()
self._lookup_start_ts = ffiUtil.getTimestamp()
local results = self:startSdcv(word, dict_names, fuzzy_search)
if results and results[1] and results[1].lookup_cancelled and ffiUtil.getDuration(lookup_start_ts) < 1.5 then
if results and results.lookup_cancelled and ffiUtil.getDuration(self._lookup_start_ts) <= self.quick_dismiss_before_delay then
-- If interrupted quickly just after launch, don't display anything
-- (this might help avoiding refreshes and the need to dismiss
-- after accidental long-press when holding a device).
@ -902,10 +914,11 @@ function ReaderDictionary:showDict(word, results, box, link)
self:dismissLookupInfo()
if results and results[1] then
UIManager:show(self.dict_window)
if not results[1].lookup_cancelled then
-- Discard queued and coming up events to avoid accidental
-- dismissal (but not if lookup interrupted, so 2 quick
-- taps can discard everything)
if not results.lookup_cancelled and ffiUtil.getDuration(self._lookup_start_ts) > self.quick_dismiss_before_delay then
-- If the search took more than a few seconds to be done, discard
-- queued and coming up events to avoid a voluntary dismissal
-- (because the user felt the result would not come) to kill the
-- result that finally came and is about to be displayed
UIManager:discardEvents(true)
end
end

@ -811,11 +811,13 @@ function UIManager:discardEvents(set_or_seconds)
-- is really painted on screen) are discarded.
if Device:hasEinkScreen() then
-- A screen refresh can take a few 100ms,
-- sometimes > 500ms on some devices/temperatures
usecs = 600000
-- sometimes > 500ms on some devices/temperatures.
-- So, block for 400ms (to have it displayed) + 400ms
-- for user reaction to it
usecs = 800000
else
-- On non-eInk screen, it's usually instantaneous
usecs = 300000
-- On non-eInk screen, display is usually instantaneous
usecs = 400000
end
else -- we expect a number
usecs = set_or_seconds * MILLION

Loading…
Cancel
Save