desktop_settings_scene_start.c 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include <applications.h>
  2. #include <lib/toolbox/value_index.h>
  3. #include "../desktop_settings_app.h"
  4. #include "desktop_settings_scene.h"
  5. #define SCENE_EVENT_SELECT_FAVORITE 0
  6. #define SCENE_EVENT_SELECT_PIN_SETUP 1
  7. #define SCENE_EVENT_SELECT_AUTO_LOCK_DELAY 2
  8. #define AUTO_LOCK_DELAY_COUNT 6
  9. const char* const auto_lock_delay_text[AUTO_LOCK_DELAY_COUNT] = {
  10. "OFF",
  11. "30s",
  12. "60s",
  13. "2min",
  14. "5min",
  15. "10min",
  16. };
  17. const uint32_t auto_lock_delay_value[AUTO_LOCK_DELAY_COUNT] =
  18. {0, 30000, 60000, 120000, 300000, 600000};
  19. static void desktop_settings_scene_start_var_list_enter_callback(void* context, uint32_t index) {
  20. DesktopSettingsApp* app = context;
  21. view_dispatcher_send_custom_event(app->view_dispatcher, index);
  22. }
  23. static void desktop_settings_scene_start_auto_lock_delay_changed(VariableItem* item) {
  24. DesktopSettingsApp* app = variable_item_get_context(item);
  25. uint8_t index = variable_item_get_current_value_index(item);
  26. variable_item_set_current_value_text(item, auto_lock_delay_text[index]);
  27. app->settings.auto_lock_delay_ms = auto_lock_delay_value[index];
  28. }
  29. void desktop_settings_scene_start_on_enter(void* context) {
  30. DesktopSettingsApp* app = context;
  31. VariableItemList* variable_item_list = app->variable_item_list;
  32. VariableItem* item;
  33. uint8_t value_index;
  34. variable_item_list_add(variable_item_list, "Favorite App", 1, NULL, NULL);
  35. variable_item_list_add(variable_item_list, "PIN Setup", 1, NULL, NULL);
  36. item = variable_item_list_add(
  37. variable_item_list,
  38. "Auto Lock Time",
  39. AUTO_LOCK_DELAY_COUNT,
  40. desktop_settings_scene_start_auto_lock_delay_changed,
  41. app);
  42. variable_item_list_set_enter_callback(
  43. variable_item_list, desktop_settings_scene_start_var_list_enter_callback, app);
  44. value_index = value_index_uint32(
  45. app->settings.auto_lock_delay_ms, auto_lock_delay_value, AUTO_LOCK_DELAY_COUNT);
  46. variable_item_set_current_value_index(item, value_index);
  47. variable_item_set_current_value_text(item, auto_lock_delay_text[value_index]);
  48. view_dispatcher_switch_to_view(app->view_dispatcher, DesktopSettingsAppViewVarItemList);
  49. }
  50. bool desktop_settings_scene_start_on_event(void* context, SceneManagerEvent event) {
  51. DesktopSettingsApp* app = context;
  52. bool consumed = false;
  53. if(event.type == SceneManagerEventTypeCustom) {
  54. switch(event.event) {
  55. case SCENE_EVENT_SELECT_FAVORITE:
  56. scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneFavorite);
  57. consumed = true;
  58. break;
  59. case SCENE_EVENT_SELECT_PIN_SETUP:
  60. scene_manager_next_scene(app->scene_manager, DesktopSettingsAppScenePinMenu);
  61. consumed = true;
  62. break;
  63. case SCENE_EVENT_SELECT_AUTO_LOCK_DELAY:
  64. consumed = true;
  65. break;
  66. }
  67. }
  68. return consumed;
  69. }
  70. void desktop_settings_scene_start_on_exit(void* context) {
  71. DesktopSettingsApp* app = context;
  72. variable_item_list_reset(app->variable_item_list);
  73. SAVE_DESKTOP_SETTINGS(&app->settings);
  74. }