<commit_before>local InputContainer = require("ui/widget/container/inputcontainer")
local InputDialog = require("ui/widget/inputdialog")
local Notification = require("ui/widget/notification")
local GestureRange = require("ui/gesturerange")
local UIManager = require("ui/uimanager")
local Geom = require("ui/geometry")
local Screen = require("ui/screen")
local Device = require("ui/device")
local DEBUG = require("dbg")
local _ = require("gettext")

local ReaderFrontLight = InputContainer:new{
    steps = {0,1,1,1,1,2,2,2,3,4,5,6,7,8,9,10},
}

function ReaderFrontLight:init()
    if Device:isTouchDevice() then
        self.ges_events = {
            Adjust = {
                GestureRange:new{
                    ges = "two_finger_pan",
                    rate = Device:getModel() ~= 'Kobo_phoenix' and 3.0 or nil,
                }
            },
            PanRelease= {
                GestureRange:new{
                    ges = "two_finger_pan_release",
                }
            },
            Swipe = {
                GestureRange:new{
                    ges = "two_finger_swipe",
                }
            },
        }
		DEBUG("Device:getModel() ~= 'Kobo_phoenix' and 3.0 or nil =", Device:getModel() ~= 'Kobo_phoenix' and 3.0 or nil)
        self.ui.menu:registerToMainMenu(self)
    end
	
end

function ReaderFrontLight:onAdjust(arg, ges)
    local powerd = Device:getPowerDevice()
    if powerd.flIntensity ~= nil then
        DEBUG("frontlight intensity", powerd.flIntensity)
        local step = math.ceil(#self.steps * ges.distance / Screen:getWidth())
		DEBUG("step = ", step)
        local delta_int = self.steps[step] or self.steps[#self.steps]
		DEBUG("delta_int = ", delta_int)
        if ges.direction == "north" then
            powerd:setIntensity(powerd.flIntensity + delta_int)
        elseif ges.direction == "south" then
            powerd:setIntensity(powerd.flIntensity - delta_int)
        end
    end
    return true
end

function ReaderFrontLight:onShowIntensity()
    local powerd = Device:getPowerDevice()
    if powerd.flIntensity ~= nil then
        UIManager:show(Notification:new{
            text = _("Frontlight intensity is set to ")..powerd.flIntensity,
            timeout = 1.0,
        })
    end
    return true
end

function ReaderFrontLight:onSwipe(arg, ges)
    if ges.direction == "north" or ges.direction == "south" then
		DEBUG("onSwipe activated")
        return self:onShowIntensity()
    end
end

function ReaderFrontLight:onPanRelease(arg, ges)
	DEBUG("onPanRelease activated")
    return self:onShowIntensity()
end

function ReaderFrontLight:addToMainMenu(tab_item_table)
    -- insert fldial command to main reader menu
    table.insert(tab_item_table.main, {
        text = _("Frontlight settings"),
        callback = function()
            self:onShowFlDialog()
        end,
    })
end

function ReaderFrontLight:onShowFlDialog()
    local powerd = Device:getPowerDevice()
    self.fl_dialog = InputDialog:new{
        title = _("Frontlight Level"),
        input_hint = ("(%d - %d)"):format(powerd.fl_min, powerd.fl_max),
        buttons = {
            {
                {<commit_msg>remove unnecessary DEBUG<commit_after>local InputContainer = require("ui/widget/container/inputcontainer")
local InputDialog = require("ui/widget/inputdialog")
local Notification = require("ui/widget/notification")
local GestureRange = require("ui/gesturerange")
local UIManager = require("ui/uimanager")
local Geom = require("ui/geometry")
local Screen = require("ui/screen")
local Device = require("ui/device")
local DEBUG = require("dbg")
local _ = require("gettext")

local ReaderFrontLight = InputContainer:new{
    steps = {0,1,1,1,1,2,2,2,3,4,5,6,7,8,9,10},
}

function ReaderFrontLight:init()
    if Device:isTouchDevice() then
        self.ges_events = {
            Adjust = {
                GestureRange:new{
                    ges = "two_finger_pan",
                    rate = Device:getModel() ~= 'Kobo_phoenix' and 3.0 or nil,
                }
            },
            PanRelease= {
                GestureRange:new{
                    ges = "two_finger_pan_release",
                }
            },
            Swipe = {
                GestureRange:new{
                    ges = "two_finger_swipe",
                }
            },
        }
        self.ui.menu:registerToMainMenu(self)
    end

end

function ReaderFrontLight:onAdjust(arg, ges)
    local powerd = Device:getPowerDevice()
    if powerd.flIntensity ~= nil then
        DEBUG("frontlight intensity", powerd.flIntensity)
        local step = math.ceil(#self.steps * ges.distance / Screen:getWidth())
        DEBUG("step = ", step)
        local delta_int = self.steps[step] or self.steps[#self.steps]
        DEBUG("delta_int = ", delta_int)
        if ges.direction == "north" then
            powerd:setIntensity(powerd.flIntensity + delta_int)
        elseif ges.direction == "south" then
            powerd:setIntensity(powerd.flIntensity - delta_int)
        end
    end
    return true
end

function ReaderFrontLight:onShowIntensity()
    local powerd = Device:getPowerDevice()
    if powerd.flIntensity ~= nil then
        UIManager:show(Notification:new{
            text = _("Frontlight intensity is set to ")..powerd.flIntensity,
            timeout = 1.0,
        })
    end
    return true
end

function ReaderFrontLight:onSwipe(arg, ges)
    if ges.direction == "north" or ges.direction == "south" then
        DEBUG("onSwipe activated")
        return self:onShowIntensity()
    end
end

function ReaderFrontLight:onPanRelease(arg, ges)
    DEBUG("onPanRelease activated")
    return self:onShowIntensity()
end

function ReaderFrontLight:addToMainMenu(tab_item_table)
    -- insert fldial command to main reader menu
    table.insert(tab_item_table.main, {
        text = _("Frontlight settings"),
        callback = function()
            self:onShowFlDialog()
        end,
    })
end

function ReaderFrontLight:onShowFlDialog()
    local powerd = Device:getPowerDevice()
    self.fl_dialog = InputDialog:new{
        title = _("Frontlight Level"),
        input_hint = ("(%d - %d)"):format(powerd.fl_min, powerd.fl_max),
        buttons = {
            {
                {
{'fraction_non_alphanumeric': 0.11216151257811248, 'fraction_numerical': 0.007370613683704535, 'mean_word_length': 2.4988789237668163, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5005435', 'n_tokens_mistral': 1901, 'n_tokens_neox': 1849, 'n_words': 386}