subrem_scene_enter_new_name.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "../subghz_remote_app_i.h"
  2. #include "../helpers/subrem_custom_event.h"
  3. #include <gui/modules/validators.h>
  4. void subrem_scene_enter_new_name_text_input_callback(void* context) {
  5. furi_assert(context);
  6. SubGhzRemoteApp* app = context;
  7. view_dispatcher_send_custom_event(app->view_dispatcher, SubRemCustomEventSceneNewName);
  8. }
  9. void subrem_scene_enter_new_name_on_enter(void* context) {
  10. SubGhzRemoteApp* app = context;
  11. // Setup view
  12. TextInput* text_input = app->text_input;
  13. //strncpy(app->file_name_tmp, "subrem_", SUBREM_MAX_LEN_NAME);
  14. text_input_set_header_text(text_input, "Map file Name");
  15. text_input_set_result_callback(
  16. text_input,
  17. subrem_scene_enter_new_name_text_input_callback,
  18. app,
  19. app->file_name_tmp,
  20. 25,
  21. false);
  22. ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
  23. furi_string_get_cstr(app->file_path), SUBREM_APP_EXTENSION, "");
  24. text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
  25. view_dispatcher_switch_to_view(app->view_dispatcher, SubRemViewIDTextInput);
  26. }
  27. bool subrem_scene_enter_new_name_on_event(void* context, SceneManagerEvent event) {
  28. furi_assert(context);
  29. SubGhzRemoteApp* app = context;
  30. bool consumed = false;
  31. if(event.type == SceneManagerEventTypeCustom) {
  32. if(event.event == SubRemCustomEventSceneNewName) {
  33. if(strcmp(app->file_name_tmp, "") != 0) {
  34. furi_string_set(app->file_path, SUBREM_APP_FOLDER);
  35. furi_string_cat_printf(
  36. app->file_path, "/%s%s", app->file_name_tmp, SUBREM_APP_EXTENSION);
  37. subrem_map_preset_reset(app->map_preset);
  38. scene_manager_next_scene(app->scene_manager, SubRemSceneEditMenu);
  39. } else { //error
  40. }
  41. consumed = true;
  42. }
  43. }
  44. return consumed;
  45. }
  46. void subrem_scene_enter_new_name_on_exit(void* context) {
  47. furi_assert(context);
  48. SubGhzRemoteApp* app = context;
  49. submenu_reset(app->submenu);
  50. // Clear validator & view
  51. void* validator_context = text_input_get_validator_callback_context(app->text_input);
  52. text_input_set_validator(app->text_input, NULL, NULL);
  53. validator_is_file_free(validator_context);
  54. text_input_reset(app->text_input);
  55. }