lfrfid_scene_raw_name.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "../lfrfid_i.h"
  2. void lfrfid_scene_raw_name_on_enter(void* context) {
  3. LfRfid* app = context;
  4. TextInput* text_input = app->text_input;
  5. const char* key_name = furi_string_get_cstr(app->raw_file_name);
  6. bool key_name_is_empty = furi_string_empty(app->file_name);
  7. if(key_name_is_empty) {
  8. lfrfid_text_store_set(app, "RfidRecord");
  9. } else {
  10. lfrfid_text_store_set(app, "%s", key_name);
  11. }
  12. text_input_set_header_text(text_input, "Name the raw file");
  13. text_input_set_result_callback(
  14. text_input,
  15. lfrfid_text_input_callback,
  16. app,
  17. app->text_store,
  18. LFRFID_KEY_NAME_SIZE,
  19. key_name_is_empty);
  20. ValidatorIsFile* validator_is_file =
  21. validator_is_file_alloc_init(LFRFID_SD_FOLDER, LFRFID_APP_RAW_ASK_EXTENSION, NULL);
  22. text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
  23. view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewTextInput);
  24. }
  25. bool lfrfid_scene_raw_name_on_event(void* context, SceneManagerEvent event) {
  26. LfRfid* app = context;
  27. SceneManager* scene_manager = app->scene_manager;
  28. bool consumed = false;
  29. if(event.type == SceneManagerEventTypeCustom) {
  30. if(event.event == LfRfidEventNext) {
  31. consumed = true;
  32. furi_string_set(app->raw_file_name, app->text_store);
  33. scene_manager_next_scene(scene_manager, LfRfidSceneRawInfo);
  34. }
  35. }
  36. return consumed;
  37. }
  38. void lfrfid_scene_raw_name_on_exit(void* context) {
  39. LfRfid* app = context;
  40. TextInput* text_input = app->text_input;
  41. void* validator_context = text_input_get_validator_callback_context(text_input);
  42. text_input_set_validator(text_input, NULL, NULL);
  43. validator_is_file_free((ValidatorIsFile*)validator_context);
  44. text_input_reset(text_input);
  45. }