2021-07-02 13:44:10 +00:00
|
|
|
#include "../nfc_i.h"
|
2021-07-25 11:34:54 +00:00
|
|
|
#include <lib/toolbox/random_name.h>
|
2022-01-29 09:39:10 +00:00
|
|
|
#include <gui/modules/validators.h>
|
2022-05-27 11:19:21 +00:00
|
|
|
#include <toolbox/path.h>
|
2022-10-28 07:18:41 +00:00
|
|
|
#include <dolphin/dolphin.h>
|
2021-07-02 13:44:10 +00:00
|
|
|
|
|
|
|
void nfc_scene_save_name_text_input_callback(void* context) {
|
2022-04-19 15:23:58 +00:00
|
|
|
Nfc* nfc = context;
|
2021-07-02 13:44:10 +00:00
|
|
|
|
2022-02-02 19:59:28 +00:00
|
|
|
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventTextInputDone);
|
2021-07-02 13:44:10 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 09:34:16 +00:00
|
|
|
void nfc_scene_save_name_on_enter(void* context) {
|
2022-04-19 15:23:58 +00:00
|
|
|
Nfc* nfc = context;
|
2021-07-02 13:44:10 +00:00
|
|
|
|
|
|
|
// Setup view
|
|
|
|
TextInput* text_input = nfc->text_input;
|
2021-07-25 11:34:54 +00:00
|
|
|
bool dev_name_empty = false;
|
2021-11-08 21:55:06 +00:00
|
|
|
if(!strcmp(nfc->dev->dev_name, "")) {
|
2021-07-25 11:34:54 +00:00
|
|
|
set_random_name(nfc->text_store, sizeof(nfc->text_store));
|
|
|
|
dev_name_empty = true;
|
|
|
|
} else {
|
2021-11-08 21:55:06 +00:00
|
|
|
nfc_text_store_set(nfc, nfc->dev->dev_name);
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
2021-07-02 13:44:10 +00:00
|
|
|
text_input_set_header_text(text_input, "Name the card");
|
|
|
|
text_input_set_result_callback(
|
|
|
|
text_input,
|
|
|
|
nfc_scene_save_name_text_input_callback,
|
|
|
|
nfc,
|
|
|
|
nfc->text_store,
|
2021-07-25 11:34:54 +00:00
|
|
|
NFC_DEV_NAME_MAX_LEN,
|
|
|
|
dev_name_empty);
|
2022-01-29 09:39:10 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* folder_path;
|
|
|
|
folder_path = furi_string_alloc();
|
2022-05-27 11:19:21 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_end_with(nfc->dev->load_path, NFC_APP_EXTENSION)) {
|
|
|
|
path_extract_dirname(furi_string_get_cstr(nfc->dev->load_path), folder_path);
|
2022-05-27 11:19:21 +00:00
|
|
|
} else {
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_set(folder_path, NFC_APP_FOLDER);
|
2022-05-27 11:19:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_get_cstr(folder_path), NFC_APP_EXTENSION, nfc->dev->dev_name);
|
2022-01-29 09:39:10 +00:00
|
|
|
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
|
|
|
|
2021-07-22 06:05:07 +00:00
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextInput);
|
2022-05-27 11:19:21 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_free(folder_path);
|
2021-07-02 13:44:10 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 09:34:16 +00:00
|
|
|
bool nfc_scene_save_name_on_event(void* context, SceneManagerEvent event) {
|
2022-04-19 15:23:58 +00:00
|
|
|
Nfc* nfc = context;
|
|
|
|
bool consumed = false;
|
2021-07-02 13:44:10 +00:00
|
|
|
|
2021-07-12 18:56:14 +00:00
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
2022-02-02 19:59:28 +00:00
|
|
|
if(event.event == NfcCustomEventTextInputDone) {
|
2022-12-26 12:13:30 +00:00
|
|
|
if(strcmp(nfc->dev->dev_name, "") != 0) {
|
2022-05-27 11:19:21 +00:00
|
|
|
nfc_device_delete(nfc->dev, true);
|
2021-07-25 11:34:54 +00:00
|
|
|
}
|
2021-09-02 09:28:40 +00:00
|
|
|
if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneSetUid)) {
|
2021-11-08 21:55:06 +00:00
|
|
|
nfc->dev->dev_data.nfc_data = nfc->dev_edit_data;
|
2021-09-02 09:28:40 +00:00
|
|
|
}
|
2021-11-08 21:55:06 +00:00
|
|
|
strlcpy(nfc->dev->dev_name, nfc->text_store, strlen(nfc->text_store) + 1);
|
2022-11-10 16:20:35 +00:00
|
|
|
if(nfc_save_file(nfc)) {
|
2021-07-12 18:56:14 +00:00
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveSuccess);
|
2022-10-28 07:18:41 +00:00
|
|
|
if(!scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneSavedMenu)) {
|
|
|
|
// Nothing, do not count editing as saving
|
|
|
|
} else if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneSetType)) {
|
|
|
|
DOLPHIN_DEED(DolphinDeedNfcAddSave);
|
|
|
|
} else {
|
|
|
|
DOLPHIN_DEED(DolphinDeedNfcSave);
|
|
|
|
}
|
2022-04-19 15:23:58 +00:00
|
|
|
consumed = true;
|
2021-07-12 18:56:14 +00:00
|
|
|
} else {
|
2022-04-19 15:23:58 +00:00
|
|
|
consumed = scene_manager_search_and_switch_to_previous_scene(
|
2021-07-28 14:52:00 +00:00
|
|
|
nfc->scene_manager, NfcSceneStart);
|
2021-07-12 18:56:14 +00:00
|
|
|
}
|
2021-07-02 13:44:10 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-19 15:23:58 +00:00
|
|
|
return consumed;
|
2021-07-02 13:44:10 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 09:34:16 +00:00
|
|
|
void nfc_scene_save_name_on_exit(void* context) {
|
2022-04-19 15:23:58 +00:00
|
|
|
Nfc* nfc = context;
|
2021-07-02 13:44:10 +00:00
|
|
|
|
|
|
|
// Clear view
|
2022-01-29 09:39:10 +00:00
|
|
|
void* validator_context = text_input_get_validator_callback_context(nfc->text_input);
|
|
|
|
text_input_set_validator(nfc->text_input, NULL, NULL);
|
|
|
|
validator_is_file_free(validator_context);
|
|
|
|
|
2022-01-21 17:32:03 +00:00
|
|
|
text_input_reset(nfc->text_input);
|
2021-07-02 13:44:10 +00:00
|
|
|
}
|