nfc_maker_scene_save_result.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "../nfc_maker.h"
  2. enum PopupEvent {
  3. PopupEventExit,
  4. PopupEventFailed,
  5. };
  6. static void nfc_maker_scene_save_result_popup_callback_exit(void* context) {
  7. NfcMaker* app = context;
  8. view_dispatcher_send_custom_event(app->view_dispatcher, PopupEventExit);
  9. }
  10. static void nfc_maker_scene_save_result_popup_callback_failed(void* context) {
  11. NfcMaker* app = context;
  12. view_dispatcher_send_custom_event(app->view_dispatcher, PopupEventFailed);
  13. }
  14. void nfc_maker_scene_save_result_on_enter(void* context) {
  15. NfcMaker* app = context;
  16. Popup* popup = app->popup;
  17. FuriString* path =
  18. furi_string_alloc_printf(NFC_APP_FOLDER "/%s" NFC_APP_EXTENSION, app->save_buf);
  19. bool success = nfc_device_save(app->nfc_device, furi_string_get_cstr(path));
  20. furi_string_free(path);
  21. if(success) {
  22. popup_set_icon(popup, 36, 5, &I_DolphinDone_80x58);
  23. popup_set_header(popup, "Saved!", 13, 22, AlignLeft, AlignBottom);
  24. popup_enable_timeout(popup);
  25. popup_set_callback(popup, nfc_maker_scene_save_result_popup_callback_exit);
  26. } else {
  27. popup_set_icon(popup, 69, 15, &I_WarningDolphinFlip_45x42);
  28. popup_set_header(popup, "Error!", 13, 22, AlignLeft, AlignBottom);
  29. popup_disable_timeout(popup);
  30. popup_set_callback(popup, nfc_maker_scene_save_result_popup_callback_failed);
  31. }
  32. popup_set_timeout(popup, 1500);
  33. popup_set_context(popup, app);
  34. view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewPopup);
  35. }
  36. bool nfc_maker_scene_save_result_on_event(void* context, SceneManagerEvent event) {
  37. NfcMaker* app = context;
  38. bool consumed = false;
  39. if(event.type == SceneManagerEventTypeCustom) {
  40. consumed = true;
  41. switch(event.event) {
  42. case PopupEventExit:
  43. scene_manager_search_and_switch_to_previous_scene(
  44. app->scene_manager, NfcMakerSceneStart);
  45. break;
  46. case PopupEventFailed:
  47. scene_manager_previous_scene(app->scene_manager);
  48. break;
  49. default:
  50. break;
  51. }
  52. }
  53. return consumed;
  54. }
  55. void nfc_maker_scene_save_result_on_exit(void* context) {
  56. NfcMaker* app = context;
  57. popup_reset(app->popup);
  58. }