esubghz_chat_key_menu.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "../esubghz_chat_i.h"
  2. typedef enum {
  3. ESubGhzChatKeyMenuItems_NoEncryption,
  4. ESubGhzChatKeyMenuItems_Password,
  5. } ESubGhzChatKeyMenuItems;
  6. static void key_menu_cb(void* context, uint32_t index)
  7. {
  8. furi_assert(context);
  9. ESubGhzChatState* state = context;
  10. switch(index) {
  11. case ESubGhzChatKeyMenuItems_NoEncryption:
  12. state->encrypted = false;
  13. enter_chat(state);
  14. scene_manager_handle_custom_event(state->scene_manager,
  15. ESubGhzChatEvent_KeyMenuNoEncryption);
  16. break;
  17. case ESubGhzChatKeyMenuItems_Password:
  18. scene_manager_handle_custom_event(state->scene_manager,
  19. ESubGhzChatEvent_KeyMenuPassword);
  20. break;
  21. default:
  22. break;
  23. }
  24. }
  25. /* Prepares the key menu scene. */
  26. void scene_on_enter_key_menu(void* context)
  27. {
  28. FURI_LOG_T(APPLICATION_NAME, "scene_on_enter_key_menu");
  29. furi_assert(context);
  30. ESubGhzChatState* state = context;
  31. menu_reset(state->menu);
  32. menu_add_item(
  33. state->menu,
  34. "No encryption",
  35. NULL,
  36. ESubGhzChatKeyMenuItems_NoEncryption,
  37. key_menu_cb,
  38. state
  39. );
  40. menu_add_item(
  41. state->menu,
  42. "Password",
  43. NULL,
  44. ESubGhzChatKeyMenuItems_Password,
  45. key_menu_cb,
  46. state
  47. );
  48. view_dispatcher_switch_to_view(state->view_dispatcher, ESubGhzChatView_Menu);
  49. }
  50. /* Handles scene manager events for the key menu scene. */
  51. bool scene_on_event_key_menu(void* context, SceneManagerEvent event)
  52. {
  53. FURI_LOG_T(APPLICATION_NAME, "scene_on_event_key_menu");
  54. furi_assert(context);
  55. ESubGhzChatState* state = context;
  56. bool consumed = false;
  57. switch(event.type) {
  58. case SceneManagerEventTypeCustom:
  59. switch(event.event) {
  60. /* switch to message input scene */
  61. case ESubGhzChatEvent_KeyMenuNoEncryption:
  62. scene_manager_next_scene(state->scene_manager,
  63. ESubGhzChatScene_ChatInput);
  64. consumed = true;
  65. break;
  66. /* switch to password input scene */
  67. case ESubGhzChatEvent_KeyMenuPassword:
  68. scene_manager_next_scene(state->scene_manager,
  69. ESubGhzChatScene_PassInput);
  70. consumed = true;
  71. break;
  72. }
  73. break;
  74. case SceneManagerEventTypeBack:
  75. /* stop the application if the user presses back here */
  76. view_dispatcher_stop(state->view_dispatcher);
  77. consumed = true;
  78. break;
  79. default:
  80. consumed = false;
  81. break;
  82. }
  83. return consumed;
  84. }
  85. /* Cleans up the key menu scene. */
  86. void scene_on_exit_key_menu(void* context)
  87. {
  88. FURI_LOG_T(APPLICATION_NAME, "scene_on_exit_key_menu");
  89. furi_assert(context);
  90. ESubGhzChatState* state = context;
  91. menu_reset(state->menu);
  92. }