confirm_delete.c 2.3 KB

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