metroflip_scene_delete.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_delete_popup_callback(void* context) {
  8. Metroflip* app = context;
  9. view_dispatcher_send_custom_event(app->view_dispatcher, PopupEventExit);
  10. }
  11. void metroflip_scene_delete_on_enter(void* context) {
  12. Metroflip* app = context;
  13. Popup* popup = app->popup;
  14. Storage* storage = furi_record_open(RECORD_STORAGE);
  15. FURI_LOG_I("PATH", "PATH: %s", app->delete_file_path);
  16. bool success = storage_simply_remove(storage, app->delete_file_path);
  17. furi_record_close(RECORD_STORAGE);
  18. if(success) {
  19. popup_set_icon(popup, 0, 2, &I_DolphinMafia_119x62);
  20. popup_set_header(popup, "Deleted", 80, 19, AlignLeft, AlignBottom);
  21. popup_enable_timeout(popup);
  22. } else {
  23. popup_set_icon(popup, 69, 15, &I_WarningDolphinFlip_45x42);
  24. popup_set_header(popup, "Error!", 13, 22, AlignLeft, AlignBottom);
  25. popup_disable_timeout(popup);
  26. }
  27. popup_set_timeout(popup, 1500);
  28. popup_set_context(popup, app);
  29. popup_set_callback(popup, metroflip_scene_delete_popup_callback);
  30. view_dispatcher_switch_to_view(app->view_dispatcher, MetroflipViewPopup);
  31. }
  32. bool metroflip_scene_delete_on_event(void* context, SceneManagerEvent event) {
  33. Metroflip* app = context;
  34. bool consumed = false;
  35. if(event.type == SceneManagerEventTypeCustom) {
  36. consumed = true;
  37. switch(event.event) {
  38. case PopupEventExit:
  39. scene_manager_search_and_switch_to_previous_scene(
  40. app->scene_manager, MetroflipSceneStart);
  41. break;
  42. default:
  43. break;
  44. }
  45. }
  46. return consumed;
  47. }
  48. void metroflip_scene_delete_on_exit(void* context) {
  49. Metroflip* app = context;
  50. app->delete_file_path[0] = '\0';
  51. popup_reset(app->popup);
  52. }