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