Swipe for menu and quickstart guide (#2761)

* Swipe for menu and quickstart guide

Because swiping for the menu is a big change from what we're used to, this commit includes a new quickstart guide.

Fixes #2608.

* add some dev docs
* add FileConverter spec
* add QuickStart spec
* add Version module
* add Version spec
pull/2770/head
Frans de Jonge 7 years ago committed by GitHub
parent 6542382a0c
commit 89099e2c94

@ -3,8 +3,6 @@ local CloudStorage = require("apps/cloudstorage/cloudstorage")
local ConfirmBox = require("ui/widget/confirmbox")
local Device = require("device")
local FileSearcher = require("apps/filemanager/filemanagerfilesearcher")
local Geom = require("ui/geometry")
local GestureRange = require("ui/gesturerange")
local InputContainer = require("ui/widget/container/inputcontainer")
local InputDialog = require("ui/widget/inputdialog")
local Screensaver = require("ui/screensaver")
@ -50,19 +48,20 @@ function FileManagerMenu:init()
end
function FileManagerMenu:initGesListener()
self.ges_events = {
TapShowMenu = {
GestureRange:new{
ges = "tap",
range = Geom:new{
x = 0,
y = 0,
w = Screen:getWidth()*3/4,
h = Screen:getHeight()/4,
}
}
if not Device:isTouchDevice() then return end
self:registerTouchZones({
{
id = "filemanager_swipe",
ges = "swipe",
screen_zone = {
ratio_x = DTAP_ZONE_MENU.x, ratio_y = DTAP_ZONE_MENU.y,
ratio_w = DTAP_ZONE_MENU.w, ratio_h = DTAP_ZONE_MENU.h,
},
overrides = { "rolling_swipe", "paging_swipe", },
handler = function(ges) return self:onSwipeShowMenu(ges) end,
},
}
})
end
function FileManagerMenu:setUpdateItemTable()
@ -335,9 +334,11 @@ function FileManagerMenu:onCloseFileManagerMenu()
return true
end
function FileManagerMenu:onTapShowMenu()
self:onShowMenu()
return true
function FileManagerMenu:onSwipeShowMenu(ges)
if ges.direction == "south" then
self:onShowMenu()
return true
end
end
function FileManagerMenu:onSetDimensions(dimen)

@ -1,4 +1,4 @@
-- From https://github.com/bakpakin/luamd revision daf7cc71f5de9a2fe66a60f452172e9597724d5d
-- From https://github.com/bakpakin/luamd revision 5e8fa39173afecd73913d27e0f0e63649b01fb5b
--[[
Copyright (c) 2016 Calvin Rose <calsrose@gmail.com>
@ -183,6 +183,11 @@ local function stripIndent(line, level, ignorepattern) -- luacheck: no unused ar
end
end
--------------------------------------------------------------------------------
-- Useful variables
--------------------------------------------------------------------------------
local NEWLINE = '\n'
--------------------------------------------------------------------------------
-- Patterns
--------------------------------------------------------------------------------
@ -190,9 +195,9 @@ end
local PATTERN_EMPTY = "^%s*$"
local PATTERN_COMMENT = "^%s*<>"
local PATTERN_HEADER = "^%s*(%#+)%s*(.*)%#*$"
local PATTERN_RULE1 = "^%s*(%-+)%s*$"
local PATTERN_RULE2 = "^%s*(%*+)%s*$"
local PATTERN_RULE3 = "^%s*(%_+)%s*$"
local PATTERN_RULE1 = "^%s?%s?%s?(-%s*-%s*-[%s-]*)$"
local PATTERN_RULE2 = "^%s?%s?%s?(*%s**%s**[%s*]*)$"
local PATTERN_RULE3 = "^%s?%s?%s?(_%s*_%s*_[%s_]*)$"
local PATTERN_CODEBLOCK = "^%s*%`%`%`(.*)"
local PATTERN_BLOCKQUOTE = "^%s*> (.*)$"
local PATTERN_ULIST = "^%s*[%*%-] (.+)$"
@ -241,6 +246,7 @@ local function readSimple(pop, peek, tree, links)
lineRead(rest),
type = "h" .. #m
}
tree[#tree + 1] = NEWLINE
return pop()
end
@ -249,6 +255,7 @@ local function readSimple(pop, peek, tree, links)
match(line, PATTERN_RULE2) or
match(line, PATTERN_RULE3) then
tree[#tree + 1] = { type = "hr", noclose = true }
tree[#tree + 1] = NEWLINE
return pop()
end
@ -295,15 +302,17 @@ local function readSimple(pop, peek, tree, links)
-- Do Paragraph
local p = {
lineRead(line), '\r\n',
lineRead(line), NEWLINE,
type = "p"
}
tree[#tree + 1] = p
while nextLine and not isSpecialLine(nextLine) do
p[#p + 1] = lineRead(nextLine)
p[#p + 1] = '\r\n'
p[#p + 1] = NEWLINE
nextLine = pop()
end
p[#p] = nil
tree[#tree + 1] = NEWLINE
return peek()
end
@ -355,6 +364,7 @@ local function readList(pop, peek, tree, links, expectedIndent)
type = (listPattern == PATTERN_ULIST and "ul" or "ol")
}
tree[#tree + 1] = list
list[1] = NEWLINE
while lineType == listPattern do
list[#list + 1] = {
lineRead(match(line, lineType)),
@ -364,6 +374,7 @@ local function readList(pop, peek, tree, links, expectedIndent)
if not line then break end
lineType = isSpecialLine(line)
if lineType ~= PATTERN_EMPTY then
list[#list + 1] = NEWLINE
local i = getIndentLevel(line)
if i < indent then break end
if i > indent then
@ -379,6 +390,8 @@ local function readList(pop, peek, tree, links, expectedIndent)
end
end
end
list[#list + 1] = NEWLINE
tree[#tree + 1] = NEWLINE
return peek()
end
@ -462,6 +475,7 @@ local function renderLinesRaw(stream, options)
accum[#accum + 1] = head
accum[#accum + 1] = insertHead
renderTree(tree, links, accum)
if accum[#accum] == NEWLINE then accum[#accum] = nil end
accum[#accum + 1] = insertTail
accum[#accum + 1] = tail
accum[#accum + 1] = appendTail

@ -236,10 +236,6 @@ function ReaderFooter:setupTouchZones()
handler = function(ges) return self:onTapFooter(ges) end,
overrides = {
'tap_forward', 'tap_backward',
-- NOTE: readermenu_tap override is needed to keep behavior
-- consistent with the old code base in case of overlap between
-- footer and menu tap zones
'readermenu_tap',
},
},
{

@ -80,14 +80,14 @@ function ReaderMenu:onReaderReady()
self.ui:registerTouchZones({
{
id = "readermenu_tap",
ges = "tap",
id = "readermenu_swipe",
ges = "swipe",
screen_zone = {
ratio_x = DTAP_ZONE_MENU.x, ratio_y = DTAP_ZONE_MENU.y,
ratio_w = DTAP_ZONE_MENU.w, ratio_h = DTAP_ZONE_MENU.h,
},
overrides = { "tap_forward", "tap_backward", },
handler = function() return self:onTapShowMenu() end,
overrides = { "rolling_swipe", "paging_swipe", },
handler = function(ges) return self:onSwipeShowMenu(ges) end,
},
})
end
@ -236,10 +236,12 @@ function ReaderMenu:onCloseReaderMenu()
return true
end
function ReaderMenu:onTapShowMenu()
self.ui:handleEvent(Event:new("ShowConfigMenu"))
self.ui:handleEvent(Event:new("ShowReaderMenu"))
return true
function ReaderMenu:onSwipeShowMenu(ges)
if ges.direction == "south" then
self.ui:handleEvent(Event:new("ShowConfigMenu"))
self.ui:handleEvent(Event:new("ShowReaderMenu"))
return true
end
end
function ReaderMenu:onTapCloseMenu()

@ -1,7 +1,12 @@
--[[--
This module handles generic settings as well as KOReader's global settings system.
]]
local dump = require("dump")
local LuaSettings = {}
--- Opens a settings file.
function LuaSettings:open(file_path)
local new = {file=file_path}
local ok, stored
@ -22,46 +27,71 @@ function LuaSettings:wrap(data)
return setmetatable(new, {__index = LuaSettings})
end
--[[--Reads child settings.
@usage
Settings:saveSetting("key", {
a = "b",
c = "true",
d = false,
})
local child = Settings:child("key")
child:readSetting("a")
-- result "b"
]]
function LuaSettings:child(key)
return LuaSettings:wrap(self:readSetting(key))
end
--- Reads a setting.
function LuaSettings:readSetting(key)
return self.data[key]
end
--- Saves a setting.
function LuaSettings:saveSetting(key, value)
self.data[key] = value
end
--- Deletes a setting.
function LuaSettings:delSetting(key)
self.data[key] = nil
end
--- Checks if setting exists.
function LuaSettings:has(key)
return self:readSetting(key) ~= nil
end
--- Checks if setting does not exist.
function LuaSettings:hasNot(key)
return self:readSetting(key) == nil
end
--- Checks if setting is `true`.
function LuaSettings:isTrue(key)
return string.lower(tostring(self:readSetting(key))) == "true"
end
--- Checks if setting is `false`.
function LuaSettings:isFalse(key)
return string.lower(tostring(self:readSetting(key))) == "false"
end
--- Checks if setting is `nil` or `true`.
function LuaSettings:nilOrTrue(key)
return self:hasNot(key) or self:isTrue(key)
end
--- Checks if setting is `nil` or `false`.
function LuaSettings:nilOrFalse(key)
return self:hasNot(key) or self:isFalse(key)
end
--- Flips `nil` or `true` to `false`.
function LuaSettings:flipNilOrTrue(key)
if self:nilOrTrue(key) then
self:saveSetting(key, false)
@ -70,6 +100,7 @@ function LuaSettings:flipNilOrTrue(key)
end
end
--- Flips `nil` or `false` to `true`.
function LuaSettings:flipNilOrFalse(key)
if self:nilOrFalse(key) then
self:saveSetting(key, true)
@ -78,6 +109,7 @@ function LuaSettings:flipNilOrFalse(key)
end
end
--- Flips setting to `true`.
function LuaSettings:flipTrue(key)
if self:isTrue(key) then
self:delSetting(key)
@ -86,6 +118,7 @@ function LuaSettings:flipTrue(key)
end
end
--- Flips setting to `false`.
function LuaSettings:flipFalse(key)
if self:isFalse(key) then
self:delSetting(key)
@ -94,10 +127,12 @@ function LuaSettings:flipFalse(key)
end
end
--- Replaces existing settings with table.
function LuaSettings:reset(table)
self.data = table
end
--- Writes settings to disk.
function LuaSettings:flush()
if not self.file then return end
local f_out = io.open(self.file, "w")
@ -110,10 +145,12 @@ function LuaSettings:flush()
end
end
--- Closes settings file.
function LuaSettings:close()
self:flush()
end
--- Purges settings file.
function LuaSettings:purge()
if self.file then
os.remove(self.file)

@ -11,7 +11,7 @@ if Device:isKindle() or Device:isKobo() or Device:isPocketBook()
local OTAManager = require("ui/otamanager")
common_info.ota_update = OTAManager:getOTAMenuTable()
end
local version = io.open("git-rev", "r"):read()
local version = require("version"):getCurrentRevision()
common_info.version = {
text = _("Version"),
callback = function()
@ -23,6 +23,14 @@ common_info.version = {
common_info.help = {
text = _("Help"),
}
common_info.quickstart_guide = {
text = _("Quickstart guide"),
callback = function()
local QuickStart = require("frontend/ui/quickstart")
local ReaderUI = require("apps/reader/readerui")
ReaderUI:showReader(QuickStart:getQuickStart())
end
}
common_info.about = {
text = _("About"),
callback = function()

@ -62,6 +62,8 @@ local order = {
"exit",
},
help = {
"quickstart_guide",
"----------------------------",
"report_bug",
"----------------------------",
"about",

@ -82,6 +82,8 @@ local order = {
"exit",
},
help = {
"quickstart_guide",
"----------------------------",
"report_bug",
"----------------------------",
"about",

@ -4,6 +4,7 @@ local Device = require("device")
local InfoMessage = require("ui/widget/infomessage")
local NetworkMgr = require("ui/network/manager")
local UIManager = require("ui/uimanager")
local Version = require("version")
local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
local _ = require("gettext")
@ -102,20 +103,12 @@ function OTAManager:checkUpdate()
end
zsync:close()
end
local normalized_version = function(rev)
local year, month, revision = rev:match("v(%d%d%d%d)%.(%d%d)-?(%d*)")
return tonumber(year .. month .. string.format("%.4d", revision or "0"))
end
local local_ok, local_version = pcall(function()
local rev_file = io.open("git-rev", "r")
if rev_file then
local rev = rev_file:read()
rev_file:close()
return normalized_version(rev)
end
local rev = Version:getCurrentRevision()
if rev then return Version:getNormalizedVersion(rev) end
end)
local ota_ok, ota_version = pcall(function()
return normalized_version(ota_package)
return Version:getNormalizedVersion(ota_package)
end)
-- return ota package version if package on OTA server has version
-- larger than the local package version

@ -0,0 +1,85 @@
--[[--This module is responsible for generating the quickstart guide.
]]
local DataStorage = require("datastorage")
local FileConverter = require("apps/filemanager/filemanagerconverter")
local Version = require("version")
local _ = require("gettext")
local lfs = require("libs/libkoreader-lfs")
local T = require("ffi/util").template
local QuickStart = {
quickstart_force_show_version = 201511982,
}
local quickstart_shown_version = G_reader_settings:readSetting("quickstart_shown_version") or nil
local language = G_reader_settings:readSetting("language") or "en"
local version = Version:getNormalizedCurrentVersion()
local rev = Version:getCurrentRevision()
local quickstart_guide = T(_([[
# KOReader Quickstart Guide
Welcome to KOReader. You can activate the menu by swiping down from the top of the screen. Clicking outside the menu or swiping up on the menu will discard it. Turning pages can be done either by swiping left and right or by single taps on the left or right side of the screen.
**Contents**
* [main menu](#main-menu)
* [settings](#settings)
* [file browser](#file-browser)
## Main menu <a id="main-menu"></a>
![Menu](../resources/icons/menu-icon.png) You can always view this quickstart guide again through *Help* *Quickstart guide* in the top right menu.
## Settings <a id="settings"></a>
![Settings](../resources/icons/appbar.settings.png) You can change the language and other settings through the gear icon.
## File browser <a id="file-browser"></a>
The file browser will only show document or ebook files that KOReader can read.
In the file browser, you can tap on any file to open it. Long press on any file to bring up a menu with more options. The location path display above the list of files and folders shows you which folder you're viewing. The `../` entry, at the top of the listed folders, lets you go *up* one level. For instance, if you are at `/mnt/onboard` now, tapping the `../` will bring you to `/mnt/`.
Once you have found the folder you have your books listed in, you can long press the selection that opens that folder and you should see a message box popup with the option to **Set as HOME directory**.
------------
Generated by KOReader %1.
]]),
rev)
--[[-- Returns `true` if shown, `false` if the quickstart guide hasn't been
shown yet or if display is forced through a higher version number than when
it was first shown.
]]
function QuickStart:isShown()
if quickstart_shown_version == nil then return false end
return (quickstart_shown_version >= self.quickstart_force_show_version)
end
--[[--Generates the quickstart guide in the user's language and returns its location.
The fileformat is `quickstart-en-v2015.11-985-g88308992.html`, `en` being the
language of the generated file and `v2015.11-985-g88308992` the KOReader version
used to generate the file.
@treturn string path to generated HTML quickstart guide
]]
function QuickStart:getQuickStart()
local quickstart_dir = ("%s/help"):format(DataStorage:getDataDir())
local quickstart_filename = ("%s/quickstart-%s-%s.html"):format(quickstart_dir, language, rev)
if lfs.attributes(quickstart_dir, "mode") ~= "dir" then
lfs.mkdir(quickstart_dir)
end
if lfs.attributes(quickstart_filename, "mode") ~= "file" then
local quickstart_html = FileConverter:mdToHtml(quickstart_guide, _("KOReader Quickstart Guide"))
if quickstart_html then
FileConverter:writeStringToFile(quickstart_html, quickstart_filename)
end
end
G_reader_settings:saveSetting("quickstart_shown_version", version)
return quickstart_filename
end
return QuickStart

@ -585,10 +585,12 @@ function TouchMenu:onPrevPage()
end
function TouchMenu:onSwipe(arg, ges_ev)
if ges_ev.direction == "west" or ges_ev.direction == "north" then
if ges_ev.direction == "west" then
self:onNextPage()
elseif ges_ev.direction == "east" or ges_ev.direction == "south" then
elseif ges_ev.direction == "east" then
self:onPrevPage()
elseif ges_ev.direction == "north" then
self:closeMenu()
end
end

@ -0,0 +1,46 @@
--[[--
This module helps with retrieving version information.
]]
local Version = {}
--- Returns current KOReader git-rev.
-- @treturn string full KOReader git-rev such `v2015.11-982-g704d4238`
function Version:getCurrentRevision()
if not self.rev then
local rev_file = io.open("git-rev", "r")
if rev_file then
self.rev = rev_file:read()
rev_file:close()
end
-- sanity check in case `git describe` failed
if self.rev == "fatal: No names found, cannot describe anything." then
self.rev = nil
end
end
return self.rev
end
--- Returns normalized version of KOReader git-rev input string.
-- @string rev full KOReader git-rev such `v2015.11-982-g704d4238`
-- @treturn int version in the form of a number such as `201511982`
-- @treturn string short git commit version hash such as `704d4238`
function Version:getNormalizedVersion(rev)
if not rev then return end
local year, month, revision = rev:match("v(%d%d%d%d)%.(%d%d)-?(%d*)")
local commit = rev:match("-%d*-g(.*)")
return ((year or 0) * 100 + (month or 0)) * 1000 + (revision or 0), commit
end
--- Returns current version of KOReader.
-- @treturn int version in the form of a number such as `201511982`
-- @treturn string short git commit version hash such as `704d4238`
-- @see normalized_version
function Version:getNormalizedCurrentVersion()
if not self.version or not self.commit then
self.version, self.commit = self:getNormalizedVersion(self:getCurrentRevision())
end
return self.version, self.commit
end
return Version

@ -89,11 +89,12 @@ while argidx <= #ARGV do
end
end
local lfs = require("libs/libkoreader-lfs")
local UIManager = require("ui/uimanager")
local ConfirmBox = require("ui/widget/confirmbox")
local Device = require("device")
local Font = require("ui/font")
local ConfirmBox = require("ui/widget/confirmbox")
local QuickStart = require("ui/quickstart")
local UIManager = require("ui/uimanager")
local lfs = require("libs/libkoreader-lfs")
local function retryLastFile()
return ConfirmBox:new{
@ -124,10 +125,12 @@ end
local last_file = G_reader_settings:readSetting("lastfile")
-- load last opened file
local open_last = G_reader_settings:readSetting("open_last")
if open_last and last_file and lfs.attributes(last_file, "mode") ~= "file" then
UIManager:show(retryLastFile())
last_file = nil
elseif not QuickStart:isShown() then
open_last = true
last_file = QuickStart:getQuickStart()
end
-- night mode
if G_reader_settings:readSetting("night_mode") then

@ -0,0 +1,50 @@
describe("FileConverter module", function()
local FileConverter
setup(function()
require("commonrequire")
FileConverter = require("apps/filemanager/filemanagerconverter")
end)
it("should show conversion support for Markdown", function()
assert.is_true(FileConverter:isSupported("/markdown_file.md"))
end)
it("should not show conversion support for PDF", function()
assert.is_false(FileConverter:isSupported("/pdf_file.pdf"))
end)
it("should convert Markdown to HTML", function()
local markdown = [[
# KOReader Quickstart Guide
Welcome to KOreader. You can activate the menu by swiping down from the top of the screen. Clicking outside the menu or swiping up on the menu will discard it. Turning pages can be done either by swiping left and right or by single taps on the left or right side of the screen.
**Main menu**
![Menu](../resources/icons/menu-icon.png) You can always view this quickstart guide again through *Help* *Quickstart guide* in the top right menu.
**Settings**
![Settings](../resources/icons/appbar.settings.png) You can change the language and other settings through the gear icon.
------------
Generated by KOReader v2015.11-982-g704d4238.
]]
local title = "KOReader Quickstart Guide"
local html_expected = [[<!DOCTYPE html>
<html>
<head>
<title>KOReader Quickstart Guide</title>
</head>
<body>
<h1>KOReader Quickstart Guide</h1>
<p>Welcome to KOreader. You can activate the menu by swiping down from the top of the screen. Clicking outside the menu or swiping up on the menu will discard it. Turning pages can be done either by swiping left and right or by single taps on the left or right side of the screen.</p>
<p><strong>Main menu</strong></p>
<p><img alt="Menu" src="../resources/icons/menu-icon.png"> You can always view this quickstart guide again through <em>Help</em> <em>Quickstart guide</em> in the top right menu.</p>
<p><strong>Settings</strong></p>
<p><img alt="Settings" src="../resources/icons/appbar.settings.png"> You can change the language and other settings through the gear icon.</p>
<hr>
<p>Generated by KOReader v2015.11-982-g704d4238.</p>
</body>
</html>]]
assert.are.same(html_expected, FileConverter:mdToHtml(markdown, title))
end)
end)

@ -0,0 +1,36 @@
describe("QuickStart module", function()
setup(function()
require("commonrequire")
end)
it("should return false shown_version lower than force_show_version", function()
G_reader_settings:saveSetting("quickstart_shown_version", 1)
G_reader_settings:flush()
local QuickStart = require("ui/quickstart")
QuickStart.quickstart_force_show_version = 2
assert.is_false(QuickStart:isShown())
end)
it("should return true when shown_version equal to force_show_version", function()
G_reader_settings:saveSetting("quickstart_shown_version", 1)
G_reader_settings:flush()
local QuickStart = require("ui/quickstart")
QuickStart.quickstart_force_show_version = 1
assert.is_true(QuickStart:isShown())
end)
it("should return true when shown_version higher than force_show_version", function()
G_reader_settings:saveSetting("quickstart_shown_version", 2)
G_reader_settings:flush()
local QuickStart = require("ui/quickstart")
QuickStart.quickstart_force_show_version = 1
assert.is_true(QuickStart:isShown())
end)
it("should return a proper quickstart filename", function()
local DataStorage = require("datastorage")
local QuickStart = require("ui/quickstart")
local Version = require("version")
local language = "en"
local rev = Version:getCurrentRevision()
local quickstart_dir = string.format("%s%s", DataStorage:getDataDir(), "/help")
local expected_quickstart_filename = ("%s/quickstart-%s-%s.html"):format(quickstart_dir, language, rev)
assert.is.same(expected_quickstart_filename, QuickStart:getQuickStart())
end)
end)

@ -0,0 +1,28 @@
describe("Version module", function()
local Version
setup(function()
require("commonrequire")
Version = require("version")
end)
it("should get current revision", function()
assert.is_true(22 >= (Version:getCurrentRevision()):len())
end)
it("should get normalized current version", function()
assert.is_true(9 >= tostring(Version:getNormalizedCurrentVersion()):len())
end)
it("should get normalized version", function()
local rev = "v2015.11-982-g704d4238"
local version, commit = Version:getNormalizedVersion(rev)
local expected_version = 201511982
local expected_commit = "704d4238"
assert.are.same(expected_version, version)
assert.are.same(expected_commit, commit)
end)
it("should fail gracefully", function()
local version, commit = Version:getNormalizedVersion()
local expected_version = nil
local expected_commit = nil
assert.are.same(expected_version, version)
assert.are.same(expected_commit, commit)
end)
end)
Loading…
Cancel
Save