Ask for connection when clicking on Wikipedia

pull/2492/head
robert00s 7 years ago committed by Qingping Hou
parent 130f7b0773
commit fe5379814d

@ -4,6 +4,9 @@ local Wikipedia = require("ui/wikipedia")
local logger = require("logger")
local _ = require("gettext")
local T = require("ffi/util").template
local NetworkMgr = require("ui/network/manager")
local InputDialog = require("ui/widget/inputdialog")
local UIManager = require("ui/uimanager")
-- Wikipedia as a special dictionary
local ReaderWikipedia = ReaderDictionary:extend{
@ -17,16 +20,44 @@ function ReaderWikipedia:init()
self.ui.menu:registerToMainMenu(self)
end
function ReaderWikipedia:lookupInput()
self.input_dialog = InputDialog:new{
title = _("Enter words to look up on Wikipedia"),
input = "",
input_type = "text",
buttons = {
{
{
text = _("Cancel"),
callback = function()
UIManager:close(self.input_dialog)
end,
},
{
text = _("OK"),
is_enter_default = true,
callback = function()
UIManager:close(self.input_dialog)
self:onLookupWikipedia(self.input_dialog:getInputText())
end,
},
}
},
}
self.input_dialog:onShowKeyboard()
UIManager:show(self.input_dialog)
end
function ReaderWikipedia:addToMainMenu(tab_item_table)
table.insert(tab_item_table.plugins, {
text = _("Wikipedia lookup"),
tap_input = {
title = _("Enter words to look up on Wikipedia"),
type = "text",
callback = function(input)
self:onLookupWikipedia(input)
end,
},
callback = function()
if NetworkMgr:isOnline() then
self:lookupInput()
else
NetworkMgr:promptWifiOn()
end
end
})
end
@ -71,6 +102,10 @@ function ReaderWikipedia:initLanguages(word)
end
function ReaderWikipedia:onLookupWikipedia(word, box, get_fullpage)
if not NetworkMgr:isOnline() then
NetworkMgr:promptWifiOn()
return
end
-- word is the text to query. If get_fullpage is true, it is the
-- exact wikipedia page title we want the full page of.
self:initLanguages(word)

Loading…
Cancel
Save