Skip to content

Commit

Permalink
Adds view playlist content
Browse files Browse the repository at this point in the history
  • Loading branch information
acegoal07 committed Apr 9, 2024
1 parent ec33779 commit ada95eb
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 10 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ As i know these firmwares are supported and working if you know any more please
- Reset settings (Puts all the settings back to the defaults)
## Playlist editor:
- Delete playlist (Deletes the selected playlist)
- Rename playlist (Renames the selected playlist the new name provided)
- Rename playlist (Renames the selected playlist to the new name provided)
- 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

Any feedback is welcome and would be very much appreciated
11 changes: 8 additions & 3 deletions nfc_playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ static void (*const nfc_playlist_scene_on_enter_handlers[])(void*) = {
nfc_playlist_playlist_select_scene_on_enter,
nfc_playlist_file_edit_scene_on_enter,
nfc_playlist_file_rename_scene_on_enter,
nfc_playlist_confirm_delete_scene_on_enter
nfc_playlist_confirm_delete_scene_on_enter,
nfc_playlist_view_playlist_content_scene_on_enter
};

static bool (*const nfc_playlist_scene_on_event_handlers[])(void*, SceneManagerEvent) = {
Expand All @@ -18,7 +19,8 @@ static bool (*const nfc_playlist_scene_on_event_handlers[])(void*, SceneManagerE
nfc_playlist_playlist_select_scene_on_event,
nfc_playlist_file_edit_scene_on_event,
nfc_playlist_file_rename_scene_on_event,
nfc_playlist_confirm_delete_scene_on_event
nfc_playlist_confirm_delete_scene_on_event,
nfc_playlist_view_playlist_content_scene_on_event
};

static void (*const nfc_playlist_scene_on_exit_handlers[])(void*) = {
Expand All @@ -28,7 +30,8 @@ static void (*const nfc_playlist_scene_on_exit_handlers[])(void*) = {
nfc_playlist_playlist_select_scene_on_exit,
nfc_playlist_file_edit_scene_on_exit,
nfc_playlist_file_rename_scene_on_exit,
nfc_playlist_confirm_delete_scene_on_exit
nfc_playlist_confirm_delete_scene_on_exit,
nfc_playlist_view_playlist_content_scene_on_exit
};

static const SceneManagerHandlers nfc_playlist_scene_manager_handlers = {
Expand Down Expand Up @@ -82,6 +85,7 @@ static NfcPlaylist* nfc_playlist_alloc() {
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit, submenu_get_view(nfc_playlist->submenu));
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));

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

scene_manager_free(nfc_playlist->scene_manager);
view_dispatcher_free(nfc_playlist->view_dispatcher);
Expand Down
4 changes: 3 additions & 1 deletion nfc_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ typedef enum {
NfcPlaylistView_PlaylistSelect,
NfcPlaylistView_FileEdit,
NfcPlaylistView_FileRename,
NfcPlaylistView_ConfirmDelete
NfcPlaylistView_ConfirmDelete,
NfcPlaylistView_ViewPlaylistContent
} NfcPlayScenesView;

typedef enum {
Expand All @@ -34,6 +35,7 @@ typedef enum {
NfcPlaylistScene_FileEdit,
NfcPlaylistScene_FileRename,
NfcPlaylistScene_ConfirmDelete,
NfcPlaylistScene_ViewPlaylistContent,
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 @@ -5,4 +5,5 @@
#include "scences/playlist_select.h"
#include "scences/file_edit.h"
#include "scences/file_rename.h"
#include "scences/confirm_delete.h"
#include "scences/confirm_delete.h"
#include "scences/view_playlist_content.h"
2 changes: 1 addition & 1 deletion scences/emulation.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int32_t nfc_playlist_emulation_task(void* context) {
FuriString* line = furi_string_alloc();
FuriString* tmp_header_str = furi_string_alloc();
FuriString* tmp_counter_str = furi_string_alloc();

while(stream_read_line(stream, line) && EmulationState == NfcPlaylistEmulationState_Emulating) {

char* file_path = (char*)furi_string_get_cstr(line);
Expand Down
13 changes: 13 additions & 0 deletions scences/file_edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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,
"View Playlist Content",
NfcPlaylistMenuSelection_ViewPlaylistContent,
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 @@ -45,6 +54,10 @@ bool nfc_playlist_file_edit_scene_on_event(void* context, SceneManagerEvent even
scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_FileRename);
consumed = true;
break;
case NfcPlaylistMenuSelection_ViewPlaylistContent:
scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_ViewPlaylistContent);
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 @@ -10,5 +10,6 @@ void nfc_playlist_file_edit_scene_on_exit(void* context);

typedef enum {
NfcPlaylistMenuSelection_DeletePlaylist,
NfcPlaylistMenuSelection_RenamePlaylist
NfcPlaylistMenuSelection_RenamePlaylist,
NfcPlaylistMenuSelection_ViewPlaylistContent
} NfcPlaylistFileEditMenuSelection;
2 changes: 1 addition & 1 deletion scences/file_rename.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void nfc_playlist_file_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_file_rename_menu_callback, nfc_playlist, nfc_playlist->text_input_output, 50, true);
view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileRename);
view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileRename);
}

bool nfc_playlist_file_rename_scene_on_event(void* context, SceneManagerEvent event) {
Expand Down
2 changes: 1 addition & 1 deletion scences/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void nfc_playlist_settings_scene_on_enter(void* context) {

VariableItem* credits = variable_item_list_add(nfc_playlist->variable_item_list, "acegoal07", 1, NULL, NULL);
variable_item_set_current_value_text(credits, "Credits");

variable_item_list_set_enter_callback(nfc_playlist->variable_item_list, nfc_playlist_settings_menu_callback, nfc_playlist);
view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings);
furi_string_free(tmp_str);
Expand Down
39 changes: 39 additions & 0 deletions scences/view_playlist_content.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "nfc_playlist.h"
#include "scences/view_playlist_content.h"

void nfc_playlist_view_playlist_content_scene_on_enter(void* context) {
NfcPlaylist* nfc_playlist = context;

Storage* storage = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(storage);
uint8_t buffer[8000];
FuriString* playlist_content = furi_string_alloc();

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);

for(uint16_t i = 0; i < read_count; i++) {
furi_string_push_back(playlist_content, buffer[i]);
}

widget_add_text_scroll_element(nfc_playlist->widget, 4, 4, 124, 60, furi_string_get_cstr(playlist_content));
widget_add_frame_element(nfc_playlist->widget, 0, 0, 128, 64, 0);

furi_string_free(playlist_content);
storage_file_close(file);
storage_file_free(file);
furi_record_close(RECORD_STORAGE);

view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ViewPlaylistContent);
}

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

void nfc_playlist_view_playlist_content_scene_on_exit(void* context) {
NfcPlaylist* nfc_playlist = context;
widget_reset(nfc_playlist->widget);
}
10 changes: 10 additions & 0 deletions scences/view_playlist_content.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/widget.h>
#include <storage/storage.h>

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);

0 comments on commit ada95eb

Please sign in to comment.