storage-settings-scene-ejected.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "../storage-settings.h"
  2. static void
  3. storage_settings_scene_unmounted_dialog_callback(DialogExResult result, void* context) {
  4. StorageSettings* app = context;
  5. view_dispatcher_send_custom_event(app->view_dispatcher, result);
  6. }
  7. void storage_settings_scene_unmounted_on_enter(void* context) {
  8. StorageSettings* app = context;
  9. FS_Error error = storage_sd_unmount(app->fs_api);
  10. DialogEx* dialog_ex = app->dialog_ex;
  11. dialog_ex_set_left_button_text(dialog_ex, "Back");
  12. if(error == FSE_OK) {
  13. dialog_ex_set_header(dialog_ex, "SD card unmounted", 64, 10, AlignCenter, AlignCenter);
  14. dialog_ex_set_text(
  15. dialog_ex, "Now the SD card\ncan be removed.", 64, 32, AlignCenter, AlignCenter);
  16. notification_message(app->notification, &sequence_blink_green_100);
  17. } else {
  18. dialog_ex_set_header(
  19. dialog_ex, "Cannot unmount SD Card", 64, 10, AlignCenter, AlignCenter);
  20. dialog_ex_set_text(
  21. dialog_ex, storage_error_get_desc(error), 64, 32, AlignCenter, AlignCenter);
  22. notification_message(app->notification, &sequence_blink_red_100);
  23. }
  24. dialog_ex_set_context(dialog_ex, app);
  25. dialog_ex_set_result_callback(dialog_ex, storage_settings_scene_unmounted_dialog_callback);
  26. view_dispatcher_switch_to_view(app->view_dispatcher, StorageSettingsViewDialogEx);
  27. }
  28. bool storage_settings_scene_unmounted_on_event(void* context, SceneManagerEvent event) {
  29. StorageSettings* app = context;
  30. bool consumed = false;
  31. if(event.type == SceneManagerEventTypeCustom) {
  32. switch(event.event) {
  33. case DialogExResultLeft:
  34. consumed =
  35. scene_manager_search_previous_scene(app->scene_manager, StorageSettingsStart);
  36. break;
  37. }
  38. } else if(event.type == SceneManagerEventTypeNavigation) {
  39. consumed = scene_manager_search_previous_scene(app->scene_manager, StorageSettingsStart);
  40. }
  41. return consumed;
  42. }
  43. void storage_settings_scene_unmounted_on_exit(void* context) {
  44. StorageSettings* app = context;
  45. DialogEx* dialog_ex = app->dialog_ex;
  46. dialog_ex_set_header(dialog_ex, NULL, 0, 0, AlignCenter, AlignCenter);
  47. dialog_ex_set_text(dialog_ex, NULL, 0, 0, AlignCenter, AlignTop);
  48. dialog_ex_set_icon(dialog_ex, 0, 0, NULL);
  49. dialog_ex_set_left_button_text(dialog_ex, NULL);
  50. dialog_ex_set_right_button_text(dialog_ex, NULL);
  51. dialog_ex_set_result_callback(dialog_ex, NULL);
  52. dialog_ex_set_context(dialog_ex, NULL);
  53. }