metroflip_scene_save_result.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "../metroflip_i.h"
  2. #include "../api/metroflip/metroflip_api.h"
  3. #include <stdio.h>
  4. enum PopupEvent {
  5. PopupEventExit,
  6. };
  7. static void metroflip_scene_save_result_popup_callback(void* context) {
  8. Metroflip* app = context;
  9. view_dispatcher_send_custom_event(app->view_dispatcher, PopupEventExit);
  10. }
  11. void metroflip_scene_save_result_on_enter(void* context) {
  12. Metroflip* app = context;
  13. Popup* popup = app->popup;
  14. char path[280];
  15. snprintf(path, sizeof(path), "/ext/apps_data/metroflip/%s.nfc", app->save_buf);
  16. FURI_LOG_I("path", "path: %s", path);
  17. bool success = nfc_device_save(app->nfc_device, path);
  18. Storage* storage = furi_record_open(RECORD_STORAGE);
  19. FlipperFormat* ff = flipper_format_file_alloc(storage);
  20. flipper_format_write_empty_line(ff);
  21. flipper_format_file_open_existing(ff, path);
  22. flipper_format_insert_or_update_string_cstr(ff, "Card Type", app->card_type);
  23. flipper_format_file_close(ff);
  24. flipper_format_free(ff);
  25. furi_record_close(RECORD_STORAGE);
  26. if(success) {
  27. popup_set_icon(popup, 36, 5, &I_DolphinDone_80x58);
  28. popup_set_header(popup, "Saved!", 13, 22, AlignLeft, AlignBottom);
  29. popup_enable_timeout(popup);
  30. } else {
  31. popup_set_icon(popup, 69, 15, &I_WarningDolphinFlip_45x42);
  32. popup_set_header(popup, "Error!", 13, 22, AlignLeft, AlignBottom);
  33. popup_disable_timeout(popup);
  34. }
  35. popup_set_timeout(popup, 1500);
  36. popup_set_context(popup, app);
  37. popup_set_callback(popup, metroflip_scene_save_result_popup_callback);
  38. view_dispatcher_switch_to_view(app->view_dispatcher, MetroflipViewPopup);
  39. }
  40. bool metroflip_scene_save_result_on_event(void* context, SceneManagerEvent event) {
  41. Metroflip* app = context;
  42. bool consumed = false;
  43. if(event.type == SceneManagerEventTypeCustom) {
  44. consumed = true;
  45. switch(event.event) {
  46. case PopupEventExit:
  47. scene_manager_search_and_switch_to_previous_scene(
  48. app->scene_manager, MetroflipSceneStart);
  49. break;
  50. default:
  51. break;
  52. }
  53. }
  54. return consumed;
  55. }
  56. void metroflip_scene_save_result_on_exit(void* context) {
  57. Metroflip* app = context;
  58. popup_reset(app->popup);
  59. }