nfc_playlist_scene_view_playlist_content.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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(nfc_playlist->settings.playlist_length == 0) {
  7. widget_add_text_box_element(
  8. nfc_playlist->widget,
  9. 4,
  10. 4,
  11. 128,
  12. 64,
  13. AlignCenter,
  14. AlignCenter,
  15. "\ePlaylist is empty\n\n\n\nPress back\e",
  16. false);
  17. } else if(file_stream_open(
  18. stream,
  19. furi_string_get_cstr(nfc_playlist->settings.playlist_path),
  20. FSAM_READ,
  21. FSOM_OPEN_EXISTING)) {
  22. FuriString* line = furi_string_alloc();
  23. FuriString* tmp_str = furi_string_alloc();
  24. while(stream_read_line(stream, line)) {
  25. furi_string_cat(tmp_str, furi_string_get_cstr(line));
  26. }
  27. furi_string_free(line);
  28. file_stream_close(stream);
  29. widget_add_text_scroll_element(
  30. nfc_playlist->widget, 4, 4, 124, 60, furi_string_get_cstr(tmp_str));
  31. widget_add_frame_element(nfc_playlist->widget, 0, 0, 128, 64, 0);
  32. furi_string_free(tmp_str);
  33. } else {
  34. widget_add_text_box_element(
  35. nfc_playlist->widget,
  36. 0,
  37. 0,
  38. 128,
  39. 64,
  40. AlignCenter,
  41. AlignCenter,
  42. "\eFailed to open playlist\n\n\n\nPress back\e",
  43. false);
  44. }
  45. stream_free(stream);
  46. furi_record_close(RECORD_STORAGE);
  47. view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Widget);
  48. }
  49. bool nfc_playlist_view_playlist_content_scene_on_event(void* context, SceneManagerEvent event) {
  50. UNUSED(context);
  51. UNUSED(event);
  52. return false;
  53. }
  54. void nfc_playlist_view_playlist_content_scene_on_exit(void* context) {
  55. NfcPlaylist* nfc_playlist = context;
  56. widget_reset(nfc_playlist->widget);
  57. }