Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
- Changes how add nfc and view content works
- Tweaks remove nfc to make sure things run properly and also use a different function
  • Loading branch information
acegoal07 committed May 20, 2024
1 parent b93ee28 commit 06626d8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 34 deletions.
1 change: 0 additions & 1 deletion nfc_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ static const bool default_skip_error = false;

#define PLAYLIST_LOCATION "/ext/apps_data/nfc_playlist/"
#define PLAYLIST_DIR "/ext/apps_data/nfc_playlist"
#define PLAYLIST_VIEW_MAX_SIZE 1000

typedef enum NfcPlaylistLedState {
NfcPlaylistLedState_Normal,
Expand Down
8 changes: 3 additions & 5 deletions scenes/nfc_playlist_scene_nfc_remove.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,22 @@ bool nfc_playlist_nfc_remove_scene_on_event(void* context, SceneManagerEvent eve
if (current_line != selected_line) {
furi_string_replace_all(line, "\n", "");
if (furi_string_empty(tmp_str)) {
furi_string_printf(tmp_str, "%s", furi_string_get_cstr(line));
furi_string_cat_printf(tmp_str, "%s", furi_string_get_cstr(line));
} else {
furi_string_cat(tmp_str, "\n");
furi_string_cat(tmp_str, furi_string_get_cstr(line));
furi_string_cat_printf(tmp_str, "\n%s", furi_string_get_cstr(line));
}
}
furi_string_reset(line);
}

stream_clean(stream);
furi_string_free(line);
stream_write_string(stream, tmp_str);
furi_string_free(tmp_str);
file_stream_close(stream);
stream_free(stream);
nfc_playlist->settings.playlist_length--;
selected_line = nfc_playlist->settings.playlist_length;
}
stream_free(stream);
furi_record_close(RECORD_STORAGE);

if (selected_line == 0) {
Expand Down
32 changes: 15 additions & 17 deletions scenes/nfc_playlist_scene_nfc_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,30 @@ void nfc_playlist_nfc_select_menu_callback(void* context) {
NfcPlaylist* nfc_playlist = context;

Storage* storage = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(storage);
Stream* stream = file_stream_alloc(storage);

if (storage_file_open(file, furi_string_get_cstr(nfc_playlist->settings.file_path), FSAM_READ_WRITE, FSOM_OPEN_EXISTING)) {
uint8_t buffer[PLAYLIST_VIEW_MAX_SIZE];
uint16_t read_count = storage_file_read(file, buffer, PLAYLIST_VIEW_MAX_SIZE);
FuriString* playlist_content = furi_string_alloc();

for(uint16_t i = 0; i < read_count; i++) {
furi_string_push_back(playlist_content, buffer[i]);
if (file_stream_open(stream, furi_string_get_cstr(nfc_playlist->settings.file_path), FSAM_READ_WRITE, FSOM_OPEN_EXISTING)) {
FuriString* line = furi_string_alloc();
FuriString* tmp_str = furi_string_alloc();
while(stream_read_line(stream, line)) {
furi_string_cat_printf(tmp_str, "%s", furi_string_get_cstr(line));
}

if (read_count > 0) {
furi_string_printf(playlist_content, "\n%s", furi_string_get_cstr(nfc_playlist->file_browser_output));
if (!furi_string_empty(tmp_str)) {
furi_string_cat_printf(tmp_str, "\n%s", furi_string_get_cstr(nfc_playlist->file_browser_output));
} else {
furi_string_printf(playlist_content, "%s", furi_string_get_cstr(nfc_playlist->file_browser_output));
furi_string_printf(tmp_str, "%s", furi_string_get_cstr(nfc_playlist->file_browser_output));
}

storage_file_write(file, furi_string_get_cstr(playlist_content), sizeof(char) * furi_string_utf8_length(playlist_content));

stream_clean(stream);
furi_string_free(line);
stream_write_string(stream, tmp_str);
file_stream_close(stream);
furi_string_free(tmp_str);
nfc_playlist->settings.playlist_length++;

furi_string_free(playlist_content);
storage_file_close(file);
}

storage_file_free(file);
stream_free(stream);
furi_record_close(RECORD_STORAGE);
furi_string_reset(nfc_playlist->file_browser_output);

Expand Down
24 changes: 13 additions & 11 deletions scenes/nfc_playlist_scene_view_playlist_content.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@ void nfc_playlist_view_playlist_content_scene_on_enter(void* context) {
NfcPlaylist* nfc_playlist = context;

Storage* storage = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(storage);
Stream* stream = file_stream_alloc(storage);

if (storage_file_open(file, furi_string_get_cstr(nfc_playlist->settings.file_path), FSAM_READ, FSOM_OPEN_EXISTING)) {
uint8_t buffer[PLAYLIST_VIEW_MAX_SIZE];
uint16_t read_count = storage_file_read(file, buffer, PLAYLIST_VIEW_MAX_SIZE);
FuriString* playlist_content = furi_string_alloc();
if (file_stream_open(stream, furi_string_get_cstr(nfc_playlist->settings.file_path), FSAM_READ, FSOM_OPEN_EXISTING)) {
FuriString* line = furi_string_alloc();
FuriString* tmp_str = furi_string_alloc();

for(uint16_t i = 0; i < read_count; i++) {
furi_string_push_back(playlist_content, buffer[i]);
while(stream_read_line(stream, line)) {
furi_string_cat_printf(tmp_str, "%s", furi_string_get_cstr(line));
}

widget_add_text_scroll_element(nfc_playlist->widget, 4, 4, 124, 60, furi_string_get_cstr(playlist_content));
stream_clean(stream);
furi_string_free(line);
file_stream_close(stream);

widget_add_text_scroll_element(nfc_playlist->widget, 4, 4, 124, 60, furi_string_get_cstr(tmp_str));
widget_add_frame_element(nfc_playlist->widget, 0, 0, 128, 64, 0);

furi_string_free(playlist_content);
storage_file_close(file);
furi_string_free(tmp_str);
} else {
widget_add_text_box_element(nfc_playlist->widget, 0, 0, 128, 64, AlignCenter, AlignCenter, "\eFailed to open playlist\n\nPress back\e", false);
}

storage_file_free(file);
stream_free(stream);
furi_record_close(RECORD_STORAGE);

view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Widget);
Expand Down

0 comments on commit 06626d8

Please sign in to comment.