From fe5379814d0df2d8d7ebcd1ae0ece0b6363e5c26 Mon Sep 17 00:00:00 2001 From: robert00s Date: Sat, 14 Jan 2017 18:38:28 +0100 Subject: [PATCH] Ask for connection when clicking on Wikipedia --- .../apps/reader/modules/readerwikipedia.lua | 49 ++++++++++++++++--- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/frontend/apps/reader/modules/readerwikipedia.lua b/frontend/apps/reader/modules/readerwikipedia.lua index 8a0541473..9372269de 100644 --- a/frontend/apps/reader/modules/readerwikipedia.lua +++ b/frontend/apps/reader/modules/readerwikipedia.lua @@ -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)