Skip to content

Commit

Permalink
Uniform
Browse files Browse the repository at this point in the history
- Makes a define variable for the size of the playlist name meaning it only needs to be changed in one place
- Removes accidental file clear function from view playlist content which cant run but shouldn't be there
  • Loading branch information
acegoal07 committed May 23, 2024
1 parent e574e05 commit 4396569
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
9 changes: 4 additions & 5 deletions nfc_playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ static NfcPlaylist* nfc_playlist_alloc() {
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput, text_input_get_view(nfc_playlist->text_input));

Storage* storage = furi_record_open(RECORD_STORAGE);
if (!storage_common_exists(storage, PLAYLIST_DIR)) {
storage_common_mkdir(storage, PLAYLIST_DIR);
}
storage_simply_mkdir(storage, PLAYLIST_DIR);

furi_record_close(RECORD_STORAGE);

return nfc_playlist;
Expand All @@ -68,11 +67,11 @@ static void nfc_playlist_free(NfcPlaylist* nfc_playlist) {

scene_manager_free(nfc_playlist->scene_manager);
view_dispatcher_free(nfc_playlist->view_dispatcher);
furi_record_close(RECORD_NOTIFICATION);

variable_item_list_free(nfc_playlist->variable_item_list);
submenu_free(nfc_playlist->submenu);
widget_free(nfc_playlist->widget);

furi_record_close(RECORD_NOTIFICATION);
file_browser_free(nfc_playlist->file_browser);
text_input_free(nfc_playlist->text_input);
popup_free(nfc_playlist->popup);
Expand Down
1 change: 1 addition & 0 deletions nfc_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ 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_NAME_LEN 100

typedef enum NfcPlaylistLedState {
NfcPlaylistLedState_Normal,
Expand Down
5 changes: 3 additions & 2 deletions scenes/nfc_playlist_scene_name_new_playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ void nfc_playlist_name_new_playlist_menu_callback(void* context) {

void nfc_playlist_name_new_playlist_scene_on_enter(void* context) {
NfcPlaylist* nfc_playlist = context;
nfc_playlist->text_input_output = (char*)malloc(50);

nfc_playlist->text_input_output = (char*)malloc(PLAYLIST_NAME_LEN);
text_input_set_header_text(nfc_playlist->text_input, "Enter file name");
text_input_set_minimum_length(nfc_playlist->text_input, 1);
text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_name_new_playlist_menu_callback, nfc_playlist, nfc_playlist->text_input_output, 50, true);
text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_name_new_playlist_menu_callback, nfc_playlist, nfc_playlist->text_input_output, PLAYLIST_NAME_LEN, true);

view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput);
}
Expand Down
7 changes: 3 additions & 4 deletions scenes/nfc_playlist_scene_playlist_rename.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ void nfc_playlist_playlist_rename_menu_callback(void* context) {
furi_string_cat_str(new_file_path, ".txt");

if (storage_common_rename_safe(storage, old_file_path, furi_string_get_cstr(new_file_path)) == 0) {
furi_string_move(nfc_playlist->settings.playlist_path, new_file_path);
} else {
furi_string_free(new_file_path);
furi_string_swap(nfc_playlist->settings.playlist_path, new_file_path);
}

furi_string_free(new_file_path);
furi_record_close(RECORD_STORAGE);

scene_manager_search_and_switch_to_previous_scene(nfc_playlist->scene_manager, NfcPlaylistScene_MainMenu);
Expand All @@ -36,7 +35,7 @@ void nfc_playlist_playlist_rename_scene_on_enter(void* context) {

text_input_set_header_text(nfc_playlist->text_input, "Enter new file name");
text_input_set_minimum_length(nfc_playlist->text_input, 1);
text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_playlist_rename_menu_callback, nfc_playlist, nfc_playlist->text_input_output, (50 + sizeof(nfc_playlist->text_input_output)), false);
text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_playlist_rename_menu_callback, nfc_playlist, nfc_playlist->text_input_output, PLAYLIST_NAME_LEN, false);

view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput);
}
Expand Down
1 change: 0 additions & 1 deletion scenes/nfc_playlist_scene_view_playlist_content.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ void nfc_playlist_view_playlist_content_scene_on_enter(void* context) {
furi_string_cat_printf(tmp_str, "%s", furi_string_get_cstr(line));
}

stream_clean(stream);
furi_string_free(line);
file_stream_close(stream);

Expand Down

0 comments on commit 4396569

Please sign in to comment.