nfc_maker_scene_save_result.c 1.7 KB

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