Skip to content

Commit

Permalink
Cut down
Browse files Browse the repository at this point in the history
- Cuts down on checks that are made and how they are made
  • Loading branch information
acegoal07 committed Apr 9, 2024
1 parent 1f56464 commit ec33779
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 32 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ 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 the new name provided)
## Development plans/ideas:
Things i would like to add:
- Ability to add cards to playlists
- Ability to remove cards from the playlist

Any feedback is welcome and would be very much appreciated
2 changes: 1 addition & 1 deletion application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ App(
fap_category="NFC",
fap_author="@acegoal07",
fap_weburl="https://github.com/acegoal07/FlipperZero_NFC_Playlist/tree/main",
fap_version="1.6",
fap_version="1.7",
fap_icon="assets/icon.png",
fap_private_libs=[
Lib(
Expand Down
13 changes: 5 additions & 8 deletions nfc_playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,15 @@ static NfcPlaylist* nfc_playlist_alloc() {
nfc_playlist->submenu = submenu_alloc();
nfc_playlist->widget= widget_alloc();

nfc_playlist->settings.base_file_path = furi_string_alloc_set_str("/ext/apps_data/nfc_playlist/");
nfc_playlist->settings.file_path = furi_string_alloc();
nfc_playlist->file_browser_output = furi_string_alloc();
nfc_playlist->settings.playlist_selected = false;
nfc_playlist->settings.playlist_selected_check = false;
nfc_playlist->settings.emulate_timeout = default_emulate_timeout;
nfc_playlist->settings.emulate_delay = default_emulate_delay;
nfc_playlist->settings.emulate_led_indicator = default_emulate_led_indicator;

nfc_playlist->notification = furi_record_open(RECORD_NOTIFICATION);
nfc_playlist->file_browser = file_browser_alloc(nfc_playlist->file_browser_output);
nfc_playlist->playlist_file_browser = file_browser_alloc(nfc_playlist->file_browser_output);
nfc_playlist->text_input = text_input_alloc();
nfc_playlist->popup = popup_alloc();

Expand All @@ -80,14 +78,14 @@ static NfcPlaylist* nfc_playlist_alloc() {
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Menu, submenu_get_view(nfc_playlist->submenu));
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_PlaylistSelect, file_browser_get_view(nfc_playlist->file_browser));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_PlaylistSelect, file_browser_get_view(nfc_playlist->playlist_file_browser));
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));

Storage* storage = furi_record_open(RECORD_STORAGE);
if (!storage_common_exists(storage, "/ext/apps_data/nfc_playlist")) {
storage_common_mkdir(storage, "/ext/apps_data/nfc_playlist");
if (!storage_common_exists(storage, PLAYLIST_DIR)) {
storage_common_mkdir(storage, PLAYLIST_DIR);
}
furi_record_close(RECORD_STORAGE);

Expand All @@ -112,11 +110,10 @@ static void nfc_playlist_free(NfcPlaylist* nfc_playlist) {
widget_free(nfc_playlist->widget);

furi_record_close(RECORD_NOTIFICATION);
file_browser_free(nfc_playlist->file_browser);
file_browser_free(nfc_playlist->playlist_file_browser);
text_input_free(nfc_playlist->text_input);
popup_free(nfc_playlist->popup);

furi_string_free(nfc_playlist->settings.base_file_path);
furi_string_free(nfc_playlist->settings.file_path);
furi_string_free(nfc_playlist->file_browser_output);
free(nfc_playlist);
Expand Down
11 changes: 6 additions & 5 deletions nfc_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ typedef enum {
} NfcPlaylistScene;

typedef struct {
FuriString* base_file_path;
FuriString* file_path;
bool playlist_selected;
bool playlist_selected_check;
uint8_t emulate_timeout;
uint8_t emulate_delay;
bool emulate_led_indicator;
Expand All @@ -51,21 +49,24 @@ typedef struct {
SceneManager* scene_manager;
ViewDispatcher* view_dispatcher;
VariableItemList* variable_item_list;
FileBrowser* file_browser;
FileBrowser* playlist_file_browser;
FuriString* file_browser_output;
TextInput* text_input;
char* text_input_output;
Submenu* submenu;
Popup* popup;
Widget* widget;
NotificationApp* notification;
FuriThread* thread;
NfcPlaylistWorker* nfc_playlist_worker;
NfcPlaylistSettings settings;
char* playlist_name;
} NfcPlaylist;

static const int options_emulate_timeout[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
static const int default_emulate_timeout = 4;
static const int options_emulate_delay[] = {0, 1, 2, 3, 4, 5, 6};
static const int default_emulate_delay = 0;
static const bool default_emulate_led_indicator = true;
static const bool default_emulate_led_indicator = true;

#define PLAYLIST_LOCATION "/ext/apps_data/nfc_playlist/"
#define PLAYLIST_DIR "/ext/apps_data/nfc_playlist"
3 changes: 1 addition & 2 deletions scences/confirm_delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ bool nfc_playlist_confirm_delete_scene_on_event(void* context, SceneManagerEvent
Storage* storage = furi_record_open(RECORD_STORAGE);
storage_simply_remove(storage, furi_string_get_cstr(nfc_playlist->settings.file_path));
nfc_playlist->settings.playlist_selected = false;
nfc_playlist->settings.playlist_selected_check = false;
nfc_playlist->settings.file_path = nfc_playlist->settings.base_file_path;
furi_string_reset(nfc_playlist->settings.file_path);
furi_record_close(RECORD_STORAGE);
consumed = true;
break;
Expand Down
2 changes: 1 addition & 1 deletion scences/emulation.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int32_t nfc_playlist_emulation_task(void* context) {
popup_set_context(nfc_playlist->popup, nfc_playlist);
view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup);

if (file_stream_open(stream, furi_string_get_cstr(nfc_playlist->settings.file_path), FSAM_READ, FSOM_OPEN_EXISTING) && nfc_playlist->settings.playlist_selected_check) {
if (file_stream_open(stream, furi_string_get_cstr(nfc_playlist->settings.file_path), FSAM_READ, FSOM_OPEN_EXISTING)) {
EmulationState = NfcPlaylistEmulationState_Emulating;
int file_position = 0;

Expand Down
4 changes: 2 additions & 2 deletions scences/file_edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void nfc_playlist_file_edit_scene_on_enter(void* context) {
NfcPlaylistMenuSelection_DeletePlaylist,
nfc_playlist_file_edit_menu_callback,
nfc_playlist,
!nfc_playlist->settings.playlist_selected_check,
furi_string_empty(nfc_playlist->settings.file_path),
"No\nplaylist\nselected");

submenu_add_lockable_item(
Expand All @@ -26,7 +26,7 @@ void nfc_playlist_file_edit_scene_on_enter(void* context) {
NfcPlaylistMenuSelection_RenamePlaylist,
nfc_playlist_file_edit_menu_callback,
nfc_playlist,
!nfc_playlist->settings.playlist_selected_check,
furi_string_empty(nfc_playlist->settings.file_path),
"No\nplaylist\nselected");

view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit);
Expand Down
8 changes: 4 additions & 4 deletions scences/file_rename.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void nfc_playlist_file_rename_menu_callback(void* context) {
furi_string_printf(tmp_old_file_path, "%s", old_file_path);
furi_string_replace(tmp_old_file_path, old_file_name, "");

furi_string_printf(tmp_new_file_path, "%s%s.txt", furi_string_get_cstr(tmp_old_file_path), nfc_playlist->playlist_name);
furi_string_printf(tmp_new_file_path, "%s%s.txt", furi_string_get_cstr(tmp_old_file_path), nfc_playlist->text_input_output);

if(!storage_file_exists(storage, furi_string_get_cstr(tmp_new_file_path))) {
storage_common_rename_safe(storage, furi_string_get_cstr(nfc_playlist->settings.file_path), furi_string_get_cstr(tmp_new_file_path));
Expand All @@ -28,10 +28,10 @@ void nfc_playlist_file_rename_menu_callback(void* context) {

void nfc_playlist_file_rename_scene_on_enter(void* context) {
NfcPlaylist* nfc_playlist = context;
nfc_playlist->playlist_name = (char*)malloc(50);
nfc_playlist->text_input_output = (char*)malloc(50);
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->playlist_name, 50, true);
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);
}

Expand All @@ -44,5 +44,5 @@ bool nfc_playlist_file_rename_scene_on_event(void* context, SceneManagerEvent ev
void nfc_playlist_file_rename_scene_on_exit(void* context) {
NfcPlaylist* nfc_playlist = context;
text_input_reset(nfc_playlist->text_input);
free(nfc_playlist->playlist_name);
free(nfc_playlist->text_input_output);
}
2 changes: 1 addition & 1 deletion scences/main_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void nfc_playlist_main_menu_scene_on_enter(void* context) {
NfcPlaylistMenuSelection_Start,
nfc_playlist_main_menu_menu_callback,
nfc_playlist,
!nfc_playlist->settings.playlist_selected_check,
furi_string_empty(nfc_playlist->settings.file_path),
"No\nplaylist\nselected");

submenu_add_item(
Expand Down
15 changes: 8 additions & 7 deletions scences/playlist_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

void nfc_playlist_playlist_select_menu_callback(void* context) {
NfcPlaylist* nfc_playlist = context;
nfc_playlist->settings.playlist_selected_check = true;
furi_string_move(nfc_playlist->settings.file_path, nfc_playlist->file_browser_output);
furi_string_reset(nfc_playlist->file_browser_output);
scene_manager_previous_scene(nfc_playlist->scene_manager);
Expand All @@ -12,16 +11,18 @@ void nfc_playlist_playlist_select_menu_callback(void* context) {
void nfc_playlist_playlist_select_scene_on_enter(void* context) {
NfcPlaylist* nfc_playlist = context;
file_browser_configure(
nfc_playlist->file_browser,
nfc_playlist->playlist_file_browser,
".txt",
furi_string_get_cstr(nfc_playlist->settings.base_file_path),
PLAYLIST_LOCATION,
true,
true,
&I_sub1_10px,
&I_Nfc_10px,
true);
view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_PlaylistSelect);
file_browser_set_callback(nfc_playlist->file_browser, nfc_playlist_playlist_select_menu_callback, nfc_playlist);
file_browser_start(nfc_playlist->file_browser, nfc_playlist->settings.base_file_path);
file_browser_set_callback(nfc_playlist->playlist_file_browser, nfc_playlist_playlist_select_menu_callback, nfc_playlist);
FuriString* tmp_str = furi_string_alloc_set_str(PLAYLIST_LOCATION);
file_browser_start(nfc_playlist->playlist_file_browser, tmp_str);
furi_string_free(tmp_str);
}

bool nfc_playlist_playlist_select_scene_on_event(void* context, SceneManagerEvent event) {
Expand All @@ -32,5 +33,5 @@ bool nfc_playlist_playlist_select_scene_on_event(void* context, SceneManagerEven

void nfc_playlist_playlist_select_scene_on_exit(void* context) {
NfcPlaylist* nfc_playlist = context;
file_browser_stop(nfc_playlist->file_browser);
file_browser_stop(nfc_playlist->playlist_file_browser);
}

0 comments on commit ec33779

Please sign in to comment.