Skip to content

Commit

Permalink
Add items to playlists
Browse files Browse the repository at this point in the history
  • Loading branch information
acegoal07 committed Apr 10, 2024
1 parent ada95eb commit 340a3d5
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 12 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions nfc_playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) = {
Expand All @@ -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*) = {
Expand All @@ -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 = {
Expand Down Expand Up @@ -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();

Expand All @@ -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)) {
Expand All @@ -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);
Expand All @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion nfc_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ typedef enum {
NfcPlaylistView_FileEdit,
NfcPlaylistView_FileRename,
NfcPlaylistView_ConfirmDelete,
NfcPlaylistView_ViewPlaylistContent
NfcPlaylistView_ViewPlaylistContent,
NfcPlaylistView_NfcSelect,
} NfcPlayScenesView;

typedef enum {
Expand All @@ -36,6 +37,7 @@ typedef enum {
NfcPlaylistScene_FileRename,
NfcPlaylistScene_ConfirmDelete,
NfcPlaylistScene_ViewPlaylistContent,
NfcPlaylistScene_NfcSelect,
NfcPlaylistScene_count
} NfcPlaylistScene;

Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion nfc_playlist_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
#include "scences/view_playlist_content.h"
#include "scences/nfc_select.h"
13 changes: 13 additions & 0 deletions scences/file_edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion scences/file_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
56 changes: 56 additions & 0 deletions scences/nfc_select.c
Original file line number Diff line number Diff line change
@@ -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);
}
12 changes: 12 additions & 0 deletions scences/nfc_select.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#include <furi.h>
#include <gui/view_dispatcher.h>
#include <gui/scene_manager.h>
#include <gui/modules/file_browser.h>
#include <storage/storage.h>

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
7 changes: 3 additions & 4 deletions scences/view_playlist_content.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
4 changes: 3 additions & 1 deletion scences/view_playlist_content.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
void nfc_playlist_view_playlist_content_scene_on_exit(void* context);

#define MAX_PLAYLIST_SIZE 1000

0 comments on commit 340a3d5

Please sign in to comment.