nfc_playlist.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "nfc_playlist.h"
  2. #include "nfc_playlist_i.h"
  3. static void (*const nfc_playlist_scene_on_enter_handlers[])(void*) = {
  4. nfc_playlist_main_menu_scene_on_enter,
  5. nfc_playlist_emulation_scene_on_enter,
  6. };
  7. static bool (*const nfc_playlist_scene_on_event_handlers[])(void*, SceneManagerEvent) = {
  8. nfc_playlist_main_menu_scene_on_event,
  9. nfc_playlist_emulation_scene_on_event,
  10. };
  11. static void (*const nfc_playlist_scene_on_exit_handlers[])(void*) = {
  12. nfc_playlist_main_menu_scene_on_exit,
  13. nfc_playlist_emulation_scene_on_exit,
  14. };
  15. static const SceneManagerHandlers nfc_playlist_scene_manager_handlers = {
  16. .on_enter_handlers = nfc_playlist_scene_on_enter_handlers,
  17. .on_event_handlers = nfc_playlist_scene_on_event_handlers,
  18. .on_exit_handlers = nfc_playlist_scene_on_exit_handlers,
  19. .scene_num = NfcPlaylistScene_count,
  20. };
  21. static bool nfc_playlist_custom_callback(void* context, uint32_t custom_event) {
  22. furi_assert(context);
  23. NfcPlaylist* app = context;
  24. return scene_manager_handle_custom_event(app->scene_manager, custom_event);
  25. }
  26. static bool nfc_playlist_back_event_callback(void* context) {
  27. furi_assert(context);
  28. NfcPlaylist* app = context;
  29. return scene_manager_handle_back_event(app->scene_manager);
  30. }
  31. static NfcPlaylist* nfc_playlist_alloc() {
  32. NfcPlaylist* app = malloc(sizeof(NfcPlaylist));
  33. furi_assert(app);
  34. app->scene_manager = scene_manager_alloc(&nfc_playlist_scene_manager_handlers, app);
  35. app->view_dispatcher = view_dispatcher_alloc();
  36. view_dispatcher_enable_queue(app->view_dispatcher);
  37. app->variable_item_list = variable_item_list_alloc();
  38. app->popup = popup_alloc();
  39. app->emulate_timeout = default_emulate_timeout;
  40. app->emulate_delay = default_emulate_delay;
  41. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  42. view_dispatcher_set_custom_event_callback( app->view_dispatcher, nfc_playlist_custom_callback);
  43. view_dispatcher_set_navigation_event_callback(app->view_dispatcher, nfc_playlist_back_event_callback);
  44. view_dispatcher_add_view(app->view_dispatcher, NfcPlaylistView_Menu, variable_item_list_get_view(app->variable_item_list));
  45. view_dispatcher_add_view(app->view_dispatcher, NfcPlaylistView_Popup, popup_get_view(app->popup));
  46. return app;
  47. }
  48. static void nfc_playlist_free(NfcPlaylist* app) {
  49. furi_assert(app);
  50. scene_manager_free(app->scene_manager);
  51. view_dispatcher_remove_view(app->view_dispatcher, NfcPlaylistView_Menu);
  52. view_dispatcher_remove_view(app->view_dispatcher, NfcPlaylistView_Popup);
  53. view_dispatcher_free(app->view_dispatcher);
  54. variable_item_list_free(app->variable_item_list);
  55. popup_free(app->popup);
  56. free(app);
  57. }
  58. int32_t nfc_playlist_main(void* p) {
  59. // Mark argument as unused
  60. UNUSED(p);
  61. NfcPlaylist* app = nfc_playlist_alloc();
  62. Gui* gui = furi_record_open(RECORD_GUI);
  63. view_dispatcher_attach_to_gui(app->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
  64. scene_manager_next_scene(app->scene_manager, NfcPlaylistScene_MainMenu);
  65. view_dispatcher_run(app->view_dispatcher);
  66. // free all memory
  67. furi_record_close(RECORD_GUI);
  68. nfc_playlist_free(app);
  69. return 0;
  70. }