nfc_playlist_scene_view_playlist_content.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "../nfc_playlist.h"
  2. #define MAX_PLAYLIST_SIZE 1000
  3. void nfc_playlist_view_playlist_content_scene_on_enter(void* context) {
  4. NfcPlaylist* nfc_playlist = context;
  5. Storage* storage = furi_record_open(RECORD_STORAGE);
  6. File* file = storage_file_alloc(storage);
  7. if (storage_file_open(file, furi_string_get_cstr(nfc_playlist->settings.file_path), FSAM_READ, FSOM_OPEN_EXISTING)) {
  8. uint8_t buffer[MAX_PLAYLIST_SIZE];
  9. uint16_t read_count = storage_file_read(file, buffer, MAX_PLAYLIST_SIZE);
  10. FuriString* playlist_content = furi_string_alloc();
  11. for(uint16_t i = 0; i < read_count; i++) {
  12. furi_string_push_back(playlist_content, buffer[i]);
  13. }
  14. widget_add_text_scroll_element(nfc_playlist->widget, 4, 4, 124, 60, furi_string_get_cstr(playlist_content));
  15. widget_add_frame_element(nfc_playlist->widget, 0, 0, 128, 64, 0);
  16. furi_string_free(playlist_content);
  17. storage_file_close(file);
  18. } else {
  19. widget_add_text_box_element(nfc_playlist->widget, 0, 0, 128, 64, AlignCenter, AlignCenter, "\eFailed to open playlist\n\nPress back\e", false);
  20. }
  21. storage_file_free(file);
  22. furi_record_close(RECORD_STORAGE);
  23. view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Widget);
  24. }
  25. bool nfc_playlist_view_playlist_content_scene_on_event(void* context, SceneManagerEvent event) {
  26. UNUSED(context);
  27. UNUSED(event);
  28. return false;
  29. }
  30. void nfc_playlist_view_playlist_content_scene_on_exit(void* context) {
  31. NfcPlaylist* nfc_playlist = context;
  32. widget_reset(nfc_playlist->widget);
  33. }