forked from flipperdevices/flipperzero-firmware
-
-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from acegoal07/dev
Dev 08/02/2024
- Loading branch information
Showing
11 changed files
with
213 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "nfc_playlist.h" | ||
#include "scences/file_edit.h" | ||
|
||
typedef enum { | ||
NfcPlaylistMenuSelection_DeletePlaylist, | ||
NfcPlaylistMenuSelection_RenamePlaylist, | ||
NfcPlaylistMenuSelection_EditList | ||
} 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; | ||
} | ||
case NfcPlaylistMenuSelection_RenamePlaylist: { | ||
scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_TextInput); | ||
break; | ||
} | ||
case NfcPlaylistMenuSelection_EditList: { | ||
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_lockable_item( | ||
nfc_playlist->submenu, | ||
"Delete Playlist", | ||
NfcPlaylistMenuSelection_DeletePlaylist, | ||
nfc_playlist_file_edit_menu_callback, | ||
nfc_playlist, | ||
!nfc_playlist->file_selected_check, | ||
"No\nplaylist\nselected"); | ||
|
||
submenu_add_lockable_item( | ||
nfc_playlist->submenu, | ||
"Rename Playlist", | ||
NfcPlaylistMenuSelection_RenamePlaylist, | ||
nfc_playlist_file_edit_menu_callback, | ||
nfc_playlist, | ||
!nfc_playlist->file_selected_check, | ||
"No\nplaylist\nselected"); | ||
|
||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "nfc_playlist.h" | ||
#include "scences/text_input.h" | ||
|
||
void nfc_playlist_text_input_menu_callback(void* context) { | ||
NfcPlaylist* nfc_playlist = context; | ||
Storage* storage = furi_record_open(RECORD_STORAGE); | ||
|
||
char const* old_file_path = (char*)furi_string_get_cstr(nfc_playlist->file_path); | ||
char const* old_file_name = strchr(old_file_path, '/') != NULL ? &strrchr(old_file_path, '/')[1] : old_file_path; | ||
|
||
int file_path_size = (strlen(old_file_path) - strlen(old_file_name) + 1); | ||
|
||
char* file_path = (char*)malloc(file_path_size); | ||
snprintf(file_path, file_path_size, "%s", old_file_path); | ||
|
||
int new_file_path_size = (strlen(nfc_playlist->playlist_name) + strlen(".txt") + file_path_size + 1); | ||
|
||
char* new_file_name = (char*)malloc(new_file_path_size); | ||
snprintf(new_file_name, new_file_path_size, "%s%s%s", file_path, nfc_playlist->playlist_name, ".txt"); | ||
|
||
if (!storage_file_exists(storage, new_file_name)) { | ||
storage_common_rename_safe(storage, furi_string_get_cstr(nfc_playlist->file_path), new_file_name); | ||
nfc_playlist->file_path = furi_string_alloc_set_str(new_file_name); | ||
} | ||
|
||
free(new_file_name); | ||
free(file_path); | ||
free(nfc_playlist->playlist_name); | ||
furi_record_close(RECORD_STORAGE); | ||
|
||
scene_manager_previous_scene(nfc_playlist->scene_manager); | ||
} | ||
|
||
void nfc_playlist_text_input_scene_on_enter(void* context) { | ||
NfcPlaylist* nfc_playlist = context; | ||
nfc_playlist->playlist_name = (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_text_input_menu_callback, nfc_playlist, nfc_playlist->playlist_name, 50, true); | ||
view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput); | ||
} | ||
|
||
bool nfc_playlist_text_input_scene_on_event(void* context, SceneManagerEvent event) { | ||
UNUSED(context); | ||
UNUSED(event); | ||
return false; | ||
} | ||
|
||
void nfc_playlist_text_input_scene_on_exit(void* context) { | ||
NfcPlaylist* nfc_playlist = context; | ||
text_input_reset(nfc_playlist->text_input); | ||
} |
Oops, something went wrong.