From 340a3d5dfb243b2493ed23742a4f2edb3c43f7b4 Mon Sep 17 00:00:00 2001 From: acegoal07 Date: Wed, 10 Apr 2024 17:55:53 +0100 Subject: [PATCH] Add items to playlists --- README.md | 1 - nfc_playlist.c | 14 +++++++-- nfc_playlist.h | 5 ++- nfc_playlist_i.h | 3 +- scences/file_edit.c | 13 ++++++++ scences/file_edit.h | 3 +- scences/nfc_select.c | 56 +++++++++++++++++++++++++++++++++ scences/nfc_select.h | 12 +++++++ scences/view_playlist_content.c | 7 ++--- scences/view_playlist_content.h | 4 ++- 10 files changed, 106 insertions(+), 12 deletions(-) create mode 100644 scences/nfc_select.c create mode 100644 scences/nfc_select.h diff --git a/README.md b/README.md index a4a51758792..3aa55285a40 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,6 @@ As i know these firmwares are supported and working if you know any more please - View playlist content (Allows you to view the items in the playlist) ## Development plans/ideas: Things i would like to add: -- Ability to add cards to playlists - Ability to remove cards from the playlist These features are not guaranteed to be added but are being looked at as features to add diff --git a/nfc_playlist.c b/nfc_playlist.c index 767776f3a28..ec31ff9b99a 100644 --- a/nfc_playlist.c +++ b/nfc_playlist.c @@ -9,7 +9,8 @@ static void (*const nfc_playlist_scene_on_enter_handlers[])(void*) = { nfc_playlist_file_edit_scene_on_enter, nfc_playlist_file_rename_scene_on_enter, nfc_playlist_confirm_delete_scene_on_enter, - nfc_playlist_view_playlist_content_scene_on_enter + nfc_playlist_view_playlist_content_scene_on_enter, + nfc_playlist_nfc_select_scene_on_enter }; static bool (*const nfc_playlist_scene_on_event_handlers[])(void*, SceneManagerEvent) = { @@ -20,7 +21,8 @@ static bool (*const nfc_playlist_scene_on_event_handlers[])(void*, SceneManagerE nfc_playlist_file_edit_scene_on_event, nfc_playlist_file_rename_scene_on_event, nfc_playlist_confirm_delete_scene_on_event, - nfc_playlist_view_playlist_content_scene_on_event + nfc_playlist_view_playlist_content_scene_on_event, + nfc_playlist_nfc_select_scene_on_event }; static void (*const nfc_playlist_scene_on_exit_handlers[])(void*) = { @@ -31,7 +33,8 @@ static void (*const nfc_playlist_scene_on_exit_handlers[])(void*) = { nfc_playlist_file_edit_scene_on_exit, nfc_playlist_file_rename_scene_on_exit, nfc_playlist_confirm_delete_scene_on_exit, - nfc_playlist_view_playlist_content_scene_on_exit + nfc_playlist_view_playlist_content_scene_on_exit, + nfc_playlist_nfc_select_scene_on_exit }; static const SceneManagerHandlers nfc_playlist_scene_manager_handlers = { @@ -72,6 +75,8 @@ static NfcPlaylist* nfc_playlist_alloc() { nfc_playlist->notification = furi_record_open(RECORD_NOTIFICATION); nfc_playlist->playlist_file_browser = file_browser_alloc(nfc_playlist->file_browser_output); + nfc_playlist->nfc_file_browser = file_browser_alloc(nfc_playlist->file_browser_output); + nfc_playlist->text_input = text_input_alloc(); nfc_playlist->popup = popup_alloc(); @@ -86,6 +91,7 @@ static NfcPlaylist* nfc_playlist_alloc() { view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileRename, text_input_get_view(nfc_playlist->text_input)); view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ConfirmDelete, widget_get_view(nfc_playlist->widget)); view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ViewPlaylistContent, widget_get_view(nfc_playlist->widget)); + view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_NfcSelect, file_browser_get_view(nfc_playlist->nfc_file_browser)); Storage* storage = furi_record_open(RECORD_STORAGE); if (!storage_common_exists(storage, PLAYLIST_DIR)) { @@ -107,6 +113,7 @@ static void nfc_playlist_free(NfcPlaylist* nfc_playlist) { view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileRename); view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ConfirmDelete); view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ViewPlaylistContent); + view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_NfcSelect); scene_manager_free(nfc_playlist->scene_manager); view_dispatcher_free(nfc_playlist->view_dispatcher); @@ -116,6 +123,7 @@ static void nfc_playlist_free(NfcPlaylist* nfc_playlist) { furi_record_close(RECORD_NOTIFICATION); file_browser_free(nfc_playlist->playlist_file_browser); + file_browser_free(nfc_playlist->nfc_file_browser); text_input_free(nfc_playlist->text_input); popup_free(nfc_playlist->popup); diff --git a/nfc_playlist.h b/nfc_playlist.h index 17a6bc6c8dd..bed5af41375 100644 --- a/nfc_playlist.h +++ b/nfc_playlist.h @@ -24,7 +24,8 @@ typedef enum { NfcPlaylistView_FileEdit, NfcPlaylistView_FileRename, NfcPlaylistView_ConfirmDelete, - NfcPlaylistView_ViewPlaylistContent + NfcPlaylistView_ViewPlaylistContent, + NfcPlaylistView_NfcSelect, } NfcPlayScenesView; typedef enum { @@ -36,6 +37,7 @@ typedef enum { NfcPlaylistScene_FileRename, NfcPlaylistScene_ConfirmDelete, NfcPlaylistScene_ViewPlaylistContent, + NfcPlaylistScene_NfcSelect, NfcPlaylistScene_count } NfcPlaylistScene; @@ -52,6 +54,7 @@ typedef struct { ViewDispatcher* view_dispatcher; VariableItemList* variable_item_list; FileBrowser* playlist_file_browser; + FileBrowser* nfc_file_browser; FuriString* file_browser_output; TextInput* text_input; char* text_input_output; diff --git a/nfc_playlist_i.h b/nfc_playlist_i.h index 03c23a306a6..a87498b341b 100644 --- a/nfc_playlist_i.h +++ b/nfc_playlist_i.h @@ -6,4 +6,5 @@ #include "scences/file_edit.h" #include "scences/file_rename.h" #include "scences/confirm_delete.h" -#include "scences/view_playlist_content.h" \ No newline at end of file +#include "scences/view_playlist_content.h" +#include "scences/nfc_select.h" \ No newline at end of file diff --git a/scences/file_edit.c b/scences/file_edit.c index 5a195d9772c..49dad3ac446 100644 --- a/scences/file_edit.c +++ b/scences/file_edit.c @@ -38,6 +38,15 @@ void nfc_playlist_file_edit_scene_on_enter(void* context) { furi_string_empty(nfc_playlist->settings.file_path), "No\nplaylist\nselected"); + submenu_add_lockable_item( + nfc_playlist->submenu, + "Add NFC Item", + NfcPlaylistMenuSelection_AddNfcItem, + nfc_playlist_file_edit_menu_callback, + nfc_playlist, + furi_string_empty(nfc_playlist->settings.file_path), + "No\nplaylist\nselected"); + view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit); } @@ -58,6 +67,10 @@ bool nfc_playlist_file_edit_scene_on_event(void* context, SceneManagerEvent even scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_ViewPlaylistContent); consumed = true; break; + case NfcPlaylistMenuSelection_AddNfcItem: + scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_NfcSelect); + consumed = true; + break; default: break; } diff --git a/scences/file_edit.h b/scences/file_edit.h index 270892fd8e5..6e116eee13d 100644 --- a/scences/file_edit.h +++ b/scences/file_edit.h @@ -11,5 +11,6 @@ void nfc_playlist_file_edit_scene_on_exit(void* context); typedef enum { NfcPlaylistMenuSelection_DeletePlaylist, NfcPlaylistMenuSelection_RenamePlaylist, - NfcPlaylistMenuSelection_ViewPlaylistContent + NfcPlaylistMenuSelection_ViewPlaylistContent, + NfcPlaylistMenuSelection_AddNfcItem } NfcPlaylistFileEditMenuSelection; \ No newline at end of file diff --git a/scences/nfc_select.c b/scences/nfc_select.c new file mode 100644 index 00000000000..0d9151c8e16 --- /dev/null +++ b/scences/nfc_select.c @@ -0,0 +1,56 @@ +#include "nfc_playlist.h" +#include "scences/nfc_select.h" + +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); + uint8_t buffer[MAX_PLAYLIST_SIZE]; + storage_file_open(file, furi_string_get_cstr(nfc_playlist->settings.file_path), FSAM_READ_WRITE, FSOM_OPEN_EXISTING); + uint16_t read_count = storage_file_read(file, buffer, MAX_PLAYLIST_SIZE); + FuriString* playlist_content = furi_string_alloc(); + + for(uint16_t i = 0; i < read_count; i++) { + furi_string_push_back(playlist_content, buffer[i]); + } + + furi_string_printf(playlist_content, "\n%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)); + + furi_string_free(playlist_content); + storage_file_close(file); + storage_file_free(file); + furi_record_close(RECORD_STORAGE); + furi_string_reset(nfc_playlist->file_browser_output); + scene_manager_previous_scene(nfc_playlist->scene_manager); +} + +void nfc_playlist_nfc_select_scene_on_enter(void* context) { + NfcPlaylist* nfc_playlist = context; + file_browser_configure( + nfc_playlist->playlist_file_browser, + ".nfc", + "/ext/nfc/", + true, + true, + &I_Nfc_10px, + true); + view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_PlaylistSelect); + file_browser_set_callback(nfc_playlist->playlist_file_browser, nfc_playlist_nfc_select_menu_callback, nfc_playlist); + FuriString* tmp_str = furi_string_alloc_set_str("/ext/nfc/"); + file_browser_start(nfc_playlist->playlist_file_browser, tmp_str); + furi_string_free(tmp_str); +} + +bool nfc_playlist_nfc_select_scene_on_event(void* context, SceneManagerEvent event) { + UNUSED(event); + UNUSED(context); + return false; +} + +void nfc_playlist_nfc_select_scene_on_exit(void* context) { + NfcPlaylist* nfc_playlist = context; + file_browser_stop(nfc_playlist->playlist_file_browser); +} \ No newline at end of file diff --git a/scences/nfc_select.h b/scences/nfc_select.h new file mode 100644 index 00000000000..3c179327633 --- /dev/null +++ b/scences/nfc_select.h @@ -0,0 +1,12 @@ +#pragma once +#include +#include +#include +#include +#include + +void nfc_playlist_nfc_select_scene_on_enter(void* context); +bool nfc_playlist_nfc_select_scene_on_event(void* context, SceneManagerEvent event); +void nfc_playlist_nfc_select_scene_on_exit(void* context); + +#define MAX_PLAYLIST_SIZE 1000 \ No newline at end of file diff --git a/scences/view_playlist_content.c b/scences/view_playlist_content.c index 1e7c431504f..7562b73bff8 100644 --- a/scences/view_playlist_content.c +++ b/scences/view_playlist_content.c @@ -6,11 +6,10 @@ void nfc_playlist_view_playlist_content_scene_on_enter(void* context) { Storage* storage = furi_record_open(RECORD_STORAGE); File* file = storage_file_alloc(storage); - uint8_t buffer[8000]; - FuriString* playlist_content = furi_string_alloc(); - + uint8_t buffer[MAX_PLAYLIST_SIZE]; storage_file_open(file, furi_string_get_cstr(nfc_playlist->settings.file_path), FSAM_READ, FSOM_OPEN_EXISTING); - uint16_t read_count = storage_file_read(file, buffer, 8000); + uint16_t read_count = storage_file_read(file, buffer, MAX_PLAYLIST_SIZE); + FuriString* playlist_content = furi_string_alloc(); for(uint16_t i = 0; i < read_count; i++) { furi_string_push_back(playlist_content, buffer[i]); diff --git a/scences/view_playlist_content.h b/scences/view_playlist_content.h index 9ccdeaddcb3..45c28be0ef3 100644 --- a/scences/view_playlist_content.h +++ b/scences/view_playlist_content.h @@ -7,4 +7,6 @@ void nfc_playlist_view_playlist_content_scene_on_enter(void* context); bool nfc_playlist_view_playlist_content_scene_on_event(void* context, SceneManagerEvent event); -void nfc_playlist_view_playlist_content_scene_on_exit(void* context); \ No newline at end of file +void nfc_playlist_view_playlist_content_scene_on_exit(void* context); + +#define MAX_PLAYLIST_SIZE 1000 \ No newline at end of file