Skip to content

Commit 86dd162

Browse files
committed
Create playlist
1 parent 16d6509 commit 86dd162

File tree

9 files changed

+83
-7
lines changed

9 files changed

+83
-7
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ As i know these firmwares are supported and working if you know any more please
2222
- LED indicator (Whether or not the LED's will be on)
2323
- Reset settings (Puts all the settings back to the defaults)
2424
## Playlist editor:
25+
- Create PLaylist (Creates a new playlist with the given name)
2526
- Delete playlist (Deletes the selected playlist)
2627
- Rename playlist (Renames the selected playlist to the new name provided)
27-
- View playlist content (Allows you to view the items in the playlist)
28-
- Add NFC Item (Allows you to select a NFC item to add to the end of playlist)
28+
- View playlist content (Allows you to view the contents of the playlist)
29+
- Add NFC Item (Adds the selected nfc item to the currently selected playlist)
2930
## Development plans/ideas:
3031
Things i would like to add:
3132
- Ability to remove cards from the playlist

nfc_playlist.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ static void (*const nfc_playlist_scene_on_enter_handlers[])(void*) = {
1010
nfc_playlist_file_rename_scene_on_enter,
1111
nfc_playlist_confirm_delete_scene_on_enter,
1212
nfc_playlist_view_playlist_content_scene_on_enter,
13-
nfc_playlist_nfc_select_scene_on_enter
13+
nfc_playlist_nfc_select_scene_on_enter,
14+
nfc_playlist_name_new_file_scene_on_enter
1415
};
1516

1617
static bool (*const nfc_playlist_scene_on_event_handlers[])(void*, SceneManagerEvent) = {
@@ -22,7 +23,8 @@ static bool (*const nfc_playlist_scene_on_event_handlers[])(void*, SceneManagerE
2223
nfc_playlist_file_rename_scene_on_event,
2324
nfc_playlist_confirm_delete_scene_on_event,
2425
nfc_playlist_view_playlist_content_scene_on_event,
25-
nfc_playlist_nfc_select_scene_on_event
26+
nfc_playlist_nfc_select_scene_on_event,
27+
nfc_playlist_name_new_file_scene_on_event
2628
};
2729

2830
static void (*const nfc_playlist_scene_on_exit_handlers[])(void*) = {
@@ -34,7 +36,8 @@ static void (*const nfc_playlist_scene_on_exit_handlers[])(void*) = {
3436
nfc_playlist_file_rename_scene_on_exit,
3537
nfc_playlist_confirm_delete_scene_on_exit,
3638
nfc_playlist_view_playlist_content_scene_on_exit,
37-
nfc_playlist_nfc_select_scene_on_exit
39+
nfc_playlist_nfc_select_scene_on_exit,
40+
nfc_playlist_name_new_file_scene_on_exit
3841
};
3942

4043
static const SceneManagerHandlers nfc_playlist_scene_manager_handlers = {
@@ -92,6 +95,7 @@ static NfcPlaylist* nfc_playlist_alloc() {
9295
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ConfirmDelete, widget_get_view(nfc_playlist->widget));
9396
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ViewPlaylistContent, widget_get_view(nfc_playlist->widget));
9497
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_NfcSelect, file_browser_get_view(nfc_playlist->nfc_file_browser));
98+
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_NameNewFile, text_input_get_view(nfc_playlist->text_input));
9599

96100
Storage* storage = furi_record_open(RECORD_STORAGE);
97101
if (!storage_common_exists(storage, PLAYLIST_DIR)) {
@@ -114,6 +118,7 @@ static void nfc_playlist_free(NfcPlaylist* nfc_playlist) {
114118
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ConfirmDelete);
115119
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ViewPlaylistContent);
116120
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_NfcSelect);
121+
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_NameNewFile);
117122

118123
scene_manager_free(nfc_playlist->scene_manager);
119124
view_dispatcher_free(nfc_playlist->view_dispatcher);

nfc_playlist.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ typedef enum {
2626
NfcPlaylistView_ConfirmDelete,
2727
NfcPlaylistView_ViewPlaylistContent,
2828
NfcPlaylistView_NfcSelect,
29+
NfcPlaylistView_NameNewFile
2930
} NfcPlayScenesView;
3031

3132
typedef enum {
@@ -38,6 +39,7 @@ typedef enum {
3839
NfcPlaylistScene_ConfirmDelete,
3940
NfcPlaylistScene_ViewPlaylistContent,
4041
NfcPlaylistScene_NfcSelect,
42+
NfcPlaylistScene_NameNewFile,
4143
NfcPlaylistScene_count
4244
} NfcPlaylistScene;
4345

nfc_playlist_i.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
#include "scences/file_rename.h"
88
#include "scences/confirm_delete.h"
99
#include "scences/view_playlist_content.h"
10-
#include "scences/nfc_select.h"
10+
#include "scences/nfc_select.h"
11+
#include "scences/name_new_file.h"

scences/file_edit.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ void nfc_playlist_file_edit_scene_on_enter(void* context) {
1111

1212
submenu_set_header(nfc_playlist->submenu, "Edit Playlist");
1313

14+
submenu_add_item(
15+
nfc_playlist->submenu,
16+
"Create Playlist",
17+
NfcPlaylistMenuSelection_CreatePlaylist,
18+
nfc_playlist_file_edit_menu_callback,
19+
nfc_playlist);
20+
1421
submenu_add_lockable_item(
1522
nfc_playlist->submenu,
1623
"Delete Playlist",
@@ -55,6 +62,10 @@ bool nfc_playlist_file_edit_scene_on_event(void* context, SceneManagerEvent even
5562
bool consumed = false;
5663
if(event.type == SceneManagerEventTypeCustom) {
5764
switch(event.event) {
65+
case NfcPlaylistMenuSelection_CreatePlaylist:
66+
scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_NameNewFile);
67+
consumed = true;
68+
break;
5869
case NfcPlaylistMenuSelection_DeletePlaylist:
5970
scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_ConfirmDelete);
6071
consumed = true;

scences/file_edit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ bool nfc_playlist_file_edit_scene_on_event(void* context, SceneManagerEvent even
99
void nfc_playlist_file_edit_scene_on_exit(void* context);
1010

1111
typedef enum {
12+
NfcPlaylistMenuSelection_CreatePlaylist,
1213
NfcPlaylistMenuSelection_DeletePlaylist,
1314
NfcPlaylistMenuSelection_RenamePlaylist,
1415
NfcPlaylistMenuSelection_ViewPlaylistContent,

scences/name_new_file.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include "nfc_playlist.h"
2+
#include "scences/name_new_file.h"
3+
4+
void nfc_playlist_name_new_file_menu_callback(void* context) {
5+
NfcPlaylist* nfc_playlist = context;
6+
Storage* storage = furi_record_open(RECORD_STORAGE);
7+
FuriString* file_name = furi_string_alloc();
8+
furi_string_printf(file_name, "/ext/apps_data/nfc_playlist/%s.txt", nfc_playlist->text_input_output);
9+
FURI_LOG_I("Creating file: %s", furi_string_get_cstr(file_name));
10+
if (!storage_common_exists(storage, furi_string_get_cstr(file_name))) {
11+
File* file = storage_file_alloc(storage);
12+
storage_file_open(file, furi_string_get_cstr(file_name), FSAM_READ_WRITE, FSOM_CREATE_NEW);
13+
storage_file_close(file);
14+
storage_file_free(file);
15+
}
16+
furi_string_move(nfc_playlist->settings.file_path, file_name);
17+
furi_string_free(file_name);
18+
furi_record_close(RECORD_STORAGE);
19+
scene_manager_previous_scene(nfc_playlist->scene_manager);
20+
}
21+
22+
void nfc_playlist_name_new_file_scene_on_enter(void* context) {
23+
NfcPlaylist* nfc_playlist = context;
24+
nfc_playlist->text_input_output = (char*)malloc(50);
25+
text_input_set_header_text(nfc_playlist->text_input, "Enter file name");
26+
text_input_set_minimum_length(nfc_playlist->text_input, 1);
27+
text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_name_new_file_menu_callback, nfc_playlist, nfc_playlist->text_input_output, 50, true);
28+
view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileRename);
29+
}
30+
31+
bool nfc_playlist_name_new_file_scene_on_event(void* context, SceneManagerEvent event) {
32+
UNUSED(context);
33+
UNUSED(event);
34+
return false;
35+
}
36+
37+
void nfc_playlist_name_new_file_scene_on_exit(void* context) {
38+
NfcPlaylist* nfc_playlist = context;
39+
text_input_reset(nfc_playlist->text_input);
40+
free(nfc_playlist->text_input_output);
41+
}

scences/name_new_file.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
#include <furi.h>
3+
#include <gui/view_dispatcher.h>
4+
#include <gui/scene_manager.h>
5+
#include <gui/modules/text_input.h>
6+
#include <storage/storage.h>
7+
8+
void nfc_playlist_name_new_file_scene_on_enter(void* context);
9+
bool nfc_playlist_name_new_file_scene_on_event(void* context, SceneManagerEvent event);
10+
void nfc_playlist_name_new_file_scene_on_exit(void* context);

scences/nfc_select.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ void nfc_playlist_nfc_select_menu_callback(void* context) {
1515
furi_string_push_back(playlist_content, buffer[i]);
1616
}
1717

18-
furi_string_printf(playlist_content, "\n%s", furi_string_get_cstr(nfc_playlist->file_browser_output));
18+
if (read_count > 0) {
19+
furi_string_printf(playlist_content, "\n%s", furi_string_get_cstr(nfc_playlist->file_browser_output));
20+
} else {
21+
furi_string_printf(playlist_content, "%s", furi_string_get_cstr(nfc_playlist->file_browser_output));
22+
}
1923

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

0 commit comments

Comments
 (0)