add permission checks to main widgets
This commit is contained in:
@@ -8,11 +8,19 @@
|
|||||||
|
|
||||||
local fmt = require "fmt"
|
local fmt = require "fmt"
|
||||||
|
|
||||||
|
local have_permission = false
|
||||||
local events = {}
|
local events = {}
|
||||||
|
|
||||||
function on_drawer_open()
|
function on_drawer_open()
|
||||||
events = calendar:events()
|
events = calendar:events()
|
||||||
|
|
||||||
|
if events == "permission_error" then
|
||||||
|
calendar:request_permission()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
have_permission = true
|
||||||
|
|
||||||
lines = map(events, function(it)
|
lines = map(events, function(it)
|
||||||
local date = fmt.colored(os.date("%d.%m", it.begin), it.color)
|
local date = fmt.colored(os.date("%d.%m", it.begin), it.color)
|
||||||
return date..fmt.space(4)..it.title
|
return date..fmt.space(4)..it.title
|
||||||
@@ -22,10 +30,14 @@ function on_drawer_open()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function on_click(idx)
|
function on_click(idx)
|
||||||
|
if not have_permission then return end
|
||||||
|
|
||||||
calendar:show_event_dialog(events[idx].id)
|
calendar:show_event_dialog(events[idx].id)
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_long_click(idx)
|
function on_long_click(idx)
|
||||||
|
if not have_permission then return end
|
||||||
|
|
||||||
calendar:open_event(events[idx].id)
|
calendar:open_event(events[idx].id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -15,12 +15,20 @@ local month = os.date("%m"):gsub("^0","")
|
|||||||
local day = os.date("%d"):gsub("^0","")
|
local day = os.date("%d"):gsub("^0","")
|
||||||
|
|
||||||
function on_resume()
|
function on_resume()
|
||||||
|
if widget_type == "text" then
|
||||||
|
return
|
||||||
|
end
|
||||||
--ui:set_folding_flag(true)
|
--ui:set_folding_flag(true)
|
||||||
ui:show_table(table_to_tables(tab,8),0, true, line)
|
ui:show_table(table_to_tables(tab,8),0, true, line)
|
||||||
widget_type = "table"
|
widget_type = "table"
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_alarm()
|
function on_alarm()
|
||||||
|
if calendar:events(0,0) == "permission_error" then
|
||||||
|
widget_type = "text"
|
||||||
|
ui:show_text("Click to grant permission")
|
||||||
|
return
|
||||||
|
end
|
||||||
if next(settings:get()) == nil then
|
if next(settings:get()) == nil then
|
||||||
settings:set(get_all_cals()[2])
|
settings:set(get_all_cals()[2])
|
||||||
end
|
end
|
||||||
@@ -72,9 +80,15 @@ function on_click(i)
|
|||||||
widget_type = "table"
|
widget_type = "table"
|
||||||
ui:show_table(table_to_tables(tab,8),0, true, line)
|
ui:show_table(table_to_tables(tab,8),0, true, line)
|
||||||
end
|
end
|
||||||
|
elseif widget_type == "text" then
|
||||||
|
calendar:request_permission()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function on_permission_granted()
|
||||||
|
on_alarm()
|
||||||
|
end
|
||||||
|
|
||||||
function on_dialog_action(data)
|
function on_dialog_action(data)
|
||||||
if data == -1 then
|
if data == -1 then
|
||||||
events = {}
|
events = {}
|
||||||
|
|||||||
@@ -6,7 +6,18 @@
|
|||||||
-- author = "Evgeny Zobnin"
|
-- author = "Evgeny Zobnin"
|
||||||
-- version = "1.0"
|
-- version = "1.0"
|
||||||
|
|
||||||
|
local have_permission = false
|
||||||
|
|
||||||
function on_drawer_open()
|
function on_drawer_open()
|
||||||
|
local raw_contacts = phone:contacts()
|
||||||
|
|
||||||
|
if raw_contacts == "permission_error" then
|
||||||
|
phone:request_permission()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
have_permission = true
|
||||||
|
|
||||||
contacts = distinct_by_name(
|
contacts = distinct_by_name(
|
||||||
sort_by_name(phone:contacts())
|
sort_by_name(phone:contacts())
|
||||||
)
|
)
|
||||||
@@ -22,6 +33,8 @@ function on_icons_ready(icons)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function on_click(idx)
|
function on_click(idx)
|
||||||
|
if not have_permission then return end
|
||||||
|
|
||||||
phone:show_contact_dialog(contacts[idx].lookup_key)
|
phone:show_contact_dialog(contacts[idx].lookup_key)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user