mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
KOSync: use MultiInputDialog instead of LoginDialog (#9962)
This commit is contained in:
@@ -1,113 +0,0 @@
|
||||
--[[--
|
||||
This widget displays a login dialog with a username and password.
|
||||
]]
|
||||
|
||||
local Blitbuffer = require("ffi/blitbuffer")
|
||||
local CenterContainer = require("ui/widget/container/centercontainer")
|
||||
local FrameContainer = require("ui/widget/container/framecontainer")
|
||||
local Geom = require("ui/geometry")
|
||||
local InputDialog = require("ui/widget/inputdialog")
|
||||
local InputText = require("ui/widget/inputtext")
|
||||
local Size = require("ui/size")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local VerticalGroup = require("ui/widget/verticalgroup")
|
||||
local _ = require("gettext")
|
||||
local Screen = require("device").screen
|
||||
|
||||
local LoginDialog = InputDialog:extend{
|
||||
username = "",
|
||||
username_hint = "username",
|
||||
password = "",
|
||||
password_hint = "password",
|
||||
bottom_v_padding = Size.padding.default,
|
||||
}
|
||||
|
||||
function LoginDialog:init()
|
||||
-- init title and buttons in base class
|
||||
InputDialog.init(self)
|
||||
self.input_username = InputText:new{
|
||||
text = self.username,
|
||||
hint = self.username_hint,
|
||||
face = self.input_face,
|
||||
width = math.floor(self.width * 0.9),
|
||||
focused = true,
|
||||
scroll = false,
|
||||
parent = self,
|
||||
}
|
||||
|
||||
self.input_password = InputText:new{
|
||||
text = self.password,
|
||||
hint = self.password_hint,
|
||||
face = self.input_face,
|
||||
width = math.floor(self.width * 0.9),
|
||||
text_type = "password",
|
||||
focused = false,
|
||||
scroll = false,
|
||||
parent = self,
|
||||
}
|
||||
|
||||
self.dialog_frame = FrameContainer:new{
|
||||
radius = Size.radius.window,
|
||||
padding = 0,
|
||||
margin = 0,
|
||||
background = Blitbuffer.COLOR_WHITE,
|
||||
VerticalGroup:new{
|
||||
align = "left",
|
||||
self.title_bar,
|
||||
-- username input
|
||||
CenterContainer:new{
|
||||
dimen = Geom:new{
|
||||
w = self.title_bar:getSize().w,
|
||||
h = self.input_username:getSize().h,
|
||||
},
|
||||
self.input_username,
|
||||
},
|
||||
-- password input
|
||||
CenterContainer:new{
|
||||
dimen = Geom:new{
|
||||
w = self.title_bar:getSize().w,
|
||||
h = self.input_password:getSize().h,
|
||||
},
|
||||
self.input_password,
|
||||
},
|
||||
-- buttons
|
||||
CenterContainer:new{
|
||||
dimen = Geom:new{
|
||||
w = self.title_bar:getSize().w,
|
||||
h = self.button_table:getSize().h,
|
||||
},
|
||||
self.button_table,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self._input_widget = self.input_username
|
||||
|
||||
self[1] = CenterContainer:new{
|
||||
dimen = Geom:new{
|
||||
w = Screen:getWidth(),
|
||||
h = Screen:getHeight() - self._input_widget:getKeyboardDimen().h,
|
||||
},
|
||||
self.dialog_frame,
|
||||
}
|
||||
end
|
||||
|
||||
function LoginDialog:getCredential()
|
||||
local username = self.input_username:getText()
|
||||
local password = self.input_password:getText()
|
||||
return username, password
|
||||
end
|
||||
|
||||
function LoginDialog:onSwitchFocus(inputbox)
|
||||
-- unfocus current inputbox
|
||||
self._input_widget:unfocus()
|
||||
self._input_widget:onCloseKeyboard()
|
||||
-- focus new inputbox
|
||||
self._input_widget = inputbox
|
||||
self._input_widget:focus()
|
||||
self._input_widget:onShowKeyboard()
|
||||
UIManager:setDirty(self, "ui")
|
||||
end
|
||||
|
||||
return LoginDialog
|
||||
|
||||
@@ -3,8 +3,8 @@ local Device = require("device")
|
||||
local Dispatcher = require("dispatcher")
|
||||
local Event = require("ui/event")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local LoginDialog = require("ui/widget/logindialog")
|
||||
local Math = require("optmath")
|
||||
local MultiInputDialog = require("ui/widget/multiinputdialog")
|
||||
local NetworkMgr = require("ui/network/manager")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
@@ -12,7 +12,6 @@ local logger = require("logger")
|
||||
local md5 = require("ffi/sha2").md5
|
||||
local random = require("random")
|
||||
local util = require("util")
|
||||
local Screen = Device.screen
|
||||
local T = require("ffi/util").template
|
||||
local _ = require("gettext")
|
||||
|
||||
@@ -364,23 +363,32 @@ function KOSync:login()
|
||||
return
|
||||
end
|
||||
|
||||
self.login_dialog = LoginDialog:new{
|
||||
local dialog
|
||||
dialog = MultiInputDialog:new{
|
||||
title = self.title,
|
||||
username = self.kosync_username or "",
|
||||
fields = {
|
||||
{
|
||||
text = self.kosync_username,
|
||||
hint = "username",
|
||||
},
|
||||
{
|
||||
hint = "password",
|
||||
text_type = "password",
|
||||
},
|
||||
},
|
||||
buttons = {
|
||||
{
|
||||
{
|
||||
text = _("Cancel"),
|
||||
enabled = true,
|
||||
id = "close",
|
||||
callback = function()
|
||||
self:closeDialog()
|
||||
UIManager:close(dialog)
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("Login"),
|
||||
enabled = true,
|
||||
callback = function()
|
||||
local username, password = self:getCredential()
|
||||
local username, password = unpack(dialog:getFields())
|
||||
local ok, err = validateUser(username, password)
|
||||
if not ok then
|
||||
UIManager:show(InfoMessage:new{
|
||||
@@ -388,11 +396,10 @@ function KOSync:login()
|
||||
timeout = 2,
|
||||
})
|
||||
else
|
||||
self:closeDialog()
|
||||
UIManager:close(dialog)
|
||||
UIManager:scheduleIn(0.5, function()
|
||||
self:doLogin(username, password)
|
||||
end)
|
||||
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = _("Logging in. Please wait…"),
|
||||
timeout = 1,
|
||||
@@ -402,9 +409,8 @@ function KOSync:login()
|
||||
},
|
||||
{
|
||||
text = _("Register"),
|
||||
enabled = true,
|
||||
callback = function()
|
||||
local username, password = self:getCredential()
|
||||
local username, password = unpack(dialog:getFields())
|
||||
local ok, err = validateUser(username, password)
|
||||
if not ok then
|
||||
UIManager:show(InfoMessage:new{
|
||||
@@ -412,11 +418,10 @@ function KOSync:login()
|
||||
timeout = 2,
|
||||
})
|
||||
else
|
||||
self:closeDialog()
|
||||
UIManager:close(dialog)
|
||||
UIManager:scheduleIn(0.5, function()
|
||||
self:doRegister(username, password)
|
||||
end)
|
||||
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = _("Registering. Please wait…"),
|
||||
timeout = 1,
|
||||
@@ -426,21 +431,9 @@ function KOSync:login()
|
||||
},
|
||||
},
|
||||
},
|
||||
width = math.floor(Screen:getWidth() * 0.8),
|
||||
height = math.floor(Screen:getHeight() * 0.4),
|
||||
}
|
||||
|
||||
UIManager:show(self.login_dialog)
|
||||
self.login_dialog:onShowKeyboard()
|
||||
end
|
||||
|
||||
function KOSync:closeDialog()
|
||||
self.login_dialog:onClose()
|
||||
UIManager:close(self.login_dialog)
|
||||
end
|
||||
|
||||
function KOSync:getCredential()
|
||||
return self.login_dialog:getCredential()
|
||||
UIManager:show(dialog)
|
||||
dialog:onShowKeyboard()
|
||||
end
|
||||
|
||||
function KOSync:doRegister(username, password)
|
||||
|
||||
Reference in New Issue
Block a user