Skip to content

Commit

Permalink
Create playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
acegoal07 committed Apr 10, 2024
1 parent 16d6509 commit 86dd162
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 7 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ As i know these firmwares are supported and working if you know any more please
- LED indicator (Whether or not the LED's will be on)
- Reset settings (Puts all the settings back to the defaults)
## Playlist editor:
- Create PLaylist (Creates a new playlist with the given name)
- Delete playlist (Deletes the selected playlist)
- Rename playlist (Renames the selected playlist to the new name provided)
- View playlist content (Allows you to view the items in the playlist)
- Add NFC Item (Allows you to select a NFC item to add to the end of playlist)
- View playlist content (Allows you to view the contents of the playlist)
- Add NFC Item (Adds the selected nfc item to the currently selected playlist)
## Development plans/ideas:
Things i would like to add:
- Ability to remove cards from the playlist
Expand Down
11 changes: 8 additions & 3 deletions nfc_playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ static void (*const nfc_playlist_scene_on_enter_handlers[])(void*) = {
nfc_playlist_file_rename_scene_on_enter,
nfc_playlist_confirm_delete_scene_on_enter,
nfc_playlist_view_playlist_content_scene_on_enter,
nfc_playlist_nfc_select_scene_on_enter
nfc_playlist_nfc_select_scene_on_enter,
nfc_playlist_name_new_file_scene_on_enter
};

static bool (*const nfc_playlist_scene_on_event_handlers[])(void*, SceneManagerEvent) = {
Expand All @@ -22,7 +23,8 @@ static bool (*const nfc_playlist_scene_on_event_handlers[])(void*, SceneManagerE
nfc_playlist_file_rename_scene_on_event,
nfc_playlist_confirm_delete_scene_on_event,
nfc_playlist_view_playlist_content_scene_on_event,
nfc_playlist_nfc_select_scene_on_event
nfc_playlist_nfc_select_scene_on_event,
nfc_playlist_name_new_file_scene_on_event
};

static void (*const nfc_playlist_scene_on_exit_handlers[])(void*) = {
Expand All @@ -34,7 +36,8 @@ static void (*const nfc_playlist_scene_on_exit_handlers[])(void*) = {
nfc_playlist_file_rename_scene_on_exit,
nfc_playlist_confirm_delete_scene_on_exit,
nfc_playlist_view_playlist_content_scene_on_exit,
nfc_playlist_nfc_select_scene_on_exit
nfc_playlist_nfc_select_scene_on_exit,
nfc_playlist_name_new_file_scene_on_exit
};

static const SceneManagerHandlers nfc_playlist_scene_manager_handlers = {
Expand Down Expand Up @@ -92,6 +95,7 @@ static NfcPlaylist* nfc_playlist_alloc() {
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));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_NameNewFile, text_input_get_view(nfc_playlist->text_input));

Storage* storage = furi_record_open(RECORD_STORAGE);
if (!storage_common_exists(storage, PLAYLIST_DIR)) {
Expand All @@ -114,6 +118,7 @@ static void nfc_playlist_free(NfcPlaylist* nfc_playlist) {
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);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_NameNewFile);

scene_manager_free(nfc_playlist->scene_manager);
view_dispatcher_free(nfc_playlist->view_dispatcher);
Expand Down
2 changes: 2 additions & 0 deletions nfc_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typedef enum {
NfcPlaylistView_ConfirmDelete,
NfcPlaylistView_ViewPlaylistContent,
NfcPlaylistView_NfcSelect,
NfcPlaylistView_NameNewFile
} NfcPlayScenesView;

typedef enum {
Expand All @@ -38,6 +39,7 @@ typedef enum {
NfcPlaylistScene_ConfirmDelete,
NfcPlaylistScene_ViewPlaylistContent,
NfcPlaylistScene_NfcSelect,
NfcPlaylistScene_NameNewFile,
NfcPlaylistScene_count
} NfcPlaylistScene;

Expand Down
3 changes: 2 additions & 1 deletion nfc_playlist_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
#include "scences/file_rename.h"
#include "scences/confirm_delete.h"
#include "scences/view_playlist_content.h"
#include "scences/nfc_select.h"
#include "scences/nfc_select.h"
#include "scences/name_new_file.h"
11 changes: 11 additions & 0 deletions scences/file_edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ void nfc_playlist_file_edit_scene_on_enter(void* context) {

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

submenu_add_item(
nfc_playlist->submenu,
"Create Playlist",
NfcPlaylistMenuSelection_CreatePlaylist,
nfc_playlist_file_edit_menu_callback,
nfc_playlist);

submenu_add_lockable_item(
nfc_playlist->submenu,
"Delete Playlist",
Expand Down Expand Up @@ -55,6 +62,10 @@ bool nfc_playlist_file_edit_scene_on_event(void* context, SceneManagerEvent even
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case NfcPlaylistMenuSelection_CreatePlaylist:
scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_NameNewFile);
consumed = true;
break;
case NfcPlaylistMenuSelection_DeletePlaylist:
scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_ConfirmDelete);
consumed = true;
Expand Down
1 change: 1 addition & 0 deletions scences/file_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ bool nfc_playlist_file_edit_scene_on_event(void* context, SceneManagerEvent even
void nfc_playlist_file_edit_scene_on_exit(void* context);

typedef enum {
NfcPlaylistMenuSelection_CreatePlaylist,
NfcPlaylistMenuSelection_DeletePlaylist,
NfcPlaylistMenuSelection_RenamePlaylist,
NfcPlaylistMenuSelection_ViewPlaylistContent,
Expand Down
41 changes: 41 additions & 0 deletions scences/name_new_file.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "nfc_playlist.h"
#include "scences/name_new_file.h"

void nfc_playlist_name_new_file_menu_callback(void* context) {
NfcPlaylist* nfc_playlist = context;
Storage* storage = furi_record_open(RECORD_STORAGE);
FuriString* file_name = furi_string_alloc();
furi_string_printf(file_name, "/ext/apps_data/nfc_playlist/%s.txt", nfc_playlist->text_input_output);
FURI_LOG_I("Creating file: %s", furi_string_get_cstr(file_name));
if (!storage_common_exists(storage, furi_string_get_cstr(file_name))) {
File* file = storage_file_alloc(storage);
storage_file_open(file, furi_string_get_cstr(file_name), FSAM_READ_WRITE, FSOM_CREATE_NEW);
storage_file_close(file);
storage_file_free(file);
}
furi_string_move(nfc_playlist->settings.file_path, file_name);
furi_string_free(file_name);
furi_record_close(RECORD_STORAGE);
scene_manager_previous_scene(nfc_playlist->scene_manager);
}

void nfc_playlist_name_new_file_scene_on_enter(void* context) {
NfcPlaylist* nfc_playlist = context;
nfc_playlist->text_input_output = (char*)malloc(50);
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_file_menu_callback, nfc_playlist, nfc_playlist->text_input_output, 50, true);
view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileRename);
}

bool nfc_playlist_name_new_file_scene_on_event(void* context, SceneManagerEvent event) {
UNUSED(context);
UNUSED(event);
return false;
}

void nfc_playlist_name_new_file_scene_on_exit(void* context) {
NfcPlaylist* nfc_playlist = context;
text_input_reset(nfc_playlist->text_input);
free(nfc_playlist->text_input_output);
}
10 changes: 10 additions & 0 deletions scences/name_new_file.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once
#include <furi.h>
#include <gui/view_dispatcher.h>
#include <gui/scene_manager.h>
#include <gui/modules/text_input.h>
#include <storage/storage.h>

void nfc_playlist_name_new_file_scene_on_enter(void* context);
bool nfc_playlist_name_new_file_scene_on_event(void* context, SceneManagerEvent event);
void nfc_playlist_name_new_file_scene_on_exit(void* context);
6 changes: 5 additions & 1 deletion scences/nfc_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ void nfc_playlist_nfc_select_menu_callback(void* context) {
furi_string_push_back(playlist_content, buffer[i]);
}

furi_string_printf(playlist_content, "\n%s", furi_string_get_cstr(nfc_playlist->file_browser_output));
if (read_count > 0) {
furi_string_printf(playlist_content, "\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));
}

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

Expand Down

0 comments on commit 86dd162

Please sign in to comment.