[feat] Add ReaderBack (#3821)

This implements a reasonable facsimile of going back on Android.

The back button first goes back in a history of visited pages.
When there's no history left, it closes the app.

Fixes #3816.
This commit is contained in:
Frans de Jonge
2018-03-31 21:19:31 +02:00
committed by GitHub
parent c332d517f7
commit 2c1178896c
4 changed files with 128 additions and 36 deletions

View File

@@ -95,6 +95,46 @@ function util.secondsToClock(seconds, withoutSeconds)
end
end
--[[--
Compares values in two different tables.
Source: <a href="https://stackoverflow.com/a/32660766/2470572">https://stackoverflow.com/a/32660766/2470572</a>
]]
---- @param o1 Lua table
---- @param o2 Lua table
---- @bool ignore_mt
---- @treturn boolean
function util.tableEquals(o1, o2, ignore_mt)
if o1 == o2 then return true end
local o1Type = type(o1)
local o2Type = type(o2)
if o1Type ~= o2Type then return false end
if o1Type ~= 'table' then return false end
if not ignore_mt then
local mt1 = getmetatable(o1)
if mt1 and mt1.__eq then
--compare using built in method
return o1 == o2
end
end
local keySet = {}
for key1, value1 in pairs(o1) do
local value2 = o2[key1]
if value2 == nil or util.tableEquals(value1, value2, ignore_mt) == false then
return false
end
keySet[key1] = true
end
for key2, _ in pairs(o2) do
if not keySet[key2] then return false end
end
return true
end
--- Returns number of keys in a table.
---- @param T Lua table
---- @treturn int number of keys in table T