diff --git a/README.md b/README.md index f170f9e..ca5d35c 100644 --- a/README.md +++ b/README.md @@ -343,14 +343,24 @@ end ## Application management -* `apps:list([sort_by], [no_hidden])` - returns the package table of all installed applications (if it is cloned app or Android for Work app package name will also contain user id, like that: `com.example.app:123`), `sort_by` - sort option (see below), `no_hidden` - true if no hidden applications are needed; -* `apps:name(package)` - returns application name; -* `apps:color(package)` - returns the color of the application in #XXXXXXXX format; +* `apps:apps([sort_by])` - returns the table of tables of all installed applications +, `sort_by` - sort option (see below); * `apps:launch(package)` - launches the application; * `apps:show_edit_dialog(package)` - shows edit dialog of the application; -* `apps:categories()` - returns a table of category tables; -* `apps:by_category(category_id)` - returns a table of application packages belonging to the specified category; -* `apps:request_icons(packages)` - requests icons for the specified list of applications, the result will be returned in the `on_icons_ready()` callback. +* `apps:categories()` - returns a table of category tables. + +The format of the apps table: + +``` +`pkg` - name of the app package (if it is cloned app or Android for Work app package name will also contain user id, like that: `com.example.app:123`); +`name` - name of the application; +`color` - application color; +`hidden` - true if the application is hidden; +`suspended` - true if the application is suspended; +`category_id` - category ID; +`badge` - number on the badge; +`icon` - icon of the application in the form of a link (can be used in the side menu scripts). +``` The format of the category table: @@ -427,8 +437,7 @@ The function `calendar:request_permission()` calls `on_permission_granted()` cal * `phone:make_call(number)` - dial the number in the dialer; * `phone:send_sms(number, [text])` - open SMS application and enter the number, optionally enter text; * `phone:show_contact_dialog(id|lookup_key)` - open contact dialog; -* `phone:open_contact(id)` - open contact in the contacts app; -* `phone:request_icons(cantact_ids)` - requests icons of contacts with specified IDs, the result will be in the `on_icons_ready` callback. +* `phone:open_contact(id)` - open contact in the contacts app. Contacts table format: @@ -436,7 +445,8 @@ Contacts table format: `id` - contact id; `lookup_key` - unique contact identifier; `name` - contact name; -`number` - contact number. +`number` - contact number; +`icon` - contact icon in the form of a link (can be used in the side menu scripts). ``` The function `phone:request_permission()` calls `on_permission_granted()` callback if the user agrees to grant permission. diff --git a/main/contacts-menu.lua b/main/contacts-menu.lua index e8cf773..f0b96d3 100644 --- a/main/contacts-menu.lua +++ b/main/contacts-menu.lua @@ -28,16 +28,15 @@ function on_drawer_open() names = map(contacts, function(it) return it.name end) keys = map(contacts, function(it) return it.lookup_key end) - icons = map(contacts, function(it) return it.name:sub(1,1) end) + icons = map(contacts, function(it) + if it.icon ~= nil then + return it.icon + else + return it.name:sub(1,1) -- Backward compatibility + end + end) drawer:show_list(names, icons, nil, true) - - -- Uncomment this if you want to use real icons (slow) - --phone:request_icons(keys) -end - -function on_icons_ready(icons) - drawer:show_list(names, icons, nil, true) end function on_click(idx) diff --git a/samples/apps-menu.lua b/samples/apps-menu.lua index 536bdf0..7d26e60 100644 --- a/samples/apps-menu.lua +++ b/samples/apps-menu.lua @@ -3,8 +3,7 @@ -- testing = "true" function on_drawer_open() - apps_tab = apps:list() - debug:toast("called") + apps_tab = apps:apps() -- Do not update if the list of the apps is not changed if #apps_tab ~= #drawer:items() then @@ -13,11 +12,9 @@ function on_drawer_open() end function update() - names_tab = map(function(it) return apps:name(it) end, apps_tab) - apps:request_icons(apps_tab) -end + names_tab = map(function(it) return it.name end, apps_tab) + icons_tab = map(function(it) return it.icon end, apps_tab) -function on_icons_ready(icons_tab) drawer:show_list(names_tab, icons_tab, nil, true) end