BookStatusWidget: relocate status toggle buttons (#10179)

Same order as in the new file dialog status buttons.
reviewable/pr10188/r1
hius07 1 year ago committed by GitHub
parent d2ed7402da
commit 3640842bc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -50,6 +50,7 @@ local BookStatusWidget = FocusManager:extend{
} }
function BookStatusWidget:init() function BookStatusWidget:init()
self.updated = false
self.layout = {} self.layout = {}
-- What a blank, full summary table should look like -- What a blank, full summary table should look like
local new_summary = { local new_summary = {
@ -229,7 +230,7 @@ end
function BookStatusWidget:onChangeBookStatus(option_name, option_value) function BookStatusWidget:onChangeBookStatus(option_name, option_value)
self.summary.status = option_name[option_value] self.summary.status = option_name[option_value]
self.summary.modified = os.date("%Y-%m-%d", os.time()) self.summary.modified = os.date("%Y-%m-%d", os.time())
self:saveSummary() self.updated = true
return true return true
end end
@ -250,7 +251,7 @@ function BookStatusWidget:setStar(num)
local row = {} local row = {}
if num then if num then
self.summary.rating = num self.summary.rating = num
self:saveSummary() self.updated = true
for i = 1, num do for i = 1, num do
local star = self.star:new{ local star = self.star:new{
@ -500,19 +501,6 @@ function BookStatusWidget:genSummaryGroup(width)
} }
end end
function BookStatusWidget:onUpdateNote()
self.summary.note = self.input_note:getText()
self:saveSummary()
return true
end
function BookStatusWidget:saveSummary()
if self.summary then
self.settings:saveSetting("summary", self.summary)
self.settings:flush()
end
end
function BookStatusWidget:generateSwitchGroup(width) function BookStatusWidget:generateSwitchGroup(width)
local height local height
if Screen:getScreenMode() == "landscape" then if Screen:getScreenMode() == "landscape" then
@ -523,44 +511,25 @@ function BookStatusWidget:generateSwitchGroup(width)
height = Screen:scaleBySize(105) height = Screen:scaleBySize(105)
end end
local args = { "complete", "reading", "abandoned" } local args = { "reading", "abandoned", "complete", }
local current_status = self.summary.status local position = 1
local position = 2 for k, v in ipairs(args) do
for k, v in pairs(args) do if v == self.summary.status then
if v == current_status then
position = k position = k
break
end end
end end
local config = { local switch = ToggleSwitch:new{
width = math.floor(width * 0.6),
name = "book_status",
event = "ChangeBookStatus", event = "ChangeBookStatus",
default_value = 2, toggle = { _("Reading"), _("On hold"), _("Finished"), },
args = args, args = args,
default_arg = "reading",
toggle = { _("Finished"), _("Reading"), _("On hold") },
values = { 1, 2, 3 },
name = "book_status",
alternate = false, alternate = false,
enabled = true, values = { 1, 2, 3, },
} enabled = not self.readonly,
if self.readonly then
config.enable = false
end
local switch = ToggleSwitch:new{
width = math.floor(width * 0.6),
default_value = config.default_value,
name = config.name,
name_text = config.name_text,
event = config.event,
toggle = config.toggle,
args = config.args,
alternate = config.alternate,
default_arg = config.default_arg,
values = config.values,
enabled = config.enable,
config = self, config = self,
readonly = self.readonly, readonly = self.readonly,
} }
@ -611,7 +580,10 @@ function BookStatusWidget:onMultiSwipe(arg, ges_ev)
end end
function BookStatusWidget:onClose() function BookStatusWidget:onClose()
self:saveSummary() if self.updated and self.summary then
self.settings:saveSetting("summary", self.summary)
self.settings:flush()
end
-- NOTE: Flash on close to avoid ghosting, since we show an image. -- NOTE: Flash on close to avoid ghosting, since we show an image.
UIManager:close(self, "flashpartial") UIManager:close(self, "flashpartial")
return true return true
@ -639,9 +611,11 @@ function BookStatusWidget:onSwitchFocus(inputbox)
text = _("Save review"), text = _("Save review"),
is_enter_default = true, is_enter_default = true,
callback = function() callback = function()
self.input_note:setText(self.note_dialog:getInputText()) local note = self.note_dialog:getInputText()
self.input_note:setText(note)
self.summary.note = note
self.updated = true
self:closeInputDialog() self:closeInputDialog()
self:onUpdateNote()
end, end,
}, },
}, },

Loading…
Cancel
Save