nfc_playlist_scene_name_new_playlist.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "../nfc_playlist.h"
  2. void nfc_playlist_name_new_playlist_menu_callback(void* context) {
  3. NfcPlaylist* nfc_playlist = context;
  4. FuriString* file_name = furi_string_alloc_printf("/ext/apps_data/nfc_playlist/%s.txt", nfc_playlist->text_input_output);
  5. char const* file_name_cstr = furi_string_get_cstr(file_name);
  6. Storage* storage = furi_record_open(RECORD_STORAGE);
  7. File* file = storage_file_alloc(storage);
  8. if (!storage_file_exists(storage, file_name_cstr)) {
  9. if (storage_file_open(file, file_name_cstr, FSAM_READ_WRITE, FSOM_CREATE_NEW)) {
  10. storage_file_close(file);
  11. furi_string_swap(nfc_playlist->settings.playlist_path, file_name);
  12. nfc_playlist->settings.playlist_length = 0;
  13. }
  14. }
  15. storage_file_free(file);
  16. furi_record_close(RECORD_STORAGE);
  17. furi_string_free(file_name);
  18. scene_manager_previous_scene(nfc_playlist->scene_manager);
  19. }
  20. void nfc_playlist_name_new_playlist_scene_on_enter(void* context) {
  21. NfcPlaylist* nfc_playlist = context;
  22. nfc_playlist->text_input_output = malloc(PLAYLIST_NAME_LEN);
  23. text_input_set_header_text(nfc_playlist->text_input, "Enter file name");
  24. text_input_set_minimum_length(nfc_playlist->text_input, 1);
  25. text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_name_new_playlist_menu_callback, nfc_playlist, nfc_playlist->text_input_output, PLAYLIST_NAME_LEN, true);
  26. view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput);
  27. }
  28. bool nfc_playlist_name_new_playlist_scene_on_event(void* context, SceneManagerEvent event) {
  29. UNUSED(context);
  30. UNUSED(event);
  31. return false;
  32. }
  33. void nfc_playlist_name_new_playlist_scene_on_exit(void* context) {
  34. NfcPlaylist* nfc_playlist = context;
  35. free(nfc_playlist->text_input_output);
  36. text_input_reset(nfc_playlist->text_input);
  37. }