Skip to content

Commit

Permalink
Edit playlist
Browse files Browse the repository at this point in the history
- Adds edit playlist section
- Adds delete playlist function to edit playlist
  • Loading branch information
acegoal07 committed Jan 31, 2024
1 parent 9699914 commit 75629d3
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 6 deletions.
11 changes: 8 additions & 3 deletions nfc_playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ static void (*const nfc_playlist_scene_on_enter_handlers[])(void*) = {
nfc_playlist_main_menu_scene_on_enter,
nfc_playlist_settings_scene_on_enter,
nfc_playlist_emulation_scene_on_enter,
nfc_playlist_file_select_scene_on_enter
nfc_playlist_file_select_scene_on_enter,
nfc_playlist_file_edit_scene_on_enter
};

static bool (*const nfc_playlist_scene_on_event_handlers[])(void*, SceneManagerEvent) = {
nfc_playlist_main_menu_scene_on_event,
nfc_playlist_settings_scene_on_event,
nfc_playlist_emulation_scene_on_event,
nfc_playlist_file_select_scene_on_event
nfc_playlist_file_select_scene_on_event,
nfc_playlist_file_edit_scene_on_event
};

static void (*const nfc_playlist_scene_on_exit_handlers[])(void*) = {
nfc_playlist_main_menu_scene_on_exit,
nfc_playlist_settings_scene_on_exit,
nfc_playlist_emulation_scene_on_exit,
nfc_playlist_file_select_scene_on_exit
nfc_playlist_file_select_scene_on_exit,
nfc_playlist_file_edit_scene_on_exit
};

static const SceneManagerHandlers nfc_playlist_scene_manager_handlers = {
Expand Down Expand Up @@ -66,6 +69,7 @@ static NfcPlaylist* nfc_playlist_alloc() {
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings, variable_item_list_get_view(nfc_playlist->variable_item_list));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup, popup_get_view(nfc_playlist->popup));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileSelect, file_browser_get_view(nfc_playlist->file_browser));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit, submenu_get_view(nfc_playlist->submenu));
return nfc_playlist;
}

Expand All @@ -76,6 +80,7 @@ static void nfc_playlist_free(NfcPlaylist* nfc_playlist) {
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileSelect);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit);
view_dispatcher_free(nfc_playlist->view_dispatcher);
variable_item_list_free(nfc_playlist->variable_item_list);
submenu_free(nfc_playlist->submenu);
Expand Down
4 changes: 3 additions & 1 deletion nfc_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ typedef enum {
NfcPlaylistView_Menu,
NfcPlaylistView_Settings,
NfcPlaylistView_Popup,
NfcPlaylistView_FileSelect
NfcPlaylistView_FileSelect,
NfcPlaylistView_FileEdit
} NfcPlayScenesView;

typedef enum {
NfcPlaylistScene_MainMenu,
NfcPlaylistScene_Settings,
NfcPlaylistScene_EmulatingPopup,
NfcPlaylistScene_FileSelect,
NfcPlaylistScene_FileEdit,
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 @@ -2,4 +2,5 @@
#include "scences/main_menu.h"
#include "scences/settings.h"
#include "scences/emulation.h"
#include "scences/file_select.h"
#include "scences/file_select.h"
#include "scences/file_edit.h"
1 change: 1 addition & 0 deletions scences/emulation.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ int32_t nfc_playlist_emulation_task(void* context) {

furi_string_free(line);
file_stream_close(stream);
furi_record_close(RECORD_STORAGE);
stream_free(stream);

return 0;
Expand Down
50 changes: 50 additions & 0 deletions scences/file_edit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "nfc_playlist.h"
#include "scences/file_edit.h"

typedef enum {
NfcPlaylistMenuSelection_DeletePlaylist
} NfcPlaylistMenuSelection;

void nfc_playlist_file_edit_menu_callback(void* context, uint32_t index) {
NfcPlaylist* nfc_playlist = context;
Storage* storage = furi_record_open(RECORD_STORAGE);
switch(index) {
case NfcPlaylistMenuSelection_DeletePlaylist: {
storage_simply_remove(storage, furi_string_get_cstr(nfc_playlist->file_path));
nfc_playlist->file_selected = false;
nfc_playlist->file_selected_check = false;
nfc_playlist->file_path = nfc_playlist->base_file_path;
scene_manager_previous_scene(nfc_playlist->scene_manager);
break;
}
default:
break;
}
furi_record_close(RECORD_STORAGE);
}

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

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

submenu_add_item(
nfc_playlist->submenu,
"Delete Playlist",
NfcPlaylistMenuSelection_DeletePlaylist,
nfc_playlist_file_edit_menu_callback,
nfc_playlist);

view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit);
}

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

void nfc_playlist_file_edit_scene_on_exit(void* context) {
NfcPlaylist* nfc_playlist = context;
submenu_reset(nfc_playlist->submenu);
}
13 changes: 13 additions & 0 deletions scences/file_edit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once
#include <furi.h>
#include <gui/gui.h>
#include <gui/view_dispatcher.h>
#include <gui/scene_manager.h>
#include <gui/modules/submenu.h>
#include <storage/storage.h>
#include <toolbox/stream/stream.h>
#include <toolbox/stream/file_stream.h>

void nfc_playlist_file_edit_scene_on_enter(void* context);
bool nfc_playlist_file_edit_scene_on_event(void* context, SceneManagerEvent event);
void nfc_playlist_file_edit_scene_on_exit(void* context);
18 changes: 17 additions & 1 deletion scences/main_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
typedef enum {
NfcPlaylistEvent_ShowEmulatingPopup,
NfcPlaylistEvent_ShowFileSelect,
NfcPlaylistEvent_ShowFileEdit,
NfcPlaylistEvent_ShowSettings
} NfcPlaylistMainMenuEvent;

typedef enum {
NfcPlaylistMenuSelection_Start,
NfcPlaylistMenuSelection_FileSelect,
NfcPlaylistMenuSelection_Settings
NfcPlaylistMenuSelection_FileEdit,
NfcPlaylistMenuSelection_Settings,
} NfcPlaylistMenuSelection;

void nfc_playlist_main_menu_menu_callback(void* context, uint32_t index) {
Expand All @@ -22,6 +24,9 @@ void nfc_playlist_main_menu_menu_callback(void* context, uint32_t index) {
case NfcPlaylistMenuSelection_FileSelect:
scene_manager_handle_custom_event(nfc_playlist->scene_manager, NfcPlaylistEvent_ShowFileSelect);
break;
case NfcPlaylistMenuSelection_FileEdit:
scene_manager_handle_custom_event(nfc_playlist->scene_manager, NfcPlaylistEvent_ShowFileEdit);
break;
case NfcPlaylistMenuSelection_Settings:
scene_manager_handle_custom_event(nfc_playlist->scene_manager, NfcPlaylistEvent_ShowSettings);
break;
Expand Down Expand Up @@ -53,6 +58,13 @@ void nfc_playlist_main_menu_scene_on_enter(void* context) {
NfcPlaylistMenuSelection_FileSelect,
nfc_playlist_main_menu_menu_callback,
nfc_playlist);

submenu_add_item(
nfc_playlist->submenu,
"Edit playlist",
NfcPlaylistMenuSelection_FileEdit,
nfc_playlist_main_menu_menu_callback,
nfc_playlist);

submenu_add_item(
nfc_playlist->submenu,
Expand All @@ -77,6 +89,10 @@ bool nfc_playlist_main_menu_scene_on_event(void* context, SceneManagerEvent even
scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_FileSelect);
consumed = true;
break;
case NfcPlaylistEvent_ShowFileEdit:
scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_FileEdit);
consumed = true;
break;
case NfcPlaylistEvent_ShowSettings:
scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_Settings);
consumed = true;
Expand Down

0 comments on commit 75629d3

Please sign in to comment.