nfc_playlist_scene_confirm_delete.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "../nfc_playlist.h"
  2. void nfc_playlist_confirm_delete_menu_callback(GuiButtonType result, InputType type, void* context) {
  3. NfcPlaylist* nfc_playlist = context;
  4. if(type == InputTypeShort) {
  5. view_dispatcher_send_custom_event(nfc_playlist->view_dispatcher, result);
  6. }
  7. }
  8. void nfc_playlist_confirm_delete_scene_on_enter(void* context) {
  9. NfcPlaylist* nfc_playlist = context;
  10. FuriString* temp_str = furi_string_alloc();
  11. char* file_path = (char*)furi_string_get_cstr(nfc_playlist->settings.playlist_path);
  12. furi_string_printf(temp_str, "\e#Delete %s?\e#", strchr(file_path, '/') != NULL ? &strrchr(file_path, '/')[1] : file_path);
  13. furi_string_replace(temp_str, ".txt", "");
  14. widget_add_text_box_element(nfc_playlist->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, furi_string_get_cstr(temp_str), false);
  15. widget_add_button_element(nfc_playlist->widget, GuiButtonTypeLeft, "Cancel", nfc_playlist_confirm_delete_menu_callback, nfc_playlist);
  16. widget_add_button_element(nfc_playlist->widget, GuiButtonTypeRight, "Delete", nfc_playlist_confirm_delete_menu_callback, nfc_playlist);
  17. furi_string_free(temp_str);
  18. view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Widget);
  19. }
  20. bool nfc_playlist_confirm_delete_scene_on_event(void* context, SceneManagerEvent event) {
  21. NfcPlaylist* nfc_playlist = context;
  22. bool consumed = false;
  23. if(event.type == SceneManagerEventTypeCustom) {
  24. switch(event.event) {
  25. case GuiButtonTypeRight:
  26. Storage* storage = furi_record_open(RECORD_STORAGE);
  27. storage_simply_remove(storage, furi_string_get_cstr(nfc_playlist->settings.playlist_path));
  28. nfc_playlist->settings.playlist_selected = false;
  29. furi_string_reset(nfc_playlist->settings.playlist_path);
  30. furi_record_close(RECORD_STORAGE);
  31. consumed = true;
  32. scene_manager_search_and_switch_to_previous_scene(nfc_playlist->scene_manager, NfcPlaylistScene_MainMenu);
  33. break;
  34. default:
  35. scene_manager_previous_scene(nfc_playlist->scene_manager);
  36. break;
  37. }
  38. }
  39. return consumed;
  40. }
  41. void nfc_playlist_confirm_delete_scene_on_exit(void* context) {
  42. NfcPlaylist* nfc_playlist = context;
  43. widget_reset(nfc_playlist->widget);
  44. }