nfc_maker_scene_save_result.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. popup_enable_timeout(popup);
  20. } else {
  21. popup_set_icon(popup, 69, 15, &I_WarningDolphinFlip_45x42);
  22. popup_set_header(popup, "Error!", 13, 22, AlignLeft, AlignBottom);
  23. popup_disable_timeout(popup);
  24. }
  25. popup_set_timeout(popup, 1500);
  26. popup_set_context(popup, app);
  27. popup_set_callback(popup, nfc_maker_scene_save_result_popup_callback);
  28. view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewPopup);
  29. }
  30. bool nfc_maker_scene_save_result_on_event(void* context, SceneManagerEvent event) {
  31. NfcMaker* app = context;
  32. bool consumed = false;
  33. if(event.type == SceneManagerEventTypeCustom) {
  34. consumed = true;
  35. switch(event.event) {
  36. case PopupEventExit:
  37. scene_manager_search_and_switch_to_previous_scene(
  38. app->scene_manager, NfcMakerSceneStart);
  39. break;
  40. default:
  41. break;
  42. }
  43. }
  44. return consumed;
  45. }
  46. void nfc_maker_scene_save_result_on_exit(void* context) {
  47. NfcMaker* app = context;
  48. popup_reset(app->popup);
  49. }