diff --git a/frontend/apps/reader/modules/readerdevicestatus.lua b/frontend/apps/reader/modules/readerdevicestatus.lua index c6f9dbbbd..f7a65e791 100644 --- a/frontend/apps/reader/modules/readerdevicestatus.lua +++ b/frontend/apps/reader/modules/readerdevicestatus.lua @@ -171,7 +171,8 @@ function ReaderDeviceStatus:addToMainMenu(menu_items) keep_menu_open = true, callback = function(touchmenu_instance) local DoubleSpinWidget = require("/ui/widget/doublespinwidget") - local thresholds_widget = DoubleSpinWidget:new{ + local thresholds_widget + thresholds_widget = DoubleSpinWidget:new{ title_text = _("Battery level alert thresholds"), info_text = _([[ Low level threshold is checked when the device is not charging. @@ -190,11 +191,15 @@ High level threshold is checked when the device is charging.]]), right_hold_step = 5, default_values = true, callback = function(left_value, right_value) - if not left_value then return end -- "Use defaults" pressed + if not left_value then -- "Default" button pressed + left_value = 20 + right_value = 100 + end self.battery_threshold = left_value self.battery_threshold_high = right_value G_reader_settings:saveSetting("device_status_battery_threshold", self.battery_threshold) G_reader_settings:saveSetting("device_status_battery_threshold_high", self.battery_threshold_high) + UIManager:close(thresholds_widget) touchmenu_instance:updateItems() powerd:setDismissBatteryStatus(false) end, diff --git a/frontend/apps/reader/modules/readertypography.lua b/frontend/apps/reader/modules/readertypography.lua index be4ca2e2b..851be16a4 100644 --- a/frontend/apps/reader/modules/readertypography.lua +++ b/frontend/apps/reader/modules/readertypography.lua @@ -374,6 +374,7 @@ When the book's language tag is not among our presets, no specific features will right_default = alg_right_hyphen_min, -- let room on the widget sides so we can see -- the hyphenation changes happening + width_factor = 0.6, default_values = true, default_text = _("Use language defaults"), title_text = _("Hyphenation limits"), diff --git a/frontend/ui/widget/doublespinwidget.lua b/frontend/ui/widget/doublespinwidget.lua index bc6557a42..f14e3fd43 100644 --- a/frontend/ui/widget/doublespinwidget.lua +++ b/frontend/ui/widget/doublespinwidget.lua @@ -20,6 +20,7 @@ local VerticalSpan = require("ui/widget/verticalspan") local WidgetContainer = require("ui/widget/container/widgetcontainer") local _ = require("gettext") local Screen = Device.screen +local T = require("ffi/util").template local DoubleSpinWidget = InputContainer:new{ title_text = "", @@ -28,26 +29,30 @@ local DoubleSpinWidget = InputContainer:new{ width = nil, width_factor = nil, -- number between 0 and 1, factor to the smallest of screen width and height height = nil, + left_text = _("Left"), left_min = 1, left_max = 20, left_value = 1, left_default = nil, - left_text = _("Left"), + left_precision = nil, -- default "%02d" in NumberPickerWidget + left_wrap = false, + right_text = _("Right"), right_min = 1, right_max = 20, right_value = 1, right_default = nil, - right_text = _("Right"), + right_precision = nil, + right_wrap = false, cancel_text = _("Close"), ok_text = _("Apply"), cancel_callback = nil, callback = nil, close_callback = nil, keep_shown_on_apply = false, - -- Set this to add default button that restores numbers to their default values - default_values = nil, - default_text = _("Use defaults"), - -- Optional extra button on bottom + -- Set this to add upper default button that applies default values with callback(nil, nil) + default_values = false, + default_text = nil, + -- Optional extra button above ok/cancel buttons row extra_text = nil, extra_callback = nil, } @@ -63,7 +68,7 @@ function DoubleSpinWidget:init() end if Device:hasKeys() then self.key_events = { - Close = { {"Back"}, doc = "close time widget" } + Close = { {"Back"}, doc = "close doublespin widget" } } end if Device:isTouchDevice() then @@ -92,8 +97,8 @@ function DoubleSpinWidget:update() value_max = self.left_max, value_step = self.left_step, value_hold_step = self.left_hold_step, - precision = self.precision, - wrap = self.left_wrap or false, + precision = self.left_precision, + wrap = self.left_wrap, } local right_widget = NumberPickerWidget:new{ show_parent = self, @@ -102,12 +107,11 @@ function DoubleSpinWidget:update() value_max = self.right_max, value_step = self.right_step, value_hold_step = self.right_hold_step, - precision = self.precision, - wrap = self.right_wrap or false, + precision = self.right_precision, + wrap = self.right_wrap, } local left_vertical_group = VerticalGroup:new{ align = "center", - VerticalSpan:new{ width = Size.span.vertical_large }, TextWidget:new{ text = self.left_text, face = self.title_face, @@ -117,7 +121,6 @@ function DoubleSpinWidget:update() } local right_vertical_group = VerticalGroup:new{ align = "center", - VerticalSpan:new{ width = Size.span.vertical_large }, TextWidget:new{ text = self.right_text, face = self.title_face, @@ -173,34 +176,14 @@ function DoubleSpinWidget:update() else widget_info = VerticalSpan:new{ width = 0 } end - local buttons = { - { - { - text = self.cancel_text, - callback = function() - if self.cancel_callback then - self.cancel_callback() - end - self:onClose() - end, - }, - { - text = self.ok_text, - callback = function() - if self.callback then - self.callback(left_widget:getValue(), right_widget:getValue()) - end - if not self.keep_shown_on_apply then - self:onClose() - end - end, - }, - }, - } + + local buttons = {} if self.default_values then - table.insert(buttons,{ + table.insert(buttons, { { - text = self.default_text, + text = self.default_text or T(_("Apply default values: %1 / %2"), + self.left_precision and string.format(self.left_precision, self.left_default) or self.left_default, + self.right_precision and string.format(self.right_precision, self.right_default) or self.right_default), callback = function() left_widget.value = self.left_default right_widget.value = self.right_default @@ -212,7 +195,7 @@ function DoubleSpinWidget:update() }) end if self.extra_text then - table.insert(buttons,{ + table.insert(buttons, { { text = self.extra_text, callback = function() @@ -226,6 +209,28 @@ function DoubleSpinWidget:update() }, }) end + table.insert(buttons, { + { + text = self.cancel_text, + callback = function() + if self.cancel_callback then + self.cancel_callback() + end + self:onClose() + end, + }, + { + text = self.ok_text, + callback = function() + if self.callback then + self.callback(left_widget:getValue(), right_widget:getValue()) + end + if not self.keep_shown_on_apply then + self:onClose() + end + end, + }, + }) local button_table = ButtonTable:new{ width = self.width - 2*Size.padding.default, @@ -244,15 +249,13 @@ function DoubleSpinWidget:update() widget_title, widget_line, widget_info, - VerticalSpan:new{ width = Size.span.vertical_large }, CenterContainer:new{ dimen = Geom:new{ w = self.width, - h = widget_group:getSize().h, + h = widget_group:getSize().h + 4 * Size.padding.large, }, widget_group }, - VerticalSpan:new{ width = Size.span.vertical_large }, CenterContainer:new{ dimen = Geom:new{ w = self.width, diff --git a/plugins/autowarmth.koplugin/main.lua b/plugins/autowarmth.koplugin/main.lua index 0d69aa1ec..7eaf62850 100644 --- a/plugins/autowarmth.koplugin/main.lua +++ b/plugins/autowarmth.koplugin/main.lua @@ -481,19 +481,18 @@ function AutoWarmth:getLocationMenu() info_text = _("Enter decimal degrees, northern hemisphere and eastern length are '+'."), left_text = _("Latitude"), left_value = self.latitude, - left_default = 0, left_min = -90, left_max = 90, left_step = 0.1, - precision = "%0.2f", left_hold_step = 5, + left_precision = "%0.2f", right_text = _("Longitude"), right_value = self.longitude, - right_default = 0, right_min = -180, right_max = 180, right_step = 0.1, right_hold_step = 5, + right_precision = "%0.2f", callback = function(lat, long) self.latitude = lat self.longitude = long @@ -582,7 +581,6 @@ function AutoWarmth:getScheduleMenu() title_text = _("Set time"), left_text = _("HH"), left_value = hh, - left_default = 0, left_min = 0, left_max = 23, left_step = 1, @@ -590,7 +588,6 @@ function AutoWarmth:getScheduleMenu() left_wrap = true, right_text = _("MM"), right_value = mm, - right_default = 0, right_min = 0, right_max = 59, right_step = 1, diff --git a/plugins/statistics.koplugin/main.lua b/plugins/statistics.koplugin/main.lua index 5ff095305..52e5555eb 100644 --- a/plugins/statistics.koplugin/main.lua +++ b/plugins/statistics.koplugin/main.lua @@ -915,17 +915,15 @@ function ReaderStatistics:addToMainMenu(menu_items) right_step = 10, right_hold_step = 60, default_values = true, - default_text = _("Use defaults"), title_text = _("Read page duration limits"), info_text = _([[ Set min and max time spent (in seconds) on a page for it to be counted as read in statistics. The min value ensures pages you quickly browse and skip are not included. The max value ensures a page you stay on for a long time (because you fell asleep or went away) will be included, but with a duration capped to this specified max value.]]), callback = function(min, max) - if not min then min = DEFAULT_MIN_READ_SEC end - if not max then max = DEFAULT_MAX_READ_SEC end - if min > max then - min, max = max, min + if not min then -- "Default" button pressed + min = DEFAULT_MIN_READ_SEC + max = DEFAULT_MAX_READ_SEC end self.settings.min_sec = min self.settings.max_sec = max