nfc_playlist_scene_view_playlist_content.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "../nfc_playlist.h"
  2. void nfc_playlist_view_playlist_content_scene_on_enter(void* context) {
  3. NfcPlaylist* nfc_playlist = context;
  4. Storage* storage = furi_record_open(RECORD_STORAGE);
  5. Stream* stream = file_stream_alloc(storage);
  6. if(file_stream_open(
  7. stream,
  8. furi_string_get_cstr(nfc_playlist->settings.playlist_path),
  9. FSAM_READ,
  10. FSOM_OPEN_EXISTING)) {
  11. FuriString* line = furi_string_alloc();
  12. FuriString* tmp_str = furi_string_alloc();
  13. while(stream_read_line(stream, line)) {
  14. furi_string_cat_printf(tmp_str, "%s", furi_string_get_cstr(line));
  15. }
  16. stream_clean(stream);
  17. furi_string_free(line);
  18. file_stream_close(stream);
  19. widget_add_text_scroll_element(
  20. nfc_playlist->widget, 4, 4, 124, 60, furi_string_get_cstr(tmp_str));
  21. widget_add_frame_element(nfc_playlist->widget, 0, 0, 128, 64, 0);
  22. furi_string_free(tmp_str);
  23. } else {
  24. widget_add_text_box_element(
  25. nfc_playlist->widget,
  26. 0,
  27. 0,
  28. 128,
  29. 64,
  30. AlignCenter,
  31. AlignCenter,
  32. "\eFailed to open playlist\n\nPress back\e",
  33. false);
  34. }
  35. stream_free(stream);
  36. furi_record_close(RECORD_STORAGE);
  37. view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Widget);
  38. }
  39. bool nfc_playlist_view_playlist_content_scene_on_event(void* context, SceneManagerEvent event) {
  40. UNUSED(context);
  41. UNUSED(event);
  42. return false;
  43. }
  44. void nfc_playlist_view_playlist_content_scene_on_exit(void* context) {
  45. NfcPlaylist* nfc_playlist = context;
  46. widget_reset(nfc_playlist->widget);
  47. }