Skip to content

Commit 5c8557f

Browse files
committed
Remove unused file, name input boilerplate
1 parent 376436c commit 5c8557f

File tree

3 files changed

+74
-6
lines changed

3 files changed

+74
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ Other misc things to investigate / build:
1616
- Precomputing bit output, and then sending ("RedSpoof" by devBioS does this, as they say they had timing issues when computing the bits live)
1717
- Reverse-track emulate?
1818
- Tuning of parameters like pre-signal zeros?
19-
- "Interpacket delay" like the RedSpoof implementation?
19+
- "Interpacket delay" like the RedSpoof implementation?

mag.h

Whitespace-only changes.

scenes/mag_scene_save_name.c

+73-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,88 @@
1+
#include <lib/toolbox/random_name.h>
12
#include "../mag_i.h"
23

34
void mag_scene_save_name_on_enter(void* context) {
45
Mag* mag = context;
5-
UNUSED(mag);
6+
TextInput* text_input = mag->text_input;
7+
FuriString* folder_path;
8+
folder_path = furi_string_alloc();
9+
10+
bool key_name_is_empty = furi_string_empty(mag->file_name);
11+
12+
if(key_name_is_empty) {
13+
furi_string_set(mag->file_path, MAG_APP_FOLDER);
14+
set_random_name(mag->text_store, MAG_TEXT_STORE_SIZE);
15+
furi_string_set(folder_path, MAG_APP_FOLDER);
16+
} else {
17+
mag_text_store_set(mag, "%s", furi_string_get_cstr(mag->file_name));
18+
path_extract_dirname(furi_string_get_cstr(mag->file_path), folder_path);
19+
}
20+
21+
text_input_set_header_text(text_input, "Name the card");
22+
text_input_set_result_callback(
23+
text_input,
24+
mag_text_input_callback,
25+
mag,
26+
mag->text_store,
27+
MAG_KEY_NAME_SIZE,
28+
key_name_is_empty);
29+
30+
FURI_LOG_I("", "%s %s", furi_string_get_cstr(folder_path), mag->text_store);
31+
32+
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
33+
furi_string_get_cstr(folder_path),
34+
MAG_APP_EXTENSION,
35+
furi_string_get_cstr(mag->file_name));
36+
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
37+
38+
furi_string_free(folder_path);
39+
40+
view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewTextInput);
641
}
742

843
bool mag_scene_save_name_on_event(void* context, SceneManagerEvent event) {
944
Mag* mag = context;
10-
UNUSED(mag);
11-
UNUSED(event);
45+
SceneManager* scene_manager = mag->scene_manager;
1246
bool consumed = false;
1347

48+
if(event.type == SceneManagerEventTypeCustom) {
49+
if(event.event == MagEventNext) {
50+
consumed = true;
51+
if(!furi_string_empty(mag->file_name)) {
52+
mag_delete_key(mag);
53+
}
54+
55+
furi_string_set(mag->file_name, mag->text_store);
56+
57+
if(mag_save_key(mag)) {
58+
scene_manager_next_scene(scene_manager, MagSceneSaveSuccess);
59+
if(scene_manager_has_previous_scene(scene_manager, MagSceneSavedKeyMenu)) {
60+
// Nothing, do not count editing as saving
61+
//} else if(scene_manager_has_previous_scene(scene_manager, MagSceneSaveType)) {
62+
//DOLPHIN_DEED(DolphinDeedRfidAdd);
63+
// TODO: replace dolphin deed!
64+
} else {
65+
//DOLPHIN_DEED(DolphinDeedRfidSave);
66+
// TODO: replace dolphin deed!
67+
}
68+
} else {
69+
//scene_manager_search_and_switch_to_previous_scene(
70+
// scene_manager, MagSceneReadKeyMenu);
71+
// TODO: Replace with appropriate scene! No read scene prior if adding manually...
72+
}
73+
}
74+
}
75+
1476
return consumed;
1577
}
1678

1779
void mag_scene_save_name_on_exit(void* context) {
1880
Mag* mag = context;
19-
UNUSED(mag);
20-
}
81+
TextInput* text_input = mag->text_input;
82+
83+
void* validator_context = text_input_get_validator_callback_context(text_input);
84+
text_input_set_validator(text_input, NULL, NULL);
85+
validator_is_file_free((ValidatorIsFile*)validator_context);
86+
87+
text_input_reset(text_input);
88+
}

0 commit comments

Comments
 (0)