mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
@@ -12,6 +12,10 @@ local ReaderCoptListener = EventListener:extend{}
|
|||||||
|
|
||||||
local CRE_HEADER_DEFAULT_SIZE = 20
|
local CRE_HEADER_DEFAULT_SIZE = 20
|
||||||
|
|
||||||
|
function ReaderCoptListener:init()
|
||||||
|
self.additional_header_content = {} -- place, where additional header content can be inserted.
|
||||||
|
end
|
||||||
|
|
||||||
function ReaderCoptListener:onReadSettings(config)
|
function ReaderCoptListener:onReadSettings(config)
|
||||||
local view_mode_name = self.document.configurable.view_mode == 0 and "page" or "scroll"
|
local view_mode_name = self.document.configurable.view_mode == 0 and "page" or "scroll"
|
||||||
-- Let crengine know of the view mode before rendering, as it can
|
-- Let crengine know of the view mode before rendering, as it can
|
||||||
@@ -44,6 +48,7 @@ function ReaderCoptListener:onReadSettings(config)
|
|||||||
-- We will build the top status bar page info string ourselves,
|
-- We will build the top status bar page info string ourselves,
|
||||||
-- if we have to display any chunk of it
|
-- if we have to display any chunk of it
|
||||||
self.page_info_override = self.page_number == 1 or self.page_count == 1 or self.reading_percent == 1
|
self.page_info_override = self.page_number == 1 or self.page_count == 1 or self.reading_percent == 1
|
||||||
|
or (self.battery == 1 and self.battery_percent == 1) -- don't forget a sole battery
|
||||||
self.document:setPageInfoOverride("") -- an empty string lets crengine display its own page info
|
self.document:setPageInfoOverride("") -- an empty string lets crengine display its own page info
|
||||||
|
|
||||||
self:onTimeFormatChanged()
|
self:onTimeFormatChanged()
|
||||||
@@ -84,7 +89,10 @@ end
|
|||||||
function ReaderCoptListener:updatePageInfoOverride(pageno)
|
function ReaderCoptListener:updatePageInfoOverride(pageno)
|
||||||
pageno = pageno or self.ui.view.footer.pageno
|
pageno = pageno or self.ui.view.footer.pageno
|
||||||
|
|
||||||
if not (self.document.configurable.status_line == 0 and self.view.view_mode == "page" and self.page_info_override) then
|
if self.document.configurable.status_line ~= 0 or self.view.view_mode ~= "page"
|
||||||
|
or not self.page_info_override or not next(self.additional_header_content) then
|
||||||
|
|
||||||
|
self.document:setPageInfoOverride("")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- There are a few cases where we may not be updated on change, at least:
|
-- There are a few cases where we may not be updated on change, at least:
|
||||||
@@ -126,7 +134,18 @@ function ReaderCoptListener:updatePageInfoOverride(pageno)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local page_info = ""
|
local additional_content = ""
|
||||||
|
for dummy, v in ipairs(self.additional_header_content) do
|
||||||
|
local value = v()
|
||||||
|
if value and value ~= "" then
|
||||||
|
additional_content = additional_content .. value
|
||||||
|
if self.page_number == 1 or self.page_count == 1 then
|
||||||
|
additional_content = additional_content .. " " -- double spaces as crengine's own drawing
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local page_info = additional_content
|
||||||
if self.page_number == 1 or self.page_count == 1 then
|
if self.page_number == 1 or self.page_count == 1 then
|
||||||
page_info = page_info .. page_pre
|
page_info = page_info .. page_pre
|
||||||
if self.page_number == 1 then
|
if self.page_number == 1 then
|
||||||
@@ -158,13 +177,13 @@ function ReaderCoptListener:updatePageInfoOverride(pageno)
|
|||||||
if Device:hasAuxBattery() and powerd:isAuxBatteryConnected() then
|
if Device:hasAuxBattery() and powerd:isAuxBatteryConnected() then
|
||||||
local aux_batt_lvl = powerd:getAuxCapacity()
|
local aux_batt_lvl = powerd:getAuxCapacity()
|
||||||
if powerd:isAuxCharging() then
|
if powerd:isAuxCharging() then
|
||||||
batt_pre = "[\u{21AF}"
|
batt_pre = "[\u{21AF}" -- ↯-symbol
|
||||||
end
|
end
|
||||||
-- Sum both batteries for the actual text
|
-- Sum both batteries for the actual text
|
||||||
batt_lvl = batt_lvl + aux_batt_lvl
|
batt_lvl = batt_lvl + aux_batt_lvl
|
||||||
else
|
else
|
||||||
if powerd:isCharging() then
|
if powerd:isCharging() then
|
||||||
batt_pre = "[\u{21AF}"
|
batt_pre = "[\u{21AF}" -- ↯-symbol
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
batt_val = string.format("%2d%%", batt_lvl)
|
batt_val = string.format("%2d%%", batt_lvl)
|
||||||
@@ -300,15 +319,30 @@ end
|
|||||||
ReaderCoptListener.onCloseDocument = ReaderCoptListener.unscheduleHeaderRefresh
|
ReaderCoptListener.onCloseDocument = ReaderCoptListener.unscheduleHeaderRefresh
|
||||||
ReaderCoptListener.onSuspend = ReaderCoptListener.unscheduleHeaderRefresh
|
ReaderCoptListener.onSuspend = ReaderCoptListener.unscheduleHeaderRefresh
|
||||||
|
|
||||||
|
function ReaderCoptListener:addAdditionalHeaderContent(content_func)
|
||||||
|
table.insert(self.additional_header_content, content_func)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ReaderCoptListener:removeAdditionalHeaderContent(content_func)
|
||||||
|
for i, v in ipairs(self.additional_header_content) do
|
||||||
|
if v == content_func then
|
||||||
|
table.remove(self.additional_header_content, i)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function ReaderCoptListener:setAndSave(setting, property, value)
|
function ReaderCoptListener:setAndSave(setting, property, value)
|
||||||
self.document._document:setIntProperty(property, value)
|
self.document._document:setIntProperty(property, value)
|
||||||
G_reader_settings:saveSetting(setting, value)
|
G_reader_settings:saveSetting(setting, value)
|
||||||
self.page_info_override = self.page_number == 1 or self.page_count == 1 or self.reading_percent == 1
|
self:onUpdateHeader()
|
||||||
if self.page_info_override then
|
|
||||||
self:updatePageInfoOverride()
|
|
||||||
else
|
|
||||||
self.document:setPageInfoOverride("") -- Don't forget to restore CRE default behaviour.
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ReaderCoptListener:onUpdateHeader()
|
||||||
|
self.page_info_override = self.page_number == 1 or self.page_count == 1 or self.reading_percent == 1
|
||||||
|
or (self.battery == 1 and self.battery_percent == 1) -- don't forget a sole battery
|
||||||
|
|
||||||
|
self:updatePageInfoOverride()
|
||||||
-- Have crengine redraw it (even if hidden by the menu at this time)
|
-- Have crengine redraw it (even if hidden by the menu at this time)
|
||||||
self.ui.rolling:updateBatteryState()
|
self.ui.rolling:updateBatteryState()
|
||||||
self:updateHeader()
|
self:updateHeader()
|
||||||
|
|||||||
@@ -341,10 +341,10 @@ local footerTextGeneratorMap = {
|
|||||||
prefix .. " ", left)
|
prefix .. " ", left)
|
||||||
end,
|
end,
|
||||||
mem_usage = function(footer)
|
mem_usage = function(footer)
|
||||||
local symbol_type = footer.settings.item_prefix
|
|
||||||
local prefix = symbol_prefix[symbol_type].mem_usage
|
|
||||||
local statm = io.open("/proc/self/statm", "r")
|
local statm = io.open("/proc/self/statm", "r")
|
||||||
if statm then
|
if statm then
|
||||||
|
local symbol_type = footer.settings.item_prefix
|
||||||
|
local prefix = symbol_prefix[symbol_type].mem_usage
|
||||||
local dummy, rss = statm:read("*number", "*number")
|
local dummy, rss = statm:read("*number", "*number")
|
||||||
statm:close()
|
statm:close()
|
||||||
-- we got the nb of 4Kb-pages used, that we convert to MiB
|
-- we got the nb of 4Kb-pages used, that we convert to MiB
|
||||||
@@ -516,6 +516,8 @@ ReaderFooter.default_settings = {
|
|||||||
function ReaderFooter:init()
|
function ReaderFooter:init()
|
||||||
self.settings = G_reader_settings:readSetting("footer", self.default_settings)
|
self.settings = G_reader_settings:readSetting("footer", self.default_settings)
|
||||||
|
|
||||||
|
self.additional_footer_content = {} -- place, where additional header content can be inserted.
|
||||||
|
|
||||||
-- Remove items not supported by the current device
|
-- Remove items not supported by the current device
|
||||||
if not Device:hasFastWifiStatusQuery() then
|
if not Device:hasFastWifiStatusQuery() then
|
||||||
MODE.wifi_status = nil
|
MODE.wifi_status = nil
|
||||||
@@ -1981,6 +1983,19 @@ function ReaderFooter:genAlignmentMenuItems(value)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ReaderFooter:addAdditionalFooterContent(content_func)
|
||||||
|
table.insert(self.additional_footer_content, content_func)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ReaderFooter:removeAdditionalFooterContent(content_func)
|
||||||
|
for i, v in ipairs(self.additional_footer_content) do
|
||||||
|
if v == content_func then
|
||||||
|
table.remove(self.additional_footer_content, i)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- this method will be updated at runtime based on user setting
|
-- this method will be updated at runtime based on user setting
|
||||||
function ReaderFooter:genFooterText() end
|
function ReaderFooter:genFooterText() end
|
||||||
|
|
||||||
@@ -2153,6 +2168,13 @@ function ReaderFooter:_updateFooterText(force_repaint, full_repaint)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local text = self:genFooterText()
|
local text = self:genFooterText()
|
||||||
|
for dummy, v in ipairs(self.additional_footer_content) do
|
||||||
|
local value = v()
|
||||||
|
if value and value ~= "" then
|
||||||
|
text = value .. " " .. self:get_separator_symbol() .. " " .. text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if not text then text = "" end
|
if not text then text = "" end
|
||||||
self.footer_text:setText(text)
|
self.footer_text:setText(text)
|
||||||
if self.settings.disable_progress_bar then
|
if self.settings.disable_progress_bar then
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ local Geom = require("ui/geometry")
|
|||||||
local GestureRange = require("ui/gesturerange")
|
local GestureRange = require("ui/gesturerange")
|
||||||
local Font = require("ui/font")
|
local Font = require("ui/font")
|
||||||
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
||||||
|
local HorizontalSpan = require("ui/widget/horizontalspan")
|
||||||
local NumberPickerWidget = require("ui/widget/numberpickerwidget")
|
local NumberPickerWidget = require("ui/widget/numberpickerwidget")
|
||||||
local Size = require("ui/size")
|
local Size = require("ui/size")
|
||||||
local TextWidget = require("ui/widget/textwidget")
|
local TextWidget = require("ui/widget/textwidget")
|
||||||
@@ -342,7 +343,9 @@ function DateTimeWidget:createLayout()
|
|||||||
self.sec = self.sec_widget:getValue()
|
self.sec = self.sec_widget:getValue()
|
||||||
self:callback(self)
|
self:callback(self)
|
||||||
end
|
end
|
||||||
|
if not self.keep_shown_on_apply then
|
||||||
self:onClose()
|
self:onClose()
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -369,17 +372,18 @@ function DateTimeWidget:createLayout()
|
|||||||
w = self.width,
|
w = self.width,
|
||||||
h = math.floor(date_group:getSize().h * 1.2),
|
h = math.floor(date_group:getSize().h * 1.2),
|
||||||
},
|
},
|
||||||
date_group
|
date_group,
|
||||||
},
|
},
|
||||||
CenterContainer:new{
|
CenterContainer:new{
|
||||||
dimen = Geom:new{
|
dimen = Geom:new{
|
||||||
w = self.width,
|
w = self.width,
|
||||||
h = ok_cancel_buttons:getSize().h,
|
h = ok_cancel_buttons:getSize().h,
|
||||||
},
|
},
|
||||||
ok_cancel_buttons
|
ok_cancel_buttons,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self[1] = WidgetContainer:new{
|
self[1] = WidgetContainer:new{
|
||||||
align = "center",
|
align = "center",
|
||||||
dimen = Geom:new{
|
dimen = Geom:new{
|
||||||
@@ -396,6 +400,21 @@ function DateTimeWidget:createLayout()
|
|||||||
self:refocusWidget()
|
self:refocusWidget()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function DateTimeWidget:addWidget(widget)
|
||||||
|
table.insert(self.layout, #self.layout, {widget})
|
||||||
|
widget = HorizontalGroup:new{
|
||||||
|
align = "center",
|
||||||
|
HorizontalSpan:new{ width = Size.span.horizontal_default },
|
||||||
|
widget,
|
||||||
|
}
|
||||||
|
table.insert(self.date_frame[1], #self.date_frame[1], widget)
|
||||||
|
end
|
||||||
|
|
||||||
|
function DateTimeWidget:getAddedWidgetAvailableWidth()
|
||||||
|
return self.date_frame[1][1].width - 2*Size.padding.default
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function DateTimeWidget:update(year, month, day, hour, min, sec)
|
function DateTimeWidget:update(year, month, day, hour, min, sec)
|
||||||
self.year_widget.value = year
|
self.year_widget.value = year
|
||||||
self.year_widget:update()
|
self.year_widget:update()
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
local DateTimeWidget = require("ui/widget/datetimewidget")
|
local CheckButton = require("ui/widget/checkbutton")
|
||||||
local InfoMessage = require("ui/widget/infomessage")
|
|
||||||
local ConfirmBox = require("ui/widget/confirmbox")
|
local ConfirmBox = require("ui/widget/confirmbox")
|
||||||
|
local DateTimeWidget = require("ui/widget/datetimewidget")
|
||||||
|
local Event = require("ui/event")
|
||||||
|
local InfoMessage = require("ui/widget/infomessage")
|
||||||
local UIManager = require("ui/uimanager")
|
local UIManager = require("ui/uimanager")
|
||||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||||
local logger = require("logger")
|
local logger = require("logger")
|
||||||
local datetime = require("datetime")
|
local datetime = require("datetime")
|
||||||
|
local time = require("ui/time")
|
||||||
local _ = require("gettext")
|
local _ = require("gettext")
|
||||||
local T = require("ffi/util").template
|
local T = require("ffi/util").template
|
||||||
|
|
||||||
@@ -15,6 +18,9 @@ local ReadTimer = WidgetContainer:extend{
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ReadTimer:init()
|
function ReadTimer:init()
|
||||||
|
self.timer_symbol = "\u{23F2}" -- ⏲ timer symbol
|
||||||
|
self.timer_letter = "T"
|
||||||
|
|
||||||
self.alarm_callback = function()
|
self.alarm_callback = function()
|
||||||
-- Don't do anything if we were unscheduled
|
-- Don't do anything if we were unscheduled
|
||||||
if self.time == 0 then return end
|
if self.time == 0 then return end
|
||||||
@@ -46,18 +52,78 @@ function ReadTimer:init()
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.additional_header_content_func = function()
|
||||||
|
if self:scheduled() then
|
||||||
|
local hours, minutes, dummy = self:remainingTime(1)
|
||||||
|
local timer_info = string.format("%02d:%02d", hours, minutes)
|
||||||
|
return self.timer_symbol .. timer_info
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
self.additional_footer_content_func = function()
|
||||||
|
if self:scheduled() then
|
||||||
|
local item_prefix = self.ui.view.footer.settings.item_prefix
|
||||||
|
local hours, minutes, dummy = self:remainingTime(1)
|
||||||
|
local timer_info = string.format("%02d:%02d", hours, minutes)
|
||||||
|
|
||||||
|
if item_prefix == "icons" then
|
||||||
|
return self.timer_symbol .. " " .. timer_info
|
||||||
|
elseif item_prefix == "compact_items" then
|
||||||
|
return self.timer_symbol .. timer_info
|
||||||
|
else
|
||||||
|
return self.timer_letter .. ": " .. timer_info
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
self.show_value_in_header = G_reader_settings:readSetting("readtimer_show_value_in_header")
|
||||||
|
self.show_value_in_footer = G_reader_settings:readSetting("readtimer_show_value_in_footer")
|
||||||
|
|
||||||
|
if self.show_value_in_header then
|
||||||
|
self:addAdditionalHeaderContent()
|
||||||
|
else
|
||||||
|
self:removeAdditionalHeaderContent()
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.show_value_in_footer then
|
||||||
|
self:addAdditionalFooterContent()
|
||||||
|
else
|
||||||
|
self:removeAdditionalFooterContent()
|
||||||
|
end
|
||||||
|
|
||||||
self.ui.menu:registerToMainMenu(self)
|
self.ui.menu:registerToMainMenu(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ReadTimer:update_status_bars(seconds)
|
||||||
|
if self.show_value_in_header then
|
||||||
|
UIManager:broadcastEvent(Event:new("UpdateHeader"))
|
||||||
|
end
|
||||||
|
if self.show_value_in_footer then
|
||||||
|
UIManager:broadcastEvent(Event:new("UpdateFooter", true))
|
||||||
|
end
|
||||||
|
-- if seconds schedule 1ms later
|
||||||
|
if seconds and seconds >= 0 then
|
||||||
|
UIManager:scheduleIn(math.max(math.floor(seconds)%60, 0.001), self.update_status_bars, self)
|
||||||
|
elseif seconds and seconds < 0 and self:scheduled() then
|
||||||
|
UIManager:scheduleIn(math.max(math.floor(self:remaining())%60, 0.001), self.update_status_bars, self)
|
||||||
|
else
|
||||||
|
UIManager:scheduleIn(60, self.update_status_bars, self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function ReadTimer:scheduled()
|
function ReadTimer:scheduled()
|
||||||
return self.time ~= 0
|
return self.time ~= 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function ReadTimer:remaining()
|
function ReadTimer:remaining()
|
||||||
if self:scheduled() then
|
if self:scheduled() then
|
||||||
local td = os.difftime(self.time, os.time())
|
-- Resolution: time.now() subsecond, os.time() two seconds
|
||||||
if td > 0 then
|
local remaining_s = time.to_s(self.time - time.now())
|
||||||
return td
|
if remaining_s > 0 then
|
||||||
|
return remaining_s
|
||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
@@ -66,9 +132,21 @@ function ReadTimer:remaining()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ReadTimer:remainingTime()
|
-- can round
|
||||||
|
function ReadTimer:remainingTime(round)
|
||||||
if self:scheduled() then
|
if self:scheduled() then
|
||||||
local remainder = self:remaining()
|
local remainder = self:remaining()
|
||||||
|
if round then
|
||||||
|
if round < 0 then -- round down
|
||||||
|
remainder = remainder - 59
|
||||||
|
elseif round == 0 then
|
||||||
|
remainder = remainder + 30
|
||||||
|
else -- round up
|
||||||
|
remainder = remainder + 59
|
||||||
|
end
|
||||||
|
remainder = math.floor(remainder * (1/60)) * 60
|
||||||
|
end
|
||||||
|
|
||||||
local hours = math.floor(remainder * (1/3600))
|
local hours = math.floor(remainder * (1/3600))
|
||||||
local minutes = math.floor(remainder % 3600 * (1/60))
|
local minutes = math.floor(remainder % 3600 * (1/60))
|
||||||
local seconds = math.floor(remainder % 60)
|
local seconds = math.floor(remainder % 60)
|
||||||
@@ -76,16 +154,74 @@ function ReadTimer:remainingTime()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ReadTimer:addAdditionalHeaderContent()
|
||||||
|
self.ui.crelistener:addAdditionalHeaderContent(self.additional_header_content_func)
|
||||||
|
self:update_status_bars(-1)
|
||||||
|
end
|
||||||
|
function ReadTimer:addAdditionalFooterContent()
|
||||||
|
self.ui.view.footer:addAdditionalFooterContent(self.additional_footer_content_func)
|
||||||
|
self:update_status_bars(-1)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ReadTimer:removeAdditionalHeaderContent()
|
||||||
|
self.ui.crelistener:removeAdditionalHeaderContent(self.additional_header_content_func)
|
||||||
|
self:update_status_bars(-1)
|
||||||
|
UIManager:broadcastEvent(Event:new("UpdateHeader"))
|
||||||
|
end
|
||||||
|
function ReadTimer:removeAdditionalFooterContent()
|
||||||
|
self.ui.view.footer:removeAdditionalFooterContent(self.additional_footer_content_func)
|
||||||
|
self:update_status_bars(-1)
|
||||||
|
UIManager:broadcastEvent(Event:new("UpdateFooter", true))
|
||||||
|
end
|
||||||
|
|
||||||
function ReadTimer:unschedule()
|
function ReadTimer:unschedule()
|
||||||
if self:scheduled() then
|
if self:scheduled() then
|
||||||
UIManager:unschedule(self.alarm_callback)
|
UIManager:unschedule(self.alarm_callback)
|
||||||
self.time = 0
|
self.time = 0
|
||||||
end
|
end
|
||||||
|
UIManager:unschedule(self.update_status_bars, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ReadTimer:rescheduleIn(seconds)
|
function ReadTimer:rescheduleIn(seconds)
|
||||||
self.time = os.time() + seconds
|
-- Resolution: time.now() subsecond, os.time() two seconds
|
||||||
|
self.time = time.now() + time.s(seconds)
|
||||||
UIManager:scheduleIn(seconds, self.alarm_callback)
|
UIManager:scheduleIn(seconds, self.alarm_callback)
|
||||||
|
if self.show_value_in_header or self.show_value_in_footer then
|
||||||
|
self:update_status_bars(seconds)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function ReadTimer:addCheckboxes(widget)
|
||||||
|
local checkbox_header = CheckButton:new{
|
||||||
|
text = _("Show timer in alt status bar"),
|
||||||
|
checked = self.show_value_in_header,
|
||||||
|
parent = widget,
|
||||||
|
callback = function()
|
||||||
|
self.show_value_in_header = not self.show_value_in_header
|
||||||
|
G_reader_settings:saveSetting("readtimer_show_value_in_header", self.show_value_in_header)
|
||||||
|
if self.show_value_in_header then
|
||||||
|
self:addAdditionalHeaderContent()
|
||||||
|
else
|
||||||
|
self:removeAdditionalHeaderContent()
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
local checkbox_footer = CheckButton:new{
|
||||||
|
text = _("Show timer in status bar"),
|
||||||
|
checked = self.show_value_in_footer,
|
||||||
|
parent = widget,
|
||||||
|
callback = function()
|
||||||
|
self.show_value_in_footer = not self.show_value_in_footer
|
||||||
|
G_reader_settings:saveSetting("readtimer_show_value_in_footer", self.show_value_in_footer)
|
||||||
|
if self.show_value_in_footer then
|
||||||
|
self:addAdditionalFooterContent()
|
||||||
|
else
|
||||||
|
self:removeAdditionalFooterContent()
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
widget:addWidget(checkbox_header)
|
||||||
|
widget:addWidget(checkbox_footer)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ReadTimer:addToMainMenu(menu_items)
|
function ReadTimer:addToMainMenu(menu_items)
|
||||||
@@ -116,13 +252,12 @@ function ReadTimer:addToMainMenu(menu_items)
|
|||||||
ok_text = _("Set alarm"),
|
ok_text = _("Set alarm"),
|
||||||
title_text = _("New alarm"),
|
title_text = _("New alarm"),
|
||||||
info_text = _("Enter a time in hours and minutes."),
|
info_text = _("Enter a time in hours and minutes."),
|
||||||
callback = function(time)
|
callback = function(alarm_time)
|
||||||
self.last_interval_time = 0
|
self.last_interval_time = 0
|
||||||
touchmenu_instance:closeMenu()
|
|
||||||
self:unschedule()
|
self:unschedule()
|
||||||
local then_t = now_t
|
local then_t = now_t
|
||||||
then_t.hour = time.hour
|
then_t.hour = alarm_time.hour
|
||||||
then_t.min = time.min
|
then_t.min = alarm_time.min
|
||||||
then_t.sec = 0
|
then_t.sec = 0
|
||||||
local seconds = os.difftime(os.time(then_t), os.time())
|
local seconds = os.difftime(os.time(then_t), os.time())
|
||||||
if seconds > 0 then
|
if seconds > 0 then
|
||||||
@@ -131,10 +266,11 @@ function ReadTimer:addToMainMenu(menu_items)
|
|||||||
UIManager:show(InfoMessage:new{
|
UIManager:show(InfoMessage:new{
|
||||||
-- @translators %1:%2 is a clock time (HH:MM), %3 is a duration
|
-- @translators %1:%2 is a clock time (HH:MM), %3 is a duration
|
||||||
text = T(_("Timer set for %1:%2.\n\nThat's %3 from now."),
|
text = T(_("Timer set for %1:%2.\n\nThat's %3 from now."),
|
||||||
string.format("%02d", time.hour), string.format("%02d", time.min),
|
string.format("%02d", alarm_time.hour), string.format("%02d", alarm_time.min),
|
||||||
datetime.secondsToClockDuration(user_duration_format, seconds, false)),
|
datetime.secondsToClockDuration(user_duration_format, seconds, false)),
|
||||||
timeout = 5,
|
timeout = 5,
|
||||||
})
|
})
|
||||||
|
if touchmenu_instance then touchmenu_instance:updateItems() end
|
||||||
else
|
else
|
||||||
UIManager:show(InfoMessage:new{
|
UIManager:show(InfoMessage:new{
|
||||||
text = _("Timer could not be set. The selected time is in the past."),
|
text = _("Timer could not be set. The selected time is in the past."),
|
||||||
@@ -143,6 +279,7 @@ function ReadTimer:addToMainMenu(menu_items)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
self:addCheckboxes(time_widget)
|
||||||
UIManager:show(time_widget)
|
UIManager:show(time_widget)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
@@ -166,10 +303,9 @@ function ReadTimer:addToMainMenu(menu_items)
|
|||||||
ok_text = _("Set timer"),
|
ok_text = _("Set timer"),
|
||||||
title_text = _("Set reader timer"),
|
title_text = _("Set reader timer"),
|
||||||
info_text = _("Enter a time in hours and minutes."),
|
info_text = _("Enter a time in hours and minutes."),
|
||||||
callback = function(time)
|
callback = function(timer_time)
|
||||||
touchmenu_instance:closeMenu()
|
|
||||||
self:unschedule()
|
self:unschedule()
|
||||||
local seconds = time.hour * 3600 + time.min * 60
|
local seconds = timer_time.hour * 3600 + timer_time.min * 60
|
||||||
if seconds > 0 then
|
if seconds > 0 then
|
||||||
self.last_interval_time = seconds
|
self.last_interval_time = seconds
|
||||||
self:rescheduleIn(seconds)
|
self:rescheduleIn(seconds)
|
||||||
@@ -180,11 +316,14 @@ function ReadTimer:addToMainMenu(menu_items)
|
|||||||
datetime.secondsToClockDuration(user_duration_format, seconds, true)),
|
datetime.secondsToClockDuration(user_duration_format, seconds, true)),
|
||||||
timeout = 5,
|
timeout = 5,
|
||||||
})
|
})
|
||||||
remain_time = {time.hour, time.min}
|
remain_time = {timer_time.hour, timer_time.min}
|
||||||
G_reader_settings:saveSetting("reader_timer_remain_time", remain_time)
|
G_reader_settings:saveSetting("reader_timer_remain_time", remain_time)
|
||||||
|
if touchmenu_instance then touchmenu_instance:updateItems() end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self:addCheckboxes(time_widget)
|
||||||
UIManager:show(time_widget)
|
UIManager:show(time_widget)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user