nfc_playlist_scene_view_playlist_content.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. furi_string_free(line);
  17. file_stream_close(stream);
  18. widget_add_text_scroll_element(
  19. nfc_playlist->widget, 4, 4, 124, 60, furi_string_get_cstr(tmp_str));
  20. widget_add_frame_element(nfc_playlist->widget, 0, 0, 128, 64, 0);
  21. furi_string_free(tmp_str);
  22. } else {
  23. widget_add_text_box_element(
  24. nfc_playlist->widget,
  25. 0,
  26. 0,
  27. 128,
  28. 64,
  29. AlignCenter,
  30. AlignCenter,
  31. "\eFailed to open playlist\n\nPress back\e",
  32. false);
  33. }
  34. stream_free(stream);
  35. furi_record_close(RECORD_STORAGE);
  36. view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Widget);
  37. }
  38. bool nfc_playlist_view_playlist_content_scene_on_event(void* context, SceneManagerEvent event) {
  39. UNUSED(context);
  40. UNUSED(event);
  41. return false;
  42. }
  43. void nfc_playlist_view_playlist_content_scene_on_exit(void* context) {
  44. NfcPlaylist* nfc_playlist = context;
  45. widget_reset(nfc_playlist->widget);
  46. }