|
|
@@ -1,8 +1,6 @@
|
|
|
#include "../nfc_playlist.h"
|
|
|
|
|
|
-static bool playlist_exist_already = false;
|
|
|
-
|
|
|
-int32_t nfc_playlist_name_new_playlist_thread_task(void* context) {
|
|
|
+void nfc_playlist_name_new_playlist_menu_callback(void* context) {
|
|
|
NfcPlaylist* nfc_playlist = context;
|
|
|
|
|
|
FuriString* file_name =
|
|
|
@@ -12,6 +10,7 @@ int32_t nfc_playlist_name_new_playlist_thread_task(void* context) {
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
File* file = storage_file_alloc(storage);
|
|
|
|
|
|
+ bool playlist_exist_already = false;
|
|
|
if(!storage_file_exists(storage, file_name_cstr)) {
|
|
|
if(storage_file_open(file, file_name_cstr, FSAM_READ_WRITE, FSOM_CREATE_NEW)) {
|
|
|
storage_file_close(file);
|
|
|
@@ -26,40 +25,12 @@ int32_t nfc_playlist_name_new_playlist_thread_task(void* context) {
|
|
|
storage_file_free(file);
|
|
|
furi_record_close(RECORD_STORAGE);
|
|
|
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-void nfc_playlist_name_new_playlist_thread_state_callback(FuriThreadState state, void* context) {
|
|
|
- NfcPlaylist* nfc_playlist = context;
|
|
|
- if(state == FuriThreadStateStopped) {
|
|
|
- furi_thread_yield();
|
|
|
- nfc_playlist->thread = NULL;
|
|
|
- if(playlist_exist_already) {
|
|
|
- scene_manager_next_scene(
|
|
|
- nfc_playlist->scene_manager, NfcPlaylistScene_ErrorPlaylistAlreadyExists);
|
|
|
- } else {
|
|
|
- scene_manager_search_and_switch_to_previous_scene(
|
|
|
- nfc_playlist->scene_manager, NfcPlaylistScene_MainMenu);
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void nfc_playlist_name_new_playlist_menu_callback(void* context) {
|
|
|
- NfcPlaylist* nfc_playlist = context;
|
|
|
-
|
|
|
- nfc_playlist->thread = furi_thread_alloc_ex(
|
|
|
- "NfcPlaylistCreator", 1024, nfc_playlist_name_new_playlist_thread_task, nfc_playlist);
|
|
|
- furi_thread_set_state_context(nfc_playlist->thread, nfc_playlist);
|
|
|
- furi_thread_set_state_callback(
|
|
|
- nfc_playlist->thread, nfc_playlist_name_new_playlist_thread_state_callback);
|
|
|
- furi_thread_start(nfc_playlist->thread);
|
|
|
+ view_dispatcher_send_custom_event(nfc_playlist->view_dispatcher, playlist_exist_already);
|
|
|
}
|
|
|
|
|
|
void nfc_playlist_name_new_playlist_scene_on_enter(void* context) {
|
|
|
NfcPlaylist* nfc_playlist = context;
|
|
|
|
|
|
- playlist_exist_already = false;
|
|
|
-
|
|
|
nfc_playlist->text_input_output = malloc(MAX_PLAYLIST_NAME_LEN + 1);
|
|
|
text_input_set_header_text(nfc_playlist->text_input, "Enter file name");
|
|
|
text_input_set_minimum_length(nfc_playlist->text_input, 1);
|
|
|
@@ -75,8 +46,19 @@ void nfc_playlist_name_new_playlist_scene_on_enter(void* context) {
|
|
|
}
|
|
|
|
|
|
bool nfc_playlist_name_new_playlist_scene_on_event(void* context, SceneManagerEvent event) {
|
|
|
- UNUSED(context);
|
|
|
- UNUSED(event);
|
|
|
+ NfcPlaylist* nfc_playlist = context;
|
|
|
+
|
|
|
+ if(event.type == SceneManagerEventTypeCustom) {
|
|
|
+ bool playlist_exist_already = event.event;
|
|
|
+ if(playlist_exist_already) {
|
|
|
+ scene_manager_next_scene(
|
|
|
+ nfc_playlist->scene_manager, NfcPlaylistScene_ErrorPlaylistAlreadyExists);
|
|
|
+ } else {
|
|
|
+ scene_manager_search_and_switch_to_previous_scene(
|
|
|
+ nfc_playlist->scene_manager, NfcPlaylistScene_MainMenu);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
return false;
|
|
|
}
|
|
|
|